def test_over_withdrawal(
):  #this test function should throw an Exception or Error
    user = BankUser("Joe")
    user.addAccount(AccountType.SAVINGS)
    user.deposit(AccountType.SAVINGS, 10)

    ## test create multiple saving account
    try:
        user.addAccount(AccountType.SAVINGS)
    except Exception as e:
        print(e)

    ## test withdraw more than balance
    try:
        user.withdraw(AccountType.SAVINGS, 1000)
    except Exception as e:
        print(e)

    ## test withdraw wrong account
    try:
        user.withdraw(AccountType.CHECKING, 8)
    except Exception as e:
        print(e)

    ## test withdraw negative amount
    try:
        user.withdraw(AccountType.SAVINGS, -10)
    except Exception as e:
        print(e)

    ## test deposit negative amount
    try:
        user.deposit(AccountType.SAVINGS, -10)
    except Exception as e:
        print(e)

    ## test deposit to wrong account
    try:
        user.deposit(AccountType.CHECKING, 100)
    except Exception as e:
        print(e)

    ## test get balance from wrong account
    try:
        user.getBalance(AccountType.CHECKING)
    except Exception as e:
        print(e)

    ### test valid functions ###
    user.deposit(AccountType.SAVINGS, 100)
    user.withdraw(AccountType.SAVINGS, 10)
    print(user.getBalance(AccountType.SAVINGS))
    user.addAccount(AccountType.CHECKING)
    user.deposit(AccountType.CHECKING, 500)
    print(user.getBalance(AccountType.CHECKING))

    print(user)
    print(str(user))
    print(str(user.accounts[AccountType.SAVINGS.name]))
    print(str(user.accounts[AccountType.CHECKING.name]))
Ejemplo n.º 2
0
def test_over_withdrawal():
    user = BankUser("XinZeng")
    user.addAccount(AccountType.SAVINGS)
    user.deposit(AccountType.SAVINGS, 100)

    # test for invalid situation
    # deposit a negative value
    try:
        user.deposit(AccountType.SAVINGS, -1)
    except Exception as e:
        print(e)

    # withdraw more than balance
    try:
        user.withdraw(AccountType.SAVINGS, 200)
    except Exception as e:
        print(e)

    # withdraw a negative value
    try:
        user.withdraw(AccountType.SAVINGS, -1)
    except Exception as e:
        print(e)

    # open multiple saving account
    try:
        user.addAccount(AccountType.SAVINGS)
    except Exception as e:
        print(e)

    # withdraw from a different account
    try:
        user.withdraw(AccountType.CHECKING, 20)
    except Exception as e:
        print(e)

    # deposit to a different account
    try:
        user.deposit(AccountType.CHECKING, 1)
    except Exception as e:
        print(e)

    # get balance from wrong account
    try:
        user.getBalance(AccountType.CHECKING)
    except Exception as e:
        print(e)

    # test for valid situation
    user.withdraw(AccountType.SAVINGS, 50)
    print("Balance:", user.getBalance(AccountType.SAVINGS))
    print(user)
    print(str(user))
    print(str(user.account[AccountType.SAVINGS]))
    user.addAccount(AccountType.CHECKING)
    print("Balance:", user.getBalance(AccountType.CHECKING))
    print(user)
    print(str(user.account[AccountType.CHECKING]))
Ejemplo n.º 3
0
def test_get_balance(): #this tests if the user is trying to get a balance for a nonexistent account
    newUser = BankUser("Nishu")
    newUser.addAccount(AccountType.CHECKING)
    newUser.deposit(AccountType.CHECKING, 1000)

    try:
        newUser.getBalance(AccountType.SAVINGS)
    except Exception as excep:
        print(excep)
Ejemplo n.º 4
0
def test_over_getBalance_():  #this test function should work
    user = BankUser("Javi")
    user.addAccount(AccountType.CHECKING)
    user.deposit(AccountType.CHECKING, 20)
    user.addAccount(AccountType.SAVINGS)
    user.deposit(AccountType.SAVINGS, 1)
    try:
        print(user.getBalance(AccountType.CHECKING))
        print(user.getBalance(AccountType.SAVINGS))
    except Exception as e:
        print(e)  #print the message for the Exeption
def test_over_withdrawal(): #this test function should throw an Exception or Error 
    user = BankUser("Joe");
    user.addAccount(AccountType.SAVINGS);
    user.deposit(AccountType.SAVINGS, 10);
    user.withdraw(AccountType.SAVINGS, 1);
    print(user.getBalance(AccountType.SAVINGS));
    print(user);

    
    #CHECK WITHDRAWAL LARGER THAN BALANCE
    try:
        user.withdraw(AccountType.SAVINGS, 1000); #this will cause an Exception or Error
    except Exception as e:
        print(e); #print the message for the Exeption

    #CHECK NEGATIVE WITHDRAWAL 
    try:
        user.withdraw(AccountType.SAVINGS, -10); #this will cause an Exception or Error
    except Exception as e:
        print(e); #print the message for the Exeption

    #CHECK NEGATIVE DEPOSIT 
    try:
        user.deposit(AccountType.SAVINGS, -10); #this will cause an Exception or Error
    except Exception as e:
        print(e); #print the message for the Exeption

    #CHECK ACCOUNT TYPE WORKS FOR GETBALACE
    try:
        user.getBalance(AccountType.CHECKING); #this will cause an Exception or Error
    except Exception as e:
        print(e); #print the message for the Exeption

    #CHECK ACCOUNT TYPE WORKS FOR DEPOSIT
    try:
        user.deposit(AccountType.CHECKING,1); #this will cause an Exception or Error
    except Exception as e:
        print(e); #print the message for the Exeption

    #CHECK ACCOUNT TYPE WORKS FOR WITHDRAWAL
    try:
        user.withdraw(AccountType.CHECKING,1); #this will cause an Exception or Error
    except Exception as e:
        print(e); #print the message for the Exeption
Ejemplo n.º 6
0
def test_deposit_noAccount():
    user = BankUser("Joe")
    try:
        user.getBalance(AccountType.SAVINGS)
    except Exception as e:
        print(e)
Ejemplo n.º 7
0
def test_getBalance_noAccount():
    user = BankUser("Joe")
    try:
        user.getBalance(AccountType.CHECKING)
    except Exception as e:
        print(e)