]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/tests/model/test_currency.py
More tests for the Currency type
[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_initialization(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         self.assert_(Currency("0.01") is Currency(1),
14                      "Currency string conversion breaks")
15     
16     def test_additionMath(self):
17         """
18         Confirm that addition works over currency types and ints
19         """
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))
23     
24     def test_additionType(self):
25         """
26         Check that adding Currencies or a Currency and an int yields a
27         Currency
28         """
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)
32         
33     def test_multiplication(self):
34         """
35         This test tests the same 3 things as ``test_addition``, but
36         for multiplication
37         """
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"