1 from unittest import TestCase
2 from bluechips.tests import *
3 from bluechips.model.types import Currency
4 from decimal import Decimal
6 class TestCurrency(TestCase):
7 def test_initialization(self):
9 Make sure the constructor for Currency works
11 self.assert_(Currency(1) is Currency(1),
12 "Currency objects not interned")
13 self.assert_(Currency("0.01") is Currency(1),
14 "Currency string conversion breaks")
16 def test_additionMath(self):
18 Confirm that addition works over currency types and ints
20 self.assertEqual(Currency(2) + 2, Currency(4))
21 self.assertEqual(2 + Currency(2), Currency(4))
22 self.assertEqual(Currency(2) + Currency(2), Currency(4))
24 def test_additionType(self):
26 Check that adding Currencies or a Currency and an int yields a
29 self.assertEqual(type(Currency(2) + 2), Currency)
30 self.assertEqual(type(2 + Currency(2)), Currency)
31 self.assertEqual(type(Currency(2) + Currency(2)), Currency)
33 def test_multiplication(self):
35 This test tests the same 3 things as ``test_addition``, but
38 assert Currency(100) * Decimal(0.25) is Currency(25), \
39 "Currency * Decimal is Currency"
40 assert Decimal(0.25) * Currency(100) is Currency(25), \
41 "Decimal * Currency is Currency"