"""
Make sure the constructor for Currency works with strings
"""
- self.assertEqual(Currency("0.01"), Currency(1),
- "Currency string conversion breaks")
+ self.assertEqual(Currency("0.01"), Currency(1))
self.assert_(Currency("0.01") is Currency(1),
"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):
"""
Confirm that addition works over currency types and ints