From ea6fffbc6f6d55d013a90b1dacb743a6aa4d357f Mon Sep 17 00:00:00 2001 From: sorkan Date: Wed, 25 May 2016 00:12:48 +0530 Subject: [PATCH 1/6] Add files via upload --- account.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++ customer_tests.py | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 account.py create mode 100644 customer_tests.py diff --git a/account.py b/account.py new file mode 100644 index 0000000..78b1a7a --- /dev/null +++ b/account.py @@ -0,0 +1,61 @@ +from abcbank.transaction import Transaction + +CHECKING = 0 +SAVINGS = 1 +MAXI_SAVINGS = 2 + + +class Account: + def __init__(self, accountType): + self.accountType = accountType + self.transactions = [] + + def deposit(self, amount): + if (amount <= 0): + raise ValueError("amount must be greater than zero") + else: + self.transactions.append(Transaction(amount)) + + def withdraw(self, amount): + if (amount <= 0): + raise ValueError("amount must be greater than zero") + else: + # check for withdrawal over available funds - overdraft + if (self.sumTransactions() < amount): + raise ValueError("amount greater than avail funds") + else: + self.transactions.append(Transaction(-amount)) + + def transferFunds(self, Account_t, amount): + """ + The account you are transferring to is Account_t + (ie: savings, checking,maxi-savings). the self represents + the account you are transferring from. amount is + how much is being transferred + """ + try: + self.withdraw(amount) # call self's withdraw method + Account_t.deposit(amount) # call the destination account deposit + except ValueError as err: + raise ValueError("transfer exception: "+err[0]) + + + def interestEarned(self): + amount = self.sumTransactions() + if self.accountType == SAVINGS: + if (amount <= 1000): + return amount * 0.001 + else: + return 1 + (amount - 1000) * 0.002 + if self.accountType == MAXI_SAVINGS: + if (amount <= 1000): + return amount * 0.02 + elif (amount <= 2000): + return 20 + (amount - 1000) * 0.05 + else: + return 70 + (amount - 2000) * 0.1 + else: + return amount * 0.001 + + def sumTransactions(self, checkAllTransactions=True): + return sum([t.amount for t in self.transactions]) diff --git a/customer_tests.py b/customer_tests.py new file mode 100644 index 0000000..bc3e4ea --- /dev/null +++ b/customer_tests.py @@ -0,0 +1,49 @@ +from nose.tools import assert_equals, nottest + +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_transfer(): + checkingAccount = Account(CHECKING) + savingsAccount = account(SAVINGS) + henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount) + checkingAccount.deposit(100.0) + savingsAccount.deposit(4000.0) + savingsAccount.transferFunds(checkingAccount, 200.0) + assert_equals(henry.getStatement(), + "Statement for Henry" + + "\n\nChecking Account\n deposit $100.00\n deposit $200.00\nTotal $300.00" + + "\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" + + "\n\nTotal In All Accounts $4100.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) From 18ccf461e0beb4b9ab3a16a983be0869ea4ebc6b Mon Sep 17 00:00:00 2001 From: sorkan Date: Wed, 25 May 2016 00:14:37 +0530 Subject: [PATCH 2/6] Add files via upload --- abcbank/account.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index e010009..78b1a7a 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -20,7 +20,25 @@ def withdraw(self, amount): if (amount <= 0): raise ValueError("amount must be greater than zero") else: - self.transactions.append(Transaction(-amount)) + # check for withdrawal over available funds - overdraft + if (self.sumTransactions() < amount): + raise ValueError("amount greater than avail funds") + else: + self.transactions.append(Transaction(-amount)) + + def transferFunds(self, Account_t, amount): + """ + The account you are transferring to is Account_t + (ie: savings, checking,maxi-savings). the self represents + the account you are transferring from. amount is + how much is being transferred + """ + try: + self.withdraw(amount) # call self's withdraw method + Account_t.deposit(amount) # call the destination account deposit + except ValueError as err: + raise ValueError("transfer exception: "+err[0]) + def interestEarned(self): amount = self.sumTransactions() @@ -40,4 +58,4 @@ def interestEarned(self): return amount * 0.001 def sumTransactions(self, checkAllTransactions=True): - return sum([t.amount for t in self.transactions]) \ No newline at end of file + return sum([t.amount for t in self.transactions]) From c95b7a371a24482dfa982bee5d1d9d198ee650ec Mon Sep 17 00:00:00 2001 From: sorkan Date: Wed, 25 May 2016 00:16:15 +0530 Subject: [PATCH 3/6] Add files via upload --- tests/customer_tests.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..bc3e4ea 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -18,6 +18,19 @@ def test_statement(): "\n\nTotal In All Accounts $3900.00") +def test_transfer(): + checkingAccount = Account(CHECKING) + savingsAccount = account(SAVINGS) + henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount) + checkingAccount.deposit(100.0) + savingsAccount.deposit(4000.0) + savingsAccount.transferFunds(checkingAccount, 200.0) + assert_equals(henry.getStatement(), + "Statement for Henry" + + "\n\nChecking Account\n deposit $100.00\n deposit $200.00\nTotal $300.00" + + "\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" + + "\n\nTotal In All Accounts $4100.00") + def test_oneAccount(): oscar = Customer("Oscar").openAccount(Account(SAVINGS)) assert_equals(oscar.numAccs(), 1) @@ -33,4 +46,4 @@ def test_twoAccounts(): def test_threeAccounts(): oscar = Customer("Oscar").openAccount(Account(SAVINGS)) oscar.openAccount(Account(CHECKING)) - assert_equals(oscar.numAccs(), 3) \ No newline at end of file + assert_equals(oscar.numAccs(), 3) From ac3777f6daa62203930e76a32c8c1f7244d2f930 Mon Sep 17 00:00:00 2001 From: sorkan Date: Wed, 25 May 2016 00:17:56 +0530 Subject: [PATCH 4/6] Delete account.py --- account.py | 61 ------------------------------------------------------ 1 file changed, 61 deletions(-) delete mode 100644 account.py diff --git a/account.py b/account.py deleted file mode 100644 index 78b1a7a..0000000 --- a/account.py +++ /dev/null @@ -1,61 +0,0 @@ -from abcbank.transaction import Transaction - -CHECKING = 0 -SAVINGS = 1 -MAXI_SAVINGS = 2 - - -class Account: - def __init__(self, accountType): - self.accountType = accountType - self.transactions = [] - - def deposit(self, amount): - if (amount <= 0): - raise ValueError("amount must be greater than zero") - else: - self.transactions.append(Transaction(amount)) - - def withdraw(self, amount): - if (amount <= 0): - raise ValueError("amount must be greater than zero") - else: - # check for withdrawal over available funds - overdraft - if (self.sumTransactions() < amount): - raise ValueError("amount greater than avail funds") - else: - self.transactions.append(Transaction(-amount)) - - def transferFunds(self, Account_t, amount): - """ - The account you are transferring to is Account_t - (ie: savings, checking,maxi-savings). the self represents - the account you are transferring from. amount is - how much is being transferred - """ - try: - self.withdraw(amount) # call self's withdraw method - Account_t.deposit(amount) # call the destination account deposit - except ValueError as err: - raise ValueError("transfer exception: "+err[0]) - - - def interestEarned(self): - amount = self.sumTransactions() - if self.accountType == SAVINGS: - if (amount <= 1000): - return amount * 0.001 - else: - return 1 + (amount - 1000) * 0.002 - if self.accountType == MAXI_SAVINGS: - if (amount <= 1000): - return amount * 0.02 - elif (amount <= 2000): - return 20 + (amount - 1000) * 0.05 - else: - return 70 + (amount - 2000) * 0.1 - else: - return amount * 0.001 - - def sumTransactions(self, checkAllTransactions=True): - return sum([t.amount for t in self.transactions]) From 3daab1da001c452694bb5e6f68f5399bd7af2edf Mon Sep 17 00:00:00 2001 From: sorkan Date: Wed, 25 May 2016 00:18:13 +0530 Subject: [PATCH 5/6] Delete customer_tests.py --- customer_tests.py | 49 ----------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 customer_tests.py diff --git a/customer_tests.py b/customer_tests.py deleted file mode 100644 index bc3e4ea..0000000 --- a/customer_tests.py +++ /dev/null @@ -1,49 +0,0 @@ -from nose.tools import assert_equals, nottest - -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_transfer(): - checkingAccount = Account(CHECKING) - savingsAccount = account(SAVINGS) - henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount) - checkingAccount.deposit(100.0) - savingsAccount.deposit(4000.0) - savingsAccount.transferFunds(checkingAccount, 200.0) - assert_equals(henry.getStatement(), - "Statement for Henry" + - "\n\nChecking Account\n deposit $100.00\n deposit $200.00\nTotal $300.00" + - "\n\nSavings Account\n deposit $4000.00\n withdrawal $200.00\nTotal $3800.00" + - "\n\nTotal In All Accounts $4100.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) From 47be84481d4247a9fc6b6c421469cb65bbc17688 Mon Sep 17 00:00:00 2001 From: sorkan Date: Wed, 25 May 2016 00:40:13 +0530 Subject: [PATCH 6/6] Add files via upload --- abcbank/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abcbank/account.py b/abcbank/account.py index 78b1a7a..3256b31 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,4 @@ -from abcbank.transaction import Transaction +from transaction import Transaction CHECKING = 0 SAVINGS = 1