5 from type.rate import Rate
6 from type.money import Money
8 import unittest_utils as uu
11 class TestRate(unittest.TestCase):
12 def test_basic_utility(self):
13 my_stock_returns = Rate(percent_change=-20.0)
15 self.assertAlmostEqual(
17 my_stock_returns.apply_to(my_portfolio)
20 my_bond_returns = Rate(percentage=104.5)
21 my_money = Money(500.0)
22 self.assertAlmostEqual(
24 my_bond_returns.apply_to(my_money)
27 my_multiplier = Rate(multiplier=1.72)
29 self.assertAlmostEqual(
31 my_multiplier.apply_to(my_nose_length)
34 def test_conversions(self):
38 self.assertAlmostEqual(x, y)
41 self.assertAlmostEqual(x, z)
43 def test_divide(self):
46 self.assertAlmostEqual(10.0, x)
49 self.assertAlmostEqual(-10.0, x)
55 self.assertAlmostEqual(15.0, z)
58 self.assertAlmostEqual(5.0, x)
64 self.assertAlmostEqual(-5.0, z)
66 self.assertAlmostEqual(5.0, z)
69 x = Rate(percent_change=-50.0)
70 s = x.__repr__(relative=True)
71 self.assertEqual("-50.000%", s)
73 self.assertEqual("+50.000%", s)
76 if __name__ == '__main__':