]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/tests/model/test_currency.py
Pull more things into their own tests for Currency
[bluechips.git] / bluechips / tests / model / test_currency.py
1 from unittest import TestCase
2 from bluechips.tests import *
3 from bluechips.model.types import Currency
4 from decimal import Decimal
5
6 class TestCurrency(TestCase):
7     def test_initInt(self):
8         """
9         Make sure the constructor for Currency works
10         """
11         self.assert_(Currency(1) is Currency(1), 
12                      "Currency objects not interned")
13     def test_initString(self):
14         """
15         Make sure the constructor for Currency works with strings
16         """
17         self.assertEqual(Currency("0.01"), Currency(1),
18                      "Currency string conversion breaks")
19         self.assert_(Currency("0.01") is Currency(1),
20                      "string and int constructors return different values")
21     
22     def test_additionMath(self):
23         """
24         Confirm that addition works over currency types and ints
25         """
26         self.assertEqual(Currency(2) + 2, Currency(4))
27         self.assertEqual(2 + Currency(2), Currency(4))
28         self.assertEqual(Currency(2) + Currency(2), Currency(4))
29     
30     def test_additionType(self):
31         """
32         Adding Currencies or a Currency and an int should yield a
33         Currency
34         """
35         self.assertEqual(type(Currency(2) + 2), Currency)
36         self.assertEqual(type(2 + Currency(2)), Currency)
37         self.assertEqual(type(Currency(2) + Currency(2)), Currency)
38         
39     def test_multMath(self):
40         """
41         This test tests the same 3 things as ``test_addition``, but
42         for multiplication
43         """
44         self.assertEqual(Currency(100) * Decimal("0.25"), Currency(25))
45         self.assertEqual(Decimal("0.25") * Currency(100), Currency(25))
46         self.assertEqual(Currency(10) * Currency(10), Currency(100))
47     
48     def test_multType(self):
49         """
50         The result of multiplying a Currency with something else
51         should be a currency
52         """
53         self.assertEqual(type(Currency(100) * Decimal("0.25")), Currency)
54         self.assertEqual(type(Decimal("0.25") * Currency(100)), Currency)
55         self.assertEqual(type(Currency(100) * Currency(100)), Currency)