Example #1
0
        static void Test1()
        {
            Console.WriteLine("*** Test 1 ***");
            Console.WriteLine();

            Person p1 = new Person("John Debtor");
            Person p2 = new Person("Sally Debtor");
            Person p3 = new Person("Mark Creditor");
            Person p4 = new Person("Brock Debtor");
            Person p5 = new Person("Kane Creditor");

            p1.AddExpense(9m);
            p1.AddExpense(1m);

            p2.AddExpense(10m);
            p2.AddExpense(15m);

            p3.AddExpense(150m);

            p4.AddExpense(22.5m);
            p4.AddExpense(22.5m);

            p5.AddExpense(20m);
            p5.AddExpense(40m);
            p5.AddExpense(20m);

            SortedList<string, Person> persons = new SortedList<string, Person>();
            persons.Add(p1.PersonName, p1);
            persons.Add(p2.PersonName, p2);
            persons.Add(p3.PersonName, p3);
            persons.Add(p4.PersonName, p4);
            persons.Add(p5.PersonName, p5);

            ExpenseSplitter.SplitExpenses(persons);

            Console.WriteLine();

            Console.WriteLine(p1.ToString());
            Console.WriteLine();

            Console.WriteLine(p2.ToString());
            Console.WriteLine();

            Console.WriteLine(p3.ToString());
            Console.WriteLine();

            Console.WriteLine(p4.ToString());
            Console.WriteLine();

            Console.WriteLine(p5.ToString());
            Console.WriteLine();
        }
        public void Test_ExpenseSplitter_FiveParties()
        {
            Person p1 = new Person("John Debtor");
            Person p2 = new Person("Sally Debtor");
            Person p3 = new Person("Mark Creditor");
            Person p4 = new Person("Brock Debtor");
            Person p5 = new Person("Kane Creditor");

            //john owes the most and will pay mark, the biggest creditor
            p1.AddExpense(9m);
            p1.AddExpense(1m);

            //sally doesn't owe anything
            p2.AddExpense(10m);
            p2.AddExpense(10m);

            //mark is the biggest creditor
            p3.AddExpense(30m);

            //Brock owes the second-most and will pay Kane, the second creditor
            p4.AddExpense(10m);
            p4.AddExpense(5.5m);

            //Kane is the second biggest creditor
            p5.AddExpense(8m);
            p5.AddExpense(14.5m);
            p5.AddExpense(2m);

            SortedList<string, Person> persons = new SortedList<string, Person>();
            persons.Add(p1.PersonName, p1);
            persons.Add(p2.PersonName, p2);
            persons.Add(p3.PersonName, p3);
            persons.Add(p4.PersonName, p4);
            persons.Add(p5.PersonName, p5);

            ExpenseSplitter.SplitExpenses(persons);

            Assert.AreEqual(1, p1.PayoutObligations.Count);
            Assert.AreEqual("Mark Creditor", p1.PayoutObligations[0].Key);
            Assert.AreEqual(10m, p1.PayoutObligations[0].Value);

            Assert.AreEqual(0, p2.PayoutObligations.Count);

            Assert.AreEqual(0, p3.PayoutObligations.Count);

            Assert.AreEqual(1, p4.PayoutObligations.Count);
            Assert.AreEqual("Kane Creditor", p4.PayoutObligations[0].Key);
            Assert.AreEqual(4.5m, p4.PayoutObligations[0].Value);

            Assert.AreEqual(0, p5.PayoutObligations.Count);
        }
        public void Test_Person_AddExpense()
        {
            Person person = new Person("Test Name");
            person.AddExpense(10.25m);

            Assert.AreEqual(10.25m, person.Expenses[0]);
        }
        public void Test_Person_PROP_Expenses()
        {
            Person person = new Person("Test Name");

            Assert.AreEqual(0, person.Expenses.Count);

            person.AddExpense(10.25m);

            Assert.AreEqual(1, person.Expenses.Count);
            Assert.AreEqual(10.25m, person.Expenses[0]);
        }
Example #5
0
        static void Test0()
        {
            Console.WriteLine("*** Test 0 ***");
            Console.WriteLine();

            Person p1 = new Person("Louis");
            Person p2 = new Person("Carter");
            Person p3 = new Person("David");

            p1.AddExpense(5.75m);
            p1.AddExpense(35m);
            p1.AddExpense(12.79m);

            p2.AddExpense(12m);
            p2.AddExpense(15m);
            p2.AddExpense(23.23m);

            p3.AddExpense(10m);
            p3.AddExpense(20m);
            p3.AddExpense(38.41m);
            p3.AddExpense(45m);

            SortedList<string, Person> persons = new SortedList<string, Person>();
            persons.Add(p1.PersonName, p1);
            persons.Add(p2.PersonName, p2);
            persons.Add(p3.PersonName, p3);

            ExpenseSplitter.SplitExpenses(persons);

            Console.WriteLine();

            Console.WriteLine(p1.ToString());
            Console.WriteLine();

            Console.WriteLine(p2.ToString());
            Console.WriteLine();

            Console.WriteLine(p3.ToString());
            Console.WriteLine();
        }
        public void Test_Person_ToString()
        {
            Person person = new Person("Test Name");
            person.AddExpense(10.25m);
            person.AddPayoutObligation("Test creditor", 23.45m);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Person Name: Test Name");
            sb.AppendLine("Expense: 10.25");
            sb.AppendLine("Payout Obligation: 23.45 to Test creditor");

            Assert.AreEqual(sb.ToString(), person.ToString());
        }
        public void Test_ExpenseSplitter_OneParty()
        {
            //there is no debt to redistribute

            Person p1 = new Person("John Debtor");
            p1.AddExpense(9m);
            p1.AddExpense(1m);

            SortedList<string, Person> persons = new SortedList<string, Person>();
            persons.Add(p1.PersonName, p1);

            Assert.AreEqual(0, p1.PayoutObligations.Count);
        }
        public void Test_ExpenseSplitter_TwoParties()
        {
            Person p1 = new Person("Sally Debtor");
            Person p2 = new Person("Mark Creditor");

            //sally is the debtor
            p1.AddExpense(10m);
            p1.AddExpense(10m);

            //mark is the creditor
            p2.AddExpense(30m);

            SortedList<string, Person> persons = new SortedList<string, Person>();
            persons.Add(p1.PersonName, p1);
            persons.Add(p2.PersonName, p2);

            ExpenseSplitter.SplitExpenses(persons);

            Assert.AreEqual(1, p1.PayoutObligations.Count);
            Assert.AreEqual("Mark Creditor", p1.PayoutObligations[0].Key);
            Assert.AreEqual(5m, p1.PayoutObligations[0].Value);

            Assert.AreEqual(0, p2.PayoutObligations.Count);
        }