]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/tests/model/test_currency.py
Test Currency.__str_no_dollar__
[bluechips.git] / bluechips / tests / model / test_currency.py
index 4e3a1b908b7cd704073ccd15fdce59a75f018318..a689778eea64c7c9f32d3d45bf73c31f6dd01b78 100644 (file)
@@ -4,14 +4,41 @@ from bluechips.model.types import Currency
 from decimal import Decimal
 
 class TestCurrency(TestCase):
-    def test_initialization(self):
+    def test_initInt(self):
         """
         Make sure the constructor for Currency works
         """
         self.assert_(Currency(1) is Currency(1), 
                      "Currency objects not interned")
+    def test_initString(self):
+        """
+        Make sure the constructor for Currency works with strings
+        """
+        self.assertEqual(Currency("0.01"), Currency(1))
         self.assert_(Currency("0.01") is Currency(1),
-                     "Currency string conversion breaks")
+                     "string and int constructors return different values")
+    
+    def test_string(self):
+        """
+        Test converting a Currency to a string
+        """
+        self.assertEqual(str(Currency(1)), "$0.01")
+        self.assertEqual(str(Currency(100)), "$1.00")
+        self.assertEqual(str(Currency(101)), "$1.01")
+        self.assertEqual(str(Currency(-1)), "-$0.01")
+        self.assertEqual(str(Currency(-100)), "-$1.00")
+        self.assertEqual(str(Currency(-101)), "-$1.01")
+    
+    def test_stringNoDollar(self):
+        """
+        Test that Currency values can be retrieved without the dollar sign
+        """
+        self.assertEqual(Currency(1).__str_no_dollar__(), "0.01")
+        self.assertEqual(Currency(100).__str_no_dollar__(), "1.00")
+        self.assertEqual(Currency(101).__str_no_dollar__(), "1.01")
+        self.assertEqual(Currency(-1).__str_no_dollar__(), "-0.01")
+        self.assertEqual(Currency(-100).__str_no_dollar__(), "-1.00")
+        self.assertEqual(Currency(-101).__str_no_dollar__(), "-1.01")
     
     def test_additionMath(self):
         """
@@ -23,19 +50,27 @@ class TestCurrency(TestCase):
     
     def test_additionType(self):
         """
-        Check that adding Currencies or a Currency and an int yields a
+        Adding Currencies or a Currency and an int should yield a
         Currency
         """
         self.assertEqual(type(Currency(2) + 2), Currency)
         self.assertEqual(type(2 + Currency(2)), Currency)
         self.assertEqual(type(Currency(2) + Currency(2)), Currency)
         
-    def test_multiplication(self):
+    def test_multMath(self):
         """
         This test tests the same 3 things as ``test_addition``, but
         for multiplication
         """
-        assert Currency(100) * Decimal(0.25) is Currency(25), \
-            "Currency * Decimal is Currency"
-        assert Decimal(0.25) * Currency(100) is Currency(25), \
-            "Decimal * Currency is Currency"
+        self.assertEqual(Currency(100) * Decimal("0.25"), Currency(25))
+        self.assertEqual(Decimal("0.25") * Currency(100), Currency(25))
+        self.assertEqual(Currency(10) * Currency(10), Currency(100))
+    
+    def test_multType(self):
+        """
+        The result of multiplying a Currency with something else
+        should be a currency
+        """
+        self.assertEqual(type(Currency(100) * Decimal("0.25")), Currency)
+        self.assertEqual(type(Decimal("0.25") * Currency(100)), Currency)
+        self.assertEqual(type(Currency(100) * Currency(100)), Currency)