Package org.openfriendsbudget.model

Examples of org.openfriendsbudget.model.Person


     * Test of resolveBudget method, of class BudgetService.
     */
    public void testResolveBudget() {
        System.out.println("resolveBudget");
               
        Person p1 = new Person();
        p1.setAlias("p1");
        p1.setGivenname("p1");
        p1.setMail("p1@mail.com");
        p1.setSurname("p1");

        Person p2 = new Person();
        p2.setAlias("p2");
        p2.setGivenname("p2");
        p2.setMail("p2@mail.com");
        p2.setSurname("p2");

        Person p3 = new Person();
        p3.setAlias("p3");
        p3.setGivenname("p3");
        p3.setMail("p3@mail.com");
        p3.setSurname("p3");

        Person p4 = new Person();
        p4.setAlias("p4");
        p4.setGivenname("p4");
        p4.setMail("p4@mail.com");
        p4.setSurname("p4");


        Budget budget = new Budget();
        budget.setCurrency("euro");

        Map<String,Float> change = new HashMap<String,Float>(2);
        change.put("USD",(float)2.0);
        change.put("YEN",(float)4.0);
        budget.setChange(change);

        budget.addPerson(p1);
        budget.addPerson(p2);
        budget.addPerson(p3);
        budget.addPerson(p4);

        Expenditure exp1 = new Expenditure();
        exp1.setOwner(p1);
        exp1.addRecipient(p1, 1); // p1 : 0
        exp1.addRecipient(p2, 2); // p2 : -200 / p1 : +200
        exp1.setAmount(300);

        Expenditure exp2 = new Expenditure();
        exp2.setOwner(p3);
        exp2.addRecipient(p2, 1); // p2 : -40 / p3 : + 40
        exp2.addRecipient(p3, 1); // p3 : 0
        exp2.setAmount(20); // 20 YEN * 4 = 80 EUR
        exp2.setCurrency("YEN");

        Expenditure exp3 = new Expenditure();
        exp3.setOwner(p1);
        exp3.addRecipient(p1, 1); // p1 : 0
        exp3.addRecipient(p2, 1); // p2 : -100 / p1 : +100
        exp3.addRecipient(p3, 1); // p3 : -100 / p1 : +100
        exp3.setAmount(300);

        Expenditure exp4 = new Expenditure();
        exp4.setOwner(p2);
        exp4.addRecipient(p2, 1); // p2 : 0
        exp4.addRecipient(p3, 1); // p3 : -100 / p2 : +100
        exp4.addRecipient(p1, 2); // p1 : -200 / p2 : +200
        exp4.setAmount(400);

        Expenditure exp5 = new Expenditure();
        exp5.setOwner(p4);
        exp5.addRecipient(p2, 1); // p2 : -50 / p4 : +50
        exp5.addRecipient(p1, 1); // p1 : -50 / p4 : +50
        exp5.addRecipient(p3, 1); // p3 : -50 / p4 : +50
        exp5.addRecipient(p4, 1); // p4 : 0
        exp5.setAmount(200);

        Expenditure exp6 = new Expenditure();
        exp6.setOwner(p3);
        exp6.addRecipient(p1, 2); // p1 : -80 / p3 : +80
        exp6.addRecipient(p4, 1); // p4 : -40 / p3 : +40
        exp6.setAmount(60);
        exp6.setCurrency("USD");


        // Total:
        // p1 : +70
        // p2 : -90
        // p3 : -90
        // p4 : +110
        try {

            budget.addExpenditure(exp1);
            budget.addExpenditure(exp2);
            budget.addExpenditure(exp3);
            budget.addExpenditure(exp4);
            budget.addExpenditure(exp5);
            budget.addExpenditure(exp6);

            BudgetService bs = new BudgetService(new AdjacencyMatrixGraphFactory());

            Graph graph = bs.resolveBudget(budget);
            assertEquals(graph.getVertexSet().size(), 4);

            Set<String> personIdSet = new HashSet<String>(4);
            personIdSet.add(p1.getId());
            personIdSet.add(p2.getId());
            personIdSet.add(p3.getId());
            personIdSet.add(p4.getId());

            for(Vertex vertex : graph.getVertexSet()) {
                assertTrue(personIdSet.contains(vertex.getId()));
                if(vertex.getId().equals(p1.getId())){
                    assertEquals(vertex.getDegree(),7000);
                }
                if(vertex.getId().equals(p2.getId())){
                    assertEquals(vertex.getDegree(),-9000);
                }
                if(vertex.getId().equals(p3.getId())){
                    assertEquals(vertex.getDegree(),-9000);
                }
                if(vertex.getId().equals(p4.getId())){
                    assertEquals(vertex.getDegree(),11000);
                }
                assertTrue(vertex.getId().equals(p1.getId())
                        || vertex.getId().equals(p2.getId())
                        || vertex.getId().equals(p3.getId())
                        || vertex.getId().equals(p4.getId()));
            }

           

        } catch (Exception e) {
View Full Code Here


    }


    public void testCreateBudgetGraph() {
        System.out.println("createBudgetGraph");
        Person p1 = new Person();
        p1.setAlias("p1");
        p1.setGivenname("p1");
        p1.setMail("p1@mail.com");
        p1.setSurname("p1");

        Person p2 = new Person();
        p2.setAlias("p2");
        p2.setGivenname("p2");
        p2.setMail("p2@mail.com");
        p2.setSurname("p2");

        Person p3 = new Person();
        p3.setAlias("p3");
        p3.setGivenname("p3");
        p3.setMail("p3@mail.com");
        p3.setSurname("p3");

        Budget budget = new Budget();
        budget.setCurrency("euro");

        Map<String,Float> change = new HashMap<String,Float>(2);
        change.put("USD",(float)2.0);
        change.put("YEN",(float)4.0);
        budget.setChange(change);

        budget.addPerson(p1);
        budget.addPerson(p2);
        budget.addPerson(p3);

        Expenditure exp1 = new Expenditure();
        exp1.setOwner(p1);
        exp1.addRecipient(p1, 1); // p1 : 0
        exp1.addRecipient(p2, 2); // p2 : -200 / p1 : +200
        exp1.setAmount(300);

        Expenditure exp2 = new Expenditure();
        exp2.setOwner(p3);
        exp2.addRecipient(p2, 1); // p2 : -40 / p3 : + 40
        exp2.addRecipient(p3, 1); // p3 : 0
        exp2.setAmount(20); // 20 YEN * 4 = 80 EUR
        exp2.setCurrency("YEN");

        Expenditure exp3 = new Expenditure();
        exp3.setOwner(p1);
        exp3.addRecipient(p1, 1); // p1 : 0
        exp3.addRecipient(p2, 1); // p2 : -100 / p1 : +100
        exp3.addRecipient(p3, 1); // p3 : -100 / p1 : +100
        exp3.setAmount(300);

        // Total:
        // p1 : +400
        // p2 : -340
        // p3 : -60
        try {

            budget.addExpenditure(exp1);
            budget.addExpenditure(exp2);
            budget.addExpenditure(exp3);

            BudgetService bs = new BudgetService(new AdjacencyMatrixGraphFactory());

            Graph graph = bs.createBudgetGraph(budget);
            assertEquals(graph.getVertexSet().size(), 3);

            Set<String> personIdSet = new HashSet<String>(3);
            personIdSet.add(p1.getId());
            personIdSet.add(p2.getId());
            personIdSet.add(p3.getId());

            for(Vertex vertex : graph.getVertexSet()) {
                assertTrue(personIdSet.contains(vertex.getId()));
                if(vertex.getId().equals(p1.getId())){
                    assertEquals(vertex.getDegree(),40000);
                }
                if(vertex.getId().equals(p2.getId())){
                    assertEquals(vertex.getDegree(),-34000);
                }
                if(vertex.getId().equals(p3.getId())){
                    assertEquals(vertex.getDegree(),-6000);
                }
                assertTrue(vertex.getId().equals(p1.getId())
                        || vertex.getId().equals(p2.getId())
                        || vertex.getId().equals(p3.getId()));
            }

        } catch (Exception e) {
            assertTrue(false);
        }
View Full Code Here

TOP

Related Classes of org.openfriendsbudget.model.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.