def test_multiply_with_float(self): result1 = Money(32.34) * 4.4 result2 = 4.4 * Money(32.34) expected_result = Money(142.30) self.assertEqual(expected_result, result1) self.assertEqual(expected_result, result2)
def test_multiply_with_float_other(self): result1 = Money(100000.00) * 0.0375 result2 = 0.0375 * Money(100000.00) expected_result = Money(3750.0) self.assertEqual(expected_result, result1) self.assertEqual(expected_result, result2)
def test_multiply_with_int(self): result1 = Money(32.34) * 15 result2 = 15 * Money(32.34) expected_result = Money(485.10) self.assertEqual(expected_result, result1) self.assertEqual(expected_result, result2)
def test_combine_payments_non_empty_multiple(self): account0 = Account("Bank0", "00", "Joe", 1000, 0.03, 100.00, date(2014, 5, 1)) account1 = Account("Bank0", "01", "Joe", 7500, 0.05, 50.00, date(2014, 5, 1)) account2 = Account("Bank1", "00", "Sam", 9000, 0.06, 900.00, date(2014, 5, 1)) payment_group0 = { account0: Money(100.00), account1: Money(50.00), account2: Money(900.00) } payment_group1 = { account0: Money(100.00), account1: Money(100.00), account2: Money(100.00) } expected_payment_group = { account0: Money(200.00), account1: Money(150.00), account2: Money(1000.00) } self.assertEqual( payoff_calculator._combine_payments(payment_group0, payment_group1), expected_payment_group)
def main(): accounts = load_accounts() # minium payment is sum of all minumum payments rounded up to nearest increment minimum_payment = round_up_to_nearest_100( sum([a.minimum_payment for a in accounts], Money(0))) increment = Money(100) scenarios = generate_scenarios(load_personal_information(), accounts, minimum_payment, increment) display_scenarios(scenarios)
def test_determine_max_payment_for_should_return_constant_with_different_payments_per_year( self): payment_date = date(2014, 1, 1) expected_max_payment = (Money(1000), Money(100)) self.assertEqual( self.payment_manager.determine_max_payment_for(1, payment_date), expected_max_payment) self.assertEqual( self.payment_manager.determine_max_payment_for(4, payment_date), expected_max_payment) self.assertEqual( self.payment_manager.determine_max_payment_for(12, payment_date), expected_max_payment)
def test_determine_max_payment_for_should_return_correct_values_when_payments_per_year_when_no_raise( self): payment_date = date(2014, 1, 1) expected_max_payment = (Money(500), Money(0)) self.assertEqual( self.payment_manager.determine_max_payment_for(1, payment_date), expected_max_payment) self.assertEqual( self.payment_manager.determine_max_payment_for(4, payment_date), expected_max_payment) self.assertEqual( self.payment_manager.determine_max_payment_for(12, payment_date), expected_max_payment)
def test_determine_max_payment_for_should_return_constant_with_different_dates( self): payments_per_year = 12 expected_max_payment = (Money(1000), Money(100)) self.assertEqual( self.payment_manager.determine_max_payment_for( payments_per_year, date(2014, 1, 1)), expected_max_payment) self.assertEqual( self.payment_manager.determine_max_payment_for( payments_per_year, date(2014, 6, 1)), expected_max_payment) self.assertEqual( self.payment_manager.determine_max_payment_for( payments_per_year, date(2015, 6, 1)), expected_max_payment)
def test_analyze(self): mpd = max_payment_determiner.ConstantMaxPaymentDeterminer(2000, 50) pm = payment_manager.BiggestDebtPaymentManager() bpm = payment_manager.EvenSplitPaymentManager() (r_mpd, r_pm, r_bpm, months, initial_paid, total_paid, to_interest, monthly_payments) = analysis.analyze(mpd, pm, bpm, self.accounts) self.assertEqual(r_mpd, mpd) self.assertEqual(r_pm, pm) self.assertEqual(r_bpm, bpm) self.assertEqual(months, 75) self.assertEqual(initial_paid, Money(133000.00)) self.assertEqual(total_paid, Money(152349.04)) self.assertEqual(to_interest, Money(19349.04)) self.assertIsNotNone(monthly_payments)
def test_determine_max_payment_for_should_return_correct_values_when_payments_per_year_when_raise( self): payment_date = date(2014, 10, 1) self.assertEqual( self.payment_manager.determine_max_payment_for(1, payment_date), (Money(4250.00), Money(7875.00))) self.assertEqual( self.payment_manager.determine_max_payment_for(4, payment_date), (Money(1437.50), Money(0))) self.assertEqual( self.payment_manager.determine_max_payment_for(12, payment_date), (Money(812.50), Money(0)))
def test_determine_max_payment_for_should_return_correct_values_when_different_dates( self): payments_per_year = 12 self.assertEqual( self.payment_manager.determine_max_payment_for( payments_per_year, date(2014, 1, 1)), (Money(500.00), Money(0))) self.assertEqual( self.payment_manager.determine_max_payment_for( payments_per_year, date(2014, 6, 1)), (Money(812.50), Money(0))) self.assertEqual( self.payment_manager.determine_max_payment_for( payments_per_year, date(2015, 6, 1)), (Money(1125.00), Money(0)))
def test_iminus_with_decimals(self): result = Money(25.33) result -= Money(75.67) self.assertEqual(result, Money(-50.34))
def test_constructor_with_int(self): self.assertEqual(Money(int(100))._cents, 10000)
def round_up_to_nearest_100(x): return Money(utils.round_up(x, -2))
def test_constructor_with_long(self): self.assertEqual(Money(long(100))._cents, 10000)
def test_calculate_payoff_with_single_account_and_interest_and_bonus(self): max_payment_determiner = ConstantMaxPaymentDeterminer(50, 50) payment_determiner = EvenSplitPaymentManager() bonus_payment_determiner = EvenSplitPaymentManager() account0 = Account("Bank0", "00", "Joe", 1000, 0.05, 50.00, date(2014, 5, 1)) accounts = (account0, ) starting_date = date(2014, 6, 30) expected_total_payments_amount = Money(1023.61) expected_total_payments_count = 11 expected_total_payments = [(date(2014, 6, 30), { account0: (Money(100), Money(904.17)) }), (date(2014, 7, 30), { account0: (Money(100), Money(807.94)) }), (date(2014, 8, 30), { account0: (Money(100), Money(711.31)) }), (date(2014, 9, 30), { account0: (Money(100), Money(614.27)) }), (date(2014, 10, 30), { account0: (Money(100), Money(516.83)) }), (date(2014, 11, 30), { account0: (Money(100), Money(418.98)) }), (date(2014, 12, 30), { account0: (Money(100), Money(320.73)) }), (date(2015, 1, 30), { account0: (Money(100), Money(222.07)) }), (date(2015, 2, 28), { account0: (Money(100), Money(123.00)) }), (date(2015, 3, 28), { account0: (Money(100), Money(23.51)) }), (date(2015, 4, 28), { account0: (Money(23.61), Money(0)) })] (total_amount, payments_count, total_payoffs) = payoff_calculator.calculate_payoff( max_payment_determiner, payment_determiner, bonus_payment_determiner, accounts, starting_date) self.assertEqual(total_amount, expected_total_payments_amount) self.assertEqual(payments_count, expected_total_payments_count) self.assertEqual(total_payoffs, expected_total_payments)
def test_constructor_with_decimal(self): self.assertEqual(Money(decimal.Decimal(100.00))._cents, 10000)
def test_constructor_with_float(self): self.assertEqual(Money(float(100.00))._cents, 10000) self.assertEqual(Money(float(32.34))._cents, 3234)
def test_dump_monthly_payments_to_csv(self): account0 = Account("Bank1", "00", "Person2", 5000.00, 0.05, 50.00, datetime.date(2014, 10, 7)) account1 = Account("Bank1", "01", "Person2", 3000.00, 0.04, 40.00, datetime.date(2014, 10, 7)) account2 = Account("Bank1", "02", "Person2", 7000.00, 0.03, 100.00, datetime.date(2014, 10, 7)) monthly_payments = [(datetime.date(2014, 10, 6), { account2: (Money(1926.67), Money(5090.83)), account0: (Money(66.67), Money(4954.16)), account1: (Money(56.67), Money(2953.33)) }), (datetime.date(2014, 11, 6), { account2: (Money(1926.67), Money(3176.89)), account0: (Money(66.67), Money(4908.13)), account1: (Money(56.67), Money(2906.50)) }), (datetime.date(2014, 12, 6), { account2: (Money(116.67), Money(3068.16)), account0: (Money(1876.67), Money(3051.91)), account1: (Money(56.67), Money(2859.52)) }), (datetime.date(2015, 1, 6), { account2: (Money(1926.67), Money(1149.16)), account0: (Money(66.67), Money(2997.96)), account1: (Money(56.67), Money(2812.38)) }), (datetime.date(2015, 2, 6), { account2: (Money(116.67), Money(1035.36)), account0: (Money(1876.67), Money(1133.78)), account1: (Money(56.67), Money(2765.08)) }), (datetime.date(2015, 3, 6), { account2: (Money(116.67), Money(921.28)), account0: (Money(66.67), Money(1071.83)), account1: (Money(1866.67), Money(907.63)) }), (datetime.date(2015, 4, 6), { account2: (Money(908.70), Money(14.88)), account0: (Money(1076.30), Money(0.00)), account1: (Money(65.00), Money(845.66)) }), (datetime.date(2015, 5, 6), { account2: (Money(14.92), Money(0.00)), account1: (Money(848.48), Money(0.00)) })] output_file = os.path.join(self.temp_dir, 'test.csv') analysis.dump_monthly_payments_to_csv(output_file, monthly_payments) self.assertTrue(os.path.isfile(output_file)) self.assertEqual( open(output_file).readlines(), open( os.path.join('tests', 'data', 'expected-test-results-dump.csv')).readlines())
def test_iminus(self): result = Money(25) result -= Money(75) self.assertEqual(result, Money(-50))
def test_negative(self): result = -Money(25) self.assertEqual(result, Money(-25))
def test_iplus_with_decimals(self): result = Money(25.33) result += Money(75.67) self.assertEqual(result, Money(101))
def test_iplus(self): result = Money(25) result += Money(75) self.assertEqual(result, Money(100))
def test_str(self): self.assertEqual(str(Money(int(100))), "$100.00")
def test_not_empty_when_not_empty(self): self.assertTrue(Money(1))
def test_not_empty_when_empty(self): self.assertFalse(Money(0))
def test_calculate_payoff_with_single_account_and_no_interest_and_bonus( self): max_payment_determiner = ConstantMaxPaymentDeterminer(50, 50) payment_determiner = EvenSplitPaymentManager() bonus_payment_determiner = EvenSplitPaymentManager() account0 = Account("Bank0", "00", "Joe", 1000, 0, 50.00, date(2014, 5, 1)) accounts = (account0, ) starting_date = date(2014, 6, 30) expected_total_payments_amount = Money(1000) expected_total_payments_count = 10 expected_total_payments = [(date(2014, 6, 30), { account0: (Money(100), Money(900.00)) }), (date(2014, 7, 30), { account0: (Money(100), Money(800.00)) }), (date(2014, 8, 30), { account0: (Money(100), Money(700.00)) }), (date(2014, 9, 30), { account0: (Money(100), Money(600.00)) }), (date(2014, 10, 30), { account0: (Money(100), Money(500.00)) }), (date(2014, 11, 30), { account0: (Money(100), Money(400.00)) }), (date(2014, 12, 30), { account0: (Money(100), Money(300.00)) }), (date(2015, 1, 30), { account0: (Money(100), Money(200.00)) }), (date(2015, 2, 28), { account0: (Money(100), Money(100.00)) }), (date(2015, 3, 28), { account0: (Money(100), Money(0)) })] (total_amount, payments_count, total_payoffs) = payoff_calculator.calculate_payoff( max_payment_determiner, payment_determiner, bonus_payment_determiner, accounts, starting_date) self.assertEqual(total_amount, expected_total_payments_amount) self.assertEqual(payments_count, expected_total_payments_count) self.assertEqual(total_payoffs, expected_total_payments)
def test_constructor_with_money(self): other_money = Money(100.00) self.assertEqual(Money(other_money)._cents, 10000)
def test_long(self): money = Money("3.43") result = long(money) self.assertEqual(result, long(3))
def test_constructor_with_string(self): self.assertEqual(Money("100.00")._cents, 10000)