class BankAccountTest(unittest.TestCase): def setUp(self): self.account = BankAccount("Rado", 0, "$") def test_can_create_bank_account(self): self.assertTrue(isinstance(self.account, BankAccount)) def test_get_name(self): self.assertEqual(self.account.holder(), "Rado") def test_initial_zero_balance(self): self.assertEqual(self.account.balance(), 0) def test_negative_initial_amount(self): with self.assertRaises(ValueError): BankAccount("Test", -100, "$") def test_deposit_in_empty_account(self): self.account.deposit(500) self.assertEqual(self.account.balance(), 500) def test_deposit_in_not_empty_account(self): account = BankAccount("Ivo", 1000, "$") account.deposit(500) self.assertEqual(account.balance(), 1500) def test_deposit_negative_amount(self): with self.assertRaises(ValueError): self.account.deposit(-100) def test_withdraw_from_not_empty_account(self): self.account.deposit(100) result = self.account.withdraw(50) self.assertTrue(result) self.assertEqual(self.account.balance(), 50) def test_withdraw_from_empty_account(self): result = self.account.withdraw(50) self.assertIsNotNone(result) self.assertFalse(result) def test_history(self): account = BankAccount("Test", 0, "$") account.deposit(20) account.balance() int(account) expected = ["Account was created", "Deposited 20$", "Balance check -> 20$", "__int__ check -> 20$"] self.assertEqual(account.history(), expected) def test_transfer(self): account1 = BankAccount("Rado", 100, "$") account2 = BankAccount("Ivo", 0, "$") result = account1.transfer_to(account2, 50) self.assertTrue(result)
class BankAccountTest(unittest.TestCase): def setUp(self): self.account = BankAccount("Rado", 0, "$") def test_can_create_bank_account(self): self.assertTrue(isinstance(self.account, BankAccount)) def test_get_name(self): self.assertEqual(self.account.holder(), "Rado") def test_initial_zero_balance(self): self.assertEqual(self.account.balance(), 0) def test_negative_initial_amount(self): with self.assertRaises(ValueError): BankAccount("Test", -100, "$") def test_deposit_in_empty_account(self): self.account.deposit(500) self.assertEqual(self.account.balance(), 500) def test_deposit_in_not_empty_account(self): account = BankAccount("Ivo", 1000, "$") account.deposit(500) self.assertEqual(account.balance(), 1500) def test_deposit_negative_amount(self): with self.assertRaises(ValueError): self.account.deposit(-100) def test_withdraw_from_not_empty_account(self): self.account.deposit(100) result = self.account.withdraw(50) self.assertTrue(result) self.assertEqual(self.account.balance(), 50) def test_withdraw_from_empty_account(self): result = self.account.withdraw(50) self.assertIsNotNone(result) self.assertFalse(result) def test_history(self): account = BankAccount("Test", 0, "$") account.deposit(20) account.balance() int(account) expected = ["Account was created", "Deposited 20$", "Balance check -> 20$", "__int__ check -> 20$"] self.assertEqual(account.history(), expected)
def test_get_name_when_name_not_string_but_object(self): name = ("Radoslav", "Georgiev") account = BankAccount(name, 0, "%") self.assertEqual(str(name), account.holder())
def test_get_name(self): name = "Test" account = BankAccount(name, 0, "$") self.assertEqual(account.holder(), name)
def test_holder(self): account = BankAccount("Tester", 0, "$") self.assertEqual(account.holder(), "Tester")