]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
added some tests for settle()
authorScott Torborg <scott@crookedmedia.com>
Sun, 8 Nov 2009 21:37:45 +0000 (13:37 -0800)
committerScott Torborg <scott@crookedmedia.com>
Sun, 8 Nov 2009 21:37:45 +0000 (13:37 -0800)
bluechips/lib/totals.py
bluechips/tests/lib/test_totals.py [new file with mode: 0644]
bluechips/tests/lib/totals.py [deleted file]

index 730ca648ea1b228c3f10ab712d0b77868858cd29..e0c455967d1566c0815c462e9bf22677884fc008 100644 (file)
@@ -94,9 +94,9 @@ def settle(debts_dict):
         settle_list.append((owes['who'], owed['who'], val))
     
     if len(owes_list) > 0:
-        raise DirtyBooks, ("People still owe money", owes_list) #pragma:nocover
+        raise DirtyBooks, ("People still owe money", owes_list)
     if len(owed_list) > 0:
-        raise DirtyBooks, ("People are still owed money", owed_list) #pragma:nocover
+        raise DirtyBooks, ("People are still owed money", owed_list)
     
     return settle_list
 
diff --git a/bluechips/tests/lib/test_totals.py b/bluechips/tests/lib/test_totals.py
new file mode 100644 (file)
index 0000000..fb3e6f2
--- /dev/null
@@ -0,0 +1,47 @@
+from unittest import TestCase
+from bluechips.lib import totals
+
+class TestReorderingSettle(TestCase):
+    def test_transfer_minimized(self):
+        """
+        Test that the number of transfers is actually minimized.
+
+        Taken from a real-world situation, we discovered that failing
+        to re-order the debt lists after every transfer could lead to
+        extra, unnecessary transfers.
+        """
+        self.assertEqual(len(totals.settle({'Alice': 100,
+                                            'Bob': -85,
+                                            'Charlie': 35,
+                                            'Dave': -35,
+                                            'Eve': -15})),
+                         3)
+
+    def test_settle_even(self):
+        transfers = totals.settle({'Alice': 0,
+                                   'Bob': 0,
+                                   'Charlie': 0})
+        assert transfers == []
+    
+    def test_settle_positive(self):
+        transfers = totals.settle({'Alice': -50,
+                                   'Bob': 100,
+                                   'Charlie': -50})
+        assert transfers == [('Bob', 'Charlie', 50),
+                             ('Bob', 'Alice', 50)]
+
+    def test_settle_uneven_positive(self):
+        try:
+            transfers = totals.settle({'Alice': -50,
+                                       'Bob': -50,
+                                       'Charlie': -50})
+        except totals.DirtyBooks:
+            pass
+
+    def test_settle_uneven_negative(self):
+        try:
+            transfers = totals.settle({'Alice': 50,
+                                       'Bob': 50,
+                                       'Charlie': 50})
+        except totals.DirtyBooks:
+            pass
diff --git a/bluechips/tests/lib/totals.py b/bluechips/tests/lib/totals.py
deleted file mode 100644 (file)
index ac1d38c..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-from unittest import TestCase
-from bluechips.lib import totals
-
-class TestReorderingSettle(TestCase):
-    def test(self):
-        """
-        Test that the number of transfers is actually minimized.
-
-        Taken from a real-world situation, we discovered that failing
-        to re-order the debt lists after every transfer could lead to
-        extra, unnecessary transfers.
-        """
-        self.assertEqual(len(totals.settle({'Alice': 100,
-                                            'Bob': -85,
-                                            'Charlie': 35,
-                                            'Dave': -35,
-                                            'Eve': -15})),
-                         3)