Example #1
0
 def test_interest_with_negative_amount(self):
     assert InterestCalculator(-1).interest() == 0
    if args.years is not None and args.years < 1:
        print('Error: YEARS must be at least 1.')
        return False

    return True


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Compound interest calculator.")
    parser.add_argument('-p', '--principal', required=True, help='The principal amount')
    parser.add_argument('-r', '--rate', required=True, help='The interest rate')
    parser.add_argument('-c', '--compounds_per_year', help='The number of compounds per year')
    parser.add_argument('-i', '--inflation_rate', help='The annual inflation rate')
    parser.add_argument('-y', '--years', help='Number of years. Default=10', type=int, default=10)
    args = parser.parse_args()
    if not valid_args(args):
        parser.print_help()
        sys.exit(1)

    calculator = InterestCalculator(args.principal, args.rate)
    if args.compounds_per_year:
        calculator.compounds_per_year = args.compounds_per_year
    if args.inflation_rate:
        calculator.inflation_rate = args.inflation_rate

    x = iter(calculator)
    print("Year, Balance, Balance adjusted for inflation")
    for i in range(args.years+1):
        amounts = next(x)
        print('{0:d}, {1:.2f}, {2:.2f}'.format(i, amounts[0], amounts[1]))
Example #3
0
 def test_interest_third_tier(self):
     assert InterestCalculator(3200).calculate() == 3280
Example #4
0
 def test_interest_with_zero_amount(self):
     assert InterestCalculator(0).interest() == 0
Example #5
0
 def test_interest_first_tier(self):
     assert InterestCalculator(900).calculate() == 913.5
Example #6
0
 def test_interest_second_tier(self):
     assert InterestCalculator(1100).calculate() == 1122
Example #7
0
 def test_calculate_with_negative_amount(self):
     assert InterestCalculator(-1).calculate() == 0
Example #8
0
 def test_calculate_with_zero_amount(self):
     assert InterestCalculator(0).calculate() == 0
Example #9
0
 def test_interest_third_tier(self):
     assert InterestCalculator(3200).interest() == 0.025
Example #10
0
 def test_interest_second_tier(self):
     assert InterestCalculator(1100).interest() == 0.02
Example #11
0
 def test_interest_first_tier(self):
     assert InterestCalculator(900).interest() == 0.015