class TestAtm(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_enter_true_pin_and_check_balance(self): '''Enter the correct pin and check the balance''' balance = self.atm.check_balance() self.assertEqual(10000, balance) def test_gives_4000_money(self): '''Give money in the amount of 4000''' money = self.atm.get_money(4000) self.assertEqual(4000, money) def test_gives_10000_money(self): '''Give money in the amount of 10000''' money = self.atm.get_money(10000) self.assertEqual(10000, money) def test_gives_9999_money(self): '''Give money in the amount of 9999''' money = self.atm.get_money(9999) self.assertEqual(9999, money) def test_gives_0_money(self): '''Give money in the amount of 0''' money = self.atm.get_money(0) self.assertEqual(0, money) @unittest.skip("Bug #0001") def test_gives_min_1_money(self): '''A negative amount is given''' money = self.atm.get_money(-1) self.assertEqual(0, money) def test_rise_1000000_money(self): '''Add the amount of 1000000''' rise_money = self.atm._rise_money(1000000) self.assertEqual(1010000, rise_money) def test_rise_0_money(self): '''Add the amount of 0''' rise_money = self.atm._rise_money(0) self.assertEqual(10000, rise_money) @unittest.skip("Bug #0002") def test_rise_min_1_money(self): '''A negative amount is added''' rise_money = self.atm._rise_money(-1) self.assertEqual(10000, rise_money)
#===============================Version 3==================================== balance = Atm() while True: user_input = input("deposit, withdraw, check balance, history\n :") if user_input == 'cancel': break if user_input == 'deposit': user_deposit = round( int(input("How much money do you want to deposit.\n: $")), 2) balance.deposit(user_deposit) print(balance.check_balance()) elif user_input == 'withdraw': user_withdrawal = round( int(input("How much money do you want to withdraw? \n: $")), 2) balance.check_withdrawal(user_withdrawal) print( f"you have ${balance.withdraw(user_withdrawal)} remaining in your account" ) elif user_input == 'check_balance': #time is months time = float(input("How many months has your account been open")) print( f" your total balance including interst earned is {balance.calc_interest(time)}" )
from atm import Atm #=================================Version 1==================================== #my initial balance. setting the balance variable to the aAtm type var = Atm() #calling the check balance method print(var.check_balance()) #calling the deposit method user_deposit = round(int(input("How much money do you want to depost.\n: $")), 2) var.deposit(user_deposit) #calling the check balance method print(var.check_balance()) #inputting how much money to withdraw, calls the check_withdrawal method, calls the withdraw funtio in the print statement user_withdrawal = round( int(input("How much money do you want to withdraw? \n: $")), 2) var.check_withdrawal(user_withdrawal) print(f"you have ${var.withdraw(user_withdrawal)} remaining in your account") #to determine the interest, i input how many months the account has been open and then call the calc_interest method. time = float(input("How many months has your account been open")) print( f" your total balance including interst earned is {var.calc_interest(time)}" )
class TestAtmPinBlock(unittest.TestCase): """ Testing block with a pin input """ def setUp(self): self.term = Atm() def test_input_correct_pin_and_get_balance(self): self.term.enter_pin(777) bal = self.term.check_balance() self.assertEqual(bal, 10000) def test_input_wrong_pin_three_times_and_get_error_message(self): try: self.term.enter_pin(111) self.term.enter_pin(111) self.term.enter_pin(111) except IncorrectPin as e: pass except AttemptsOver as e: self.assertEqual('Attempts are over!!!', e.message) def test_input_wrong_pin_two_times_then_correct_and_get_balance(self): try: self.term.enter_pin(111) self.term.enter_pin(111) self.term.enter_pin(777) bal = self.term.check_balance() self.assertEqual(bal, 10000) except IncorrectPin as e: pass def test_input_pin_value_more_than_three_characters(self): try: self.term.enter_pin(8888) except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_less_than_three_characters(self): try: self.term.enter_pin(88) except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_string(self): try: self.term.enter_pin("something") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_char(self): try: self.term.enter_pin('A') except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_empty(self): try: self.term.enter_pin("") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_space(self): try: self.term.enter_pin(" ") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_without_input_pin_check_balance(self): try: self.term.check_balance() except Exception as e: self.assertEqual("Enter pin first!!!", e.message) def test_without_input_pin_get_money(self): try: self.term.get_money(1000) except Exception as e: self.assertEqual("Enter pin first!!!", e.message) def test_without_input_pin_rise_money(self): try: self.term._rise_money(1000) except Exception as e: self.assertEqual("Enter pin first!!!", e.message)
class TestAtmMoneyBlock(unittest.TestCase): """ Testing block with a cash transactions """ def setUp(self): self.term = Atm() self.term.enter_pin(777) def test_rise_money(self): rise = self.term._rise_money(1000) self.assertEqual(rise, 11000) def test_get_money(self): get = self.term.get_money(1000) balance = self.term.check_balance() self.assertEqual(balance, 10000 - get) def test_rise_money_with_negative_value(self): try: self.term._rise_money(-1000) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_zero_value(self): try: self.term._rise_money(0) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_very_big_value(self): try: self.term._rise_money(999999999) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_string_value(self): try: self.term._rise_money("Something") except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_character_value(self): try: self.term._rise_money('A') except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_negative_value(self): try: self.term.get_money(-1000) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_zero_value(self): try: self.term.get_money(0) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_very_big_value(self): try: self.term.get_money(999999999) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_string_value(self): try: self.term.get_money("Something") except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_character_value(self): try: self.term.get_money('A') except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message)