Exemple #1
0
class AccountBalanceTestCases(unittest.TestCase):
    def setUp(self):
        self.account_yangu = BankAccount()

    def test_balance(self):
        self.assertEqual(self.account_yangu.balance,
                         3000,
                         msg='Account balance Invalid')

    def test_deposit(self):
        self.account_yangu.deposit(4000)
        self.assertEqual(self.account_yangu.balance,
                         7000,
                         msg='deposit has jam')

    def test_withdraw(self):
        self.account_yangu.withdraw(500)
        self.assertEqual(self.account_yangu.balance,
                         2500,
                         msg='withdraw has jam')

    def test_invalid_trans(self):
        self.assertEqual(self.account_yangu.withdraw(6000),
                         "invalid transaction",
                         msg='invalid transaction')
Exemple #2
0
    def test_withdraw(self):
        bank = BankAccount()
        bank.deposit(30)
        bank.withdraw(20)
        self.assertEqual(10, bank.balance())

        with self.assertRaises(InsufficientFunds):
            bank.withdraw(50)
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)
Exemple #5
0
class AccountBalanaceTestCase(unittest.TestCase):
    def setUp(self):
        self.user_account = BankAccount()

    def test_balance(self):
        self.assertEqual(self.user_account.balance, 3000, msg='Account Balance Invalid.')

    def test_deposit(self):
        self.user_account.deposit(4000)
        self.assertEqual(self.user_account.balance, 7000, msg='Deposit Method Inaccurate.')

    def test_withdraw(self):
        self.user_account.withdraw(500)
        self.assertEqual(self.user_account.balance, 2500, msg='Withdraw method Inaccurate.')

    def test_invalid_transaction(self):
        self.assertEqual(self.user_account.withdraw(6000), "Invalid Transaction", msg='Invalid Transaction.')
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.currency = "BGN"
        self.account = BankAccount("Rado", 0, self.currency)

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_initial_zero_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_initial_non_zero_balance(self):
        initial_balance = 100
        account = BankAccount("Test", initial_balance, "$")

        self.assertEqual(account.balance(), initial_balance)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Test", -100, "$")

    def test_get_name(self):
        name = "Test"
        account = BankAccount(name, 0, "$")

        self.assertEqual(account.holder(), name)

    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_currency(self):
        self.assertEqual(self.account.currency(), self.currency)

    def test_currency_always_string(self):
        currency = 1

        account = BankAccount("Test", 0, currency)

        self.assertEqual(str(currency), account.currency())

    def test_deposit_in_empty_account(self):
        self.account.deposit(100)

        self.assertEqual(100, self.account.balance())

    def test_deposit_in_not_empty_account(self):
        account = BankAccount("Test", 50, "$")
        account.deposit(50)

        self.assertEqual(account.balance(), 100)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_from_non_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_when_account_is_created(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created"]

        self.assertEqual(account.history(), expected)

    def test_history_with_balance_check(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created", "Balance check -> 0$"]

        self.assertEqual(account.history(), expected)
Exemple #7
0
from bank import BankAccount  # If File name: bank.py and in the same folder

b1 = BankAccount("56789", "Tony", 500.0)
b2 = BankAccount("12345", "Jerry", 190.0)

b1.withdraw(100.0)
b2.deposit(50.0)

print(b1 < b2)
print(b1 > b2)
 def test_history_for_successful_withdraw(self):
     account = BankAccount("Tester", 100, "$")
     account.withdraw(50)
     self.assertEqual(account.history(), ["Account was created", "50$ was withdrawed"])
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_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Tester", -100, "$")

    def test_int_dunder(sefl):
        sefl.assertEqual(int(sefl.account), 0)

    def test_str_dunder(sefl):
        sefl.assertEqual(str(sefl.account), "Bank account for Rado with balance of 0$")

    def test_holder(self):
        account = BankAccount("Tester", 0, "$")
        self.assertEqual(account.holder(), "Tester")

    def test_currency(self):
        self.assertEqual(self.account.currency(), "$")

    def test_deposit(self):
        self.account.deposit(100)
        self.assertEqual(self.account.balance(), 100)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_less_than_you_have(self):
        account = BankAccount("Tester", 100, "$")
        result = account.withdraw(20)

        self.assertTrue(result)
        self.assertEqual(account.balance(), 80)

    def test_withdraw_more_than_you_have(self):
        result = self.account.withdraw(50)
        self.assertIsNotNone(result)
        self.assertFalse(result)

    def test_transfer_to(self):
        account = BankAccount("Tester", 100, "$")
        result = account.transfer_to(self.account, 70)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 70)
        self.assertEqual(account.balance(), 30)

    def test_history_when_account_is_created(self):
        self.assertEqual(self.account.history(), ["Account was created"])

    def test_history_for_int(self):
        int(self.account)
        self.assertEqual(self.account.history(), ["Account was created", "__int__ check -> 0$"])

    def test_history_with_balance_check(self):
        self.account.balance()
        self.assertEqual(self.account.history(), ["Account was created", "Balance check -> 0$"])

    def test_history_for_deposit(self):
        self.account.deposit(1000)
        self.assertEqual(self.account.history(), ["Account was created", "Deposited 1000$"])

    def test_history_for_successful_withdraw(self):
        account = BankAccount("Tester", 100, "$")
        account.withdraw(50)
        self.assertEqual(account.history(), ["Account was created", "50$ was withdrawed"])

    def test_history_for_unsuccessful_withdraw(self):
        self.account.withdraw(50)
        self.assertEqual(self.account.history(), ["Account was created", "Withdraw for 50$ failed."])

    def test_history_for_transfer_to(self):
        account = BankAccount("Tester", 100, "$")
        result = account.transfer_to(self.account, 50)

        self.assertEqual(self.account.history(), ["Account was created", "Transfer from Tester for 50$"])
        self.assertEqual(account.history(), ["Account was created", "Transfer to Rado for 50$"])
    def test_withdraw_less_than_you_have(self):
        account = BankAccount("Tester", 100, "$")
        result = account.withdraw(20)

        self.assertTrue(result)
        self.assertEqual(account.balance(), 80)
Exemple #11
0
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.currency = "BGN"
        self.account = BankAccount("Rado", 0, self.currency)

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_initial_zero_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_initial_non_zero_balance(self):
        initial_balance = 100
        account = BankAccount("Test", initial_balance, "$")

        self.assertEqual(account.balance(), initial_balance)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Test", -100, "$")

    def test_get_name(self):
        name = "Test"
        account = BankAccount(name, 0, "$")

        self.assertEqual(account.holder(), name)

    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_currency(self):
        self.assertEqual(self.account.currency(), self.currency)

    def test_currency_always_string(self):
        currency = 1

        account = BankAccount("Test", 0, currency)

        self.assertEqual(str(currency), account.currency())

    def test_deposit_in_empty_account(self):
        self.account.deposit(100)

        self.assertEqual(100, self.account.balance())

    def test_deposit_in_not_empty_account(self):
        account = BankAccount("Test", 50, "$")
        account.deposit(50)

        self.assertEqual(account.balance(), 100)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_from_non_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_when_account_is_created(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created"]

        self.assertEqual(account.history(), expected)

    def test_history_with_balance_check(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created", "Balance check -> 0$"]

        self.assertEqual(account.history(), expected)