5 from type.centcount import CentCount
6 import unittest_utils as uu
9 class TestCentCount(unittest.TestCase):
11 def test_basic_utility(self):
12 amount = CentCount(1.45)
13 another = CentCount.parse("USD 1.45")
14 self.assertEqual(amount, another)
16 def test_negation(self):
17 amount = CentCount(1.45)
19 self.assertEqual(CentCount(-1.45), amount)
21 def test_addition_and_subtraction(self):
22 amount = CentCount(1.00)
23 another = CentCount(2.00)
24 total = amount + another
25 self.assertEqual(CentCount(3.00), total)
26 delta = another - amount
27 self.assertEqual(CentCount(1.00), delta)
28 neg = amount - another
29 self.assertEqual(CentCount(-1.00), neg)
31 self.assertEqual(CentCount(1.00), neg)
33 self.assertEqual(CentCount(2.00), neg)
35 self.assertEqual(CentCount(1.00), neg)
37 self.assertEqual(CentCount(9.0), x)
39 def test_multiplication(self):
40 amount = CentCount(3.00)
42 self.assertEqual(CentCount(9.00), amount)
43 with self.assertRaises(TypeError):
44 another = CentCount(0.33)
47 def test_division(self):
48 amount = CentCount(10.00)
50 self.assertEqual(CentCount(2.00), x)
51 with self.assertRaises(TypeError):
52 another = CentCount(1.33)
55 def test_equality(self):
56 usa = CentCount(1.0, 'USD')
57 can = CentCount(1.0, 'CAD')
58 self.assertNotEqual(usa, can)
59 eh = CentCount(1.0, 'CAD')
60 self.assertEqual(can, eh)
62 def test_comparison(self):
65 three = CentCount(3.0)
66 neg_one = CentCount(-1)
67 self.assertLess(one, two)
68 self.assertLess(neg_one, one)
69 self.assertGreater(one, neg_one)
70 self.assertGreater(three, one)
71 looney = CentCount(1.0, 'CAD')
72 with self.assertRaises(TypeError):
75 def test_strict_mode(self):
76 one = CentCount(1.0, strict_mode=True)
77 two = CentCount(2.0, strict_mode=True)
78 with self.assertRaises(TypeError):
80 self.assertEqual(CentCount(3.0), one + two)
81 with self.assertRaises(TypeError):
83 self.assertEqual(CentCount(1.0), two - one)
84 with self.assertRaises(TypeError):
86 self.assertTrue(CentCount(1.0) == one)
87 with self.assertRaises(TypeError):
89 self.assertTrue(one < two)
90 with self.assertRaises(TypeError):
92 self.assertTrue(two > one)
94 def test_truncate_and_round(self):
97 x.truncate_fractional_cents()
98 self.assertEqual(CentCount(6.66), x)
101 if __name__ == '__main__':