Exemplo n.º 1
0
class TestAccount(unittest.TestCase):
    """Test for the class Accountant."""
    def setUp(self):
        self.acc = Accountant()

    def test_initial_balance(self):
        # Default balance should be 0.
        self.assertEqual(self.acc.balance, 0)

        # Test non-default balance.
        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)

    def test_deposit(self):
        # Test single deposit.
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 100)

        # Test multiple deposits.
        self.acc.deposit(100)
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 300)

    def test_withdrawal(self):
        # Test single withdrawal.
        self.acc.deposit(1000)
        self.acc.withdraw(100)
        self.assertEqual(self.acc.balance, 900)
Exemplo n.º 2
0
class TestAccountant(unittest.TestCase):

    # a == b or a !=b
    # assertEqual(a, b) or assertNotEqual(a, b)
    # x is True or x is False
    # assertTrue(x) or assertFalse(x)
    # veryfity an item is in list or not in list
    #assertIn(item, list) or assertNotIn(item, list)

    def setUp(self):
        self.acc = Accountant()

    #default balance shood be 0
    def test_initial_balance(self):
        self.assertEqual(self.acc.balance, 0)
        #non-default balance
        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)

    #test depsit
    def test_deposit(self):
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 100)
        #test multiple deposit
        self.acc.deposit(100)
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 300)

    def test_withdrawal(self):
        self.acc.deposit(1000)
        self.acc.withdraw(100)
        self.assertEqual(
            self.acc.balance,
            900)  #if you change 900 to 800 -> AssertionError: 900 != 800
Exemplo n.º 3
0
class TestAccountant(unittest.TestCase):

    def setUp(self):
        self.acc = Accountant()
    def test_initial_balance(self):
        self.assertEqual(self.acc.balance, 0)

        acc = Accountant(100)
        self.assertEqual(acc.balance, 100)

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

        self.acc.deposit(100)
        self.acc.deposit(100)
        self.assertEqual(self.acc.balance, 300)

    def test_withdrawal(self):
        self.acc.deposit(1000)
        self.acc.withdraw(100)
        self.assertEqual(self.acc.balance, 900)