3 # © Copyright 2021-2022, Scott Gasch
9 import unittest_utils as uu
10 from type.money import Money
11 from type.rate import Rate
14 class TestRate(unittest.TestCase):
15 def test_basic_utility(self):
16 my_stock_returns = Rate(percent_change=-20.0)
18 self.assertAlmostEqual(800.0, my_stock_returns.apply_to(my_portfolio))
20 my_bond_returns = Rate(percentage=104.5)
21 my_money = Money(500.0)
22 self.assertAlmostEqual(Money(522.5), my_bond_returns.apply_to(my_money))
24 my_multiplier = Rate(multiplier=1.72)
26 self.assertAlmostEqual(5.504, my_multiplier.apply_to(my_nose_length))
28 def test_conversions(self):
32 self.assertAlmostEqual(x, y)
35 self.assertAlmostEqual(x, z)
37 def test_divide(self):
40 self.assertAlmostEqual(10.0, x)
43 self.assertAlmostEqual(-10.0, x)
49 self.assertAlmostEqual(15.0, z)
52 self.assertAlmostEqual(5.0, x)
58 self.assertAlmostEqual(-5.0, z)
60 self.assertAlmostEqual(5.0, z)
63 x = Rate(percent_change=-50.0)
64 s = x.__repr__(relative=True)
65 self.assertEqual("-50.000%", s)
67 self.assertEqual("+50.000%", s)
70 if __name__ == '__main__':