Example #1
0
    def test_data_formaters_payments2(self):

        mgr = DebtManager()
        alice = Person("Alice")
        bob = Person("Bob")
        carl = Person("Carl")

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "Restaurant le Grizzli")
        outlay.items.add(Item((alice,), "Starter", 500))
        outlay.items.add(Item((alice,), "Course", 2000))
        outlay.items.add(Item((bob,), "Course", 2500))
        outlay.items.add(Item((bob,), "Wine", 1000))
        outlay.payments.add(Payment((carl,), 6000))
        mgr.transactions.add(outlay)

        outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
        outlay.addPersons((alice, bob, carl))
        outlay.payments.add(Payment((bob,), 3000))
        mgr.transactions.add(outlay)

        expected = {
            carl: {
                (datetime(2010, 3, 15, 20, 0, 0), "Restaurant le Grizzli", 6000): set((
                    6000,
                )),
            },

            Person("Bob"): {
                (datetime(2010, 3, 15, 21, 0, 0), "Cinema", 3000): set((3000, )),
            },
        }

        result = mgr.getPaymentsPerPerson()
        self.assertEqual(result, expected)
Example #2
0
    def test_real_example(self):
        mgr = DebtManager()
        alice = Person("Alice")
        bob = Person("Bob")
        cesar = Person("Cesar")
        daniel = Person("Daniel")
        empu = Person("Empu")

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T1")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1500))
        outlay.items.add(Item((bob,), "B", 1700))
        outlay.items.add(Item((cesar,), "C", 1600))
        outlay.items.add(Item((daniel,), "D", 1500))
        outlay.items.add(Item((empu,), "E", 1000))
        outlay.items.add(Item((alice, bob, cesar, daniel), "F", 2000))
        outlay.payments.add(Payment((alice,), 9300))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T2")
        mgr.transactions.add(outlay)
        outlay.addPersons((alice, bob, cesar, daniel, empu))
        outlay.payments.add(Payment((bob,), 7500))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T3")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1000))
        outlay.items.add(Item((bob,), "B", 700))
        outlay.items.add(Item((cesar,), "C", 900))
        outlay.payments.add(Payment((cesar,), 2600))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T4")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 700))
        outlay.items.add(Item((bob,), "B", 700))
        outlay.items.add(Item((daniel,), "D", 700))
        outlay.items.add(Item((empu,), "E", 700))
        outlay.payments.add(Payment((daniel,), 2800))

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T5")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1800))
        outlay.items.add(Item((bob,), "B", 1500))
        outlay.items.add(Item((cesar,), "C", 2000))
        outlay.items.add(Item((daniel,), "D", 2000))
        outlay.items.add(Item((empu,), "E", 1700))
        outlay.payments.add(Payment((bob,), 5300))
        outlay.payments.add(Payment((empu,), 3700))

        result = mgr.computeDebts()

        expected = (
            (cesar, 3900, bob),
            (daniel, 2300, bob),
            (empu, 1200, alice),
            (daniel, 1100, alice),
        )
        self.assertEqual(result, expected)
Example #3
0
 def test_rounding_bug_when_item_payment_balance_is_not_null(self):
     mgr = DebtManager()
     alice = Person("Alice")
     bob = Person("Bob")
     outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
     mgr.transactions.add(outlay)
     outlay.payments.add(Payment((bob,), 3))
     outlay.addPersons((alice,))
     result = mgr.computeDebts()
     expected = ((alice, 1, bob),)
     self.assertEqual(result, expected)
Example #4
0
 def test_with_missing_payments(self):
     mgr = DebtManager()
     alice = Person("Alice")
     bob = Person("Bob")
     outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
     mgr.transactions.add(outlay)
     outlay.items.add(Item((bob, alice, ), "Item", 2000))
     outlay.payments.add(Payment((bob,), 1000))
     result = mgr.computeDebts()
     expected = ((alice, 500, bob),)
     self.assertEqual(result, expected)
Example #5
0
    def test_simple_example(self):
        """
            Bob and Alice go to a restaurant, and after that to the cinema.
            Alice eats for ¤25 (a starter then a course)
            Bob eats for ¤35 (a course and some wine)
            Alice pays for the restaurant.

            The cinema's fee is ¤10
            Bob pays for it.
        """
        mgr = DebtManager()
        alice = Person("Alice")
        bob = Person("Bob")

        # When, what, how much, in cents
        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "Restaurant le Grizzli")
        mgr.transactions.add(outlay)
        # Who has consummed, what, how much
        outlay.items.add(Item((alice,), "Starter", 500))
        outlay.items.add(Item((alice,), "Course", 2000))
        outlay.items.add(Item((bob,), "Course", 2500))
        outlay.items.add(Item((bob,), "Wine", 1000))
        # Who, how much
        outlay.payments.add(Payment((alice,), 6000))

        outlay = Outlay(datetime(2010, 3, 15, 21, 0, 0), "Cinema")
        mgr.transactions.add(outlay)
        # Who has consummed, what, how much
        outlay.items.add(Item((alice, bob), "ticket", 2000))
        # Who, how much
        outlay.payments.add(Payment((bob,), 2000))

        # Who owes who how much?
        result = mgr.computeDebts()

        # Bob should pay back ¤25,00.
        expected = (
            (bob, 2500, alice),
        )
        self.assertEqual(result, expected)
Example #6
0
    def test_void_operation(self):
        mgr = DebtManager()
        result = mgr.computeDebts()
        expected = ()
        self.assertEqual(result, expected)

        alice = Person("Alice")
        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T1")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1))

        result = mgr.computeDebts()
        expected = ()
        self.assertEqual(result, expected)

        bob = Person("Bob")
        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T2")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1))
        outlay.items.add(Item((bob,), "B", 1))

        result = mgr.computeDebts()
        expected = ()
        self.assertEqual(result, expected)

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T3")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1))
        outlay.items.add(Item((bob,), "B", 1))
        outlay.payments.add(Payment((alice, bob), 2))

        result = mgr.computeDebts()
        expected = ()
        self.assertEqual(result, expected)

        outlay = Outlay(datetime(2010, 3, 15, 20, 0, 0), "T4")
        mgr.transactions.add(outlay)
        outlay.items.add(Item((alice,), "A", 1))
        outlay.payments.add(Payment((bob,), 1))

        result = mgr.computeDebts()
        expected = ((alice, 1, bob), )
        self.assertEqual(result, expected)