From fd8b9e337ad2e1c368c8e24e7ef43efb59307732 Mon Sep 17 00:00:00 2001 From: liwenguo123 Date: Mon, 16 May 2016 00:41:11 -0400 Subject: [PATCH] Update customer_tests.py --- tests/customer_tests.py | 94 ++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..ca3cb88 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -1,36 +1,60 @@ -from nose.tools import assert_equals, nottest +from nose.tools import assert_equals, nottest + +from account import Account, CHECKING, SAVINGS +from customer import Customer + +def test_statement(name, accounts, amounts): + customer = Customer(name) + stmt = None; + for i, account in enumerate(accounts): + customer.openAccount(account) + if account.accountType == CHECKING: + atype = "Checking" + elif account.accountType == SAVINGS: + atype = "Saving" + elif account.accountType == MAXI_SAVINGS: + atype = "Maxi Savings" + stmt += "\n\n“ + atype + " Account\n" + for accountAmounts in amounts[i]: + for amount in accountAmounts: + if amount > 0: + account.deposit(amount) + stmt += " deposit " + _toDollars(abs(amount)) + elif amount < 0: + account.withdraw(-amount) + stmt += " withdraw " + _toDollars(abs(amount)) + stmt += "\nTotal" + _toDollars(abs(account.balance)) + stmt += "\n\nTotal In All Accounts " + _toDollars(customer.getTotalBalance()) + + assert_equals(customer.getStatement(), stmt) + +def test_statement_call(): + name = "Henry" + anum = 12345 + accounts = [] + atypes = [CHECKING, SAVINGS, MAXI_SAVINGS] + for atype in atypes): + account = Account(anum, atype) + accounts.append(account) + camount = [100, -50, -30] + samount = [100, -50, 10] + mamount = [1000, 500, -2000] + amounts = [amount, smount, mmount] + test_statement(name, accounts, amounts) + +def test_multipleAccount(customerName, accounts): + customer = Customer(customerName) + for account in accounts: + customer.openAccount(account) + assert_equals(customer.numAccs(), len(accounts)) + +def test_multipleAccount_call(): + name = "John" + anum = 12345 + accounts = [] + atypes = [CHECKING, SAVINGS, MAXI_SAVINGS, 10, None] + for atype in atypes: + account = Account(anum, atype) + accounts.append(account) + test_multipleAccount(name, accounts) -from account import Account, CHECKING, SAVINGS -from customer import Customer - - -def test_statement(): - checkingAccount = Account(CHECKING) - savingsAccount = Account(SAVINGS) - henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount) - checkingAccount.deposit(100.0) - savingsAccount.deposit(4000.0) - savingsAccount.withdraw(200.0) - assert_equals(henry.getStatement(), - "Statement for Henry" + - "\n\nChecking Account\n deposit $100.00\nTotal $100.00" + - "\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" + - "\n\nTotal In All Accounts $3900.00") - - -def test_oneAccount(): - oscar = Customer("Oscar").openAccount(Account(SAVINGS)) - assert_equals(oscar.numAccs(), 1) - - -def test_twoAccounts(): - oscar = Customer("Oscar").openAccount(Account(SAVINGS)) - oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 2) - - -@nottest -def test_threeAccounts(): - oscar = Customer("Oscar").openAccount(Account(SAVINGS)) - oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 3) \ No newline at end of file