class TestBankAcount(unittest.TestCase): def setUp(self): # Create a test BankAccount object self.account = BankAccount() # Provide it with some property values self.account.balance = 1000.0 def test_legal_deposit_works(self): # Your code here to test that depsositing money using the account's # 'deposit_funds' function adds the amount to the balance. previous_balance = self.account.balance self.account.deposit_funds(2000) self.assertGreater(self.account.balance, previous_balance) def test_illegal_deposit_raises_exception(self): # Your code here to test that depositing an illegal value (like 'bananas' # or such - something which is NOT a float) results in an exception being # raised. try: self.account.deposit_funds("bananas") except ValueError: pass except Exception as e: self.fail('Unexpected exception raised:' + str(e)) def test_legal_withdrawal(self): # Your code here to test that withdrawing a legal amount subtracts the # funds from the balance. previous_balance = self.account.balance self.account.withdraw_funds(100) self.assertLess(self.account.balance, previous_balance) def test_illegal_withdrawal(self): # Your code here to test that withdrawing an illegal amount (like 'bananas' # or such - something which is NOT a float) raises a suitable exception. try: self.account.withdraw_funds("apple") except ValueError: pass except Exception as e: self.fail('Unexpected exception raised:' + str(e)) def test_insufficient_funds_withdrawal(self): # Your code here to test that you can only withdraw funds which are available. # For example, if you have a balance of 500.00 dollars then that is the maximum # that can be withdrawn. If you tried to withdraw 600.00 then a suitable exception # should be raised and the withdrawal should NOT be applied to the account balance # or the account's transaction list. try: self.account.withdraw_funds(5000000) except Exception as e: pass
class TestBankAcount(unittest.TestCase): def setUp(self): # Create a test BankAccount object self.account = BankAccount() # Provide it with some property values self.account.balance= 1000.0 def test_legal_deposit_works(self): # deposit amount + into current balance. result = self.account.deposit_funds(500.0) self.assertEqual(self.account.balance,1500.0) def test_illegal_deposit_raises_exception(self): # deposit amount illegal amount like negative amount self.assertRaises(ValueError ,self.account.deposit_funds,'fantastic') self.assertRaises(ValueError ,self.account.deposit_funds,'-145.0') def test_legal_withdrawal(self): #withdraw amount from current balance self.account.withdraw_funds(100.0) self.assertEqual(self.account.balance,900.0) def test_illegal_withdrawal(self): # Your code here to test that withdrawing an illegal amount (like 'bananas'none) self.assertRaises(ValueError ,self.account.withdraw_funds,'anything') self.assertRaises(ValueError ,self.account.withdraw_funds,'-4.44') def test_insufficient_funds_withdrawal(self): #withdrawal fund is not more balance amount self.assertRaises(ValueError ,self.account.withdraw_funds,3100.0) self.assertRaises(ValueError ,self.account.withdraw_funds,3100.78)
class TestBankAcount(unittest.TestCase): def setUp(self): # Create a test BankAccount object self.account = BankAccount() # Provide it with some property values self.account.balance = 1000.0 def test_legal_deposit_works(self): # Your code here to test that depsositing money using the account's # 'deposit_funds' function adds the amount to the balance. curent_val = self.account.balance self.account.deposit_funds(100) self.assertEqual(self.account.balance, curent_val + 100) def test_illegal_deposit_raises_exception(self): # Your code here to test that depositing an illegal value (like 'bananas' # or such - something which is NOT a float) results in an exception being # raised. self.assertRaises(ValueError, self.account.deposit_funds(-100)) self.assertRaises(ValueError, self.account.deposit_funds('abc')) def test_legal_withdrawal(self): # Your code here to test that withdrawing a legal amount subtracts the # funds from the balance. curent_val = self.account.balance withraw = len(self.account.transaction_list) self.account.withdraw_funds(100) self.assertGreater(len(self.account.transaction_list), withraw) self.assertLessEqual(self.account.balance, curent_val) def test_illegal_withdrawal(self): # Your code here to test that withdrawing an illegal amount (like 'bananas' # or such - something which is NOT a float) raises a suitable exception. self.assertRaises(ValueError, self.account.withdraw_funds('banana')) def test_insufficient_funds_withdrawal(self): # Your code here to test that you can only withdraw funds which are available. # For example, if you have a balance of 500.00 dollars then that is the maximum # that can be withdrawn. If you tried to withdraw 600.00 then a suitable exception # should be raised and the withdrawal should NOT be applied to the account balance # or the account's transaction list. overdraw = self.account.balance + 100 self.assertRaises(ValueError, self.account.withdraw_funds(overdraw))
class TestBankAcount(unittest.TestCase): def setUp(self): # Create a test BankAccount object self.account = BankAccount() # test for save file self.account.account_number = 1100 self.account.pin_number = 1100 # Provide it with some property values self.account.balance = 1000.0 def test_legal_deposit_works(self): # Your code here to test that depsositing money using the account's # 'deposit_funds' function adds the amount to the balance. self.account.deposit_funds(2000) self.account.deposit_funds("3123") def test_illegal_deposit_raises_exception(self): # Your code here to test that depositing an illegal value (like 'bananas' # or such - something which is NOT a float) results in an exception being # raised. self.account.deposit_funds("fsdfsd") def test_legal_withdrawal(self): # Your code here to test that withdrawing a legal amount subtracts the # funds from the balance. self.account.withdraw_funds(200) self.account.withdraw_funds("300") def test_illegal_withdrawal(self): # Your code here to test that withdrawing an illegal amount (like 'bananas' # or such - something which is NOT a float) raises a suitable exception. self.account.withdraw_funds("sdfsad") def test_insufficient_funds_withdrawal(self): # Your code here to test that you can only withdraw funds which are available. # For example, if you have a balance of 500.00 dollars then that is the maximum # that can be withdrawn. If you tried to withdraw 600.00 then a suitable exception # should be raised and the withdrawal should NOT be applied to the account balance # or the account's transaction list. self.account.withdraw_funds("50000000000") def test_save_to_file(self): # Test the function of saving file self.account.save_to_file()