5 import unittest_utils as uu
6 from type.money import Money
7 from type.rate import Rate
10 class TestRate(unittest.TestCase):
11 def test_basic_utility(self):
12 my_stock_returns = Rate(percent_change=-20.0)
14 self.assertAlmostEqual(800.0, my_stock_returns.apply_to(my_portfolio))
16 my_bond_returns = Rate(percentage=104.5)
17 my_money = Money(500.0)
18 self.assertAlmostEqual(Money(522.5), my_bond_returns.apply_to(my_money))
20 my_multiplier = Rate(multiplier=1.72)
22 self.assertAlmostEqual(5.504, my_multiplier.apply_to(my_nose_length))
24 def test_conversions(self):
28 self.assertAlmostEqual(x, y)
31 self.assertAlmostEqual(x, z)
33 def test_divide(self):
36 self.assertAlmostEqual(10.0, x)
39 self.assertAlmostEqual(-10.0, x)
45 self.assertAlmostEqual(15.0, z)
48 self.assertAlmostEqual(5.0, x)
54 self.assertAlmostEqual(-5.0, z)
56 self.assertAlmostEqual(5.0, z)
59 x = Rate(percent_change=-50.0)
60 s = x.__repr__(relative=True)
61 self.assertEqual("-50.000%", s)
63 self.assertEqual("+50.000%", s)
66 if __name__ == '__main__':