From a4e11f95ed4b462d4b6e38260b37cf6a903ff797 Mon Sep 17 00:00:00 2001 From: Rohit_Sonawane Date: Tue, 22 May 2018 23:08:34 -0400 Subject: [PATCH 1/5] adding test cases for transfer function --- tests/customer_tests.py | 45 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..fc61d4d 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -1,5 +1,5 @@ -from nose.tools import assert_equals, nottest - +from nose.tools import assert_equals, nottest, raises +from bank import Bank from account import Account, CHECKING, SAVINGS from customer import Customer @@ -33,4 +33,43 @@ 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) + +bank = Bank() +checkingAccount = Account(CHECKING) +savingAccount = Account(SAVINGS) +bill = Customer("Bill") +bill.openAccount(checkingAccount) +bill.openAccount(savingAccount) +bank.addCustomer(bill) +checkingAccount.deposit(100.0) +checkingAccount.deposit(500.0) +checkingAccount.deposit(2000.0) +savingAccount.deposit(900.0) + +from_acc = checkingAccount +to_acc = savingAccount + +def test_transfer_success(): + transfer_amount = 100 + result = bill.transfer(from_acc, to_acc, transfer_amount) + assert_equals(result, True) + assert_equals(checkingAccount.sumTransactions(), 2500.0) + assert_equals(savingAccount.sumTransactions(), 1000.0) + +@raises(ValueError) +def test_transfer_insufficient_balance_failure(): + transfer_amount = 5000 + result = bill.transfer(from_acc, to_acc, transfer_amount) + +@raises(ValueError) +def test_transfer_insufficient_balance_failure(): + checkingAccount_oscar = Account(CHECKING) + oscar = Customer("Oscar").openAccount(checkingAccount_oscar) + bank.addCustomer(oscar) + checkingAccount_oscar.deposit(100.0) + transfer_amount = 5000 + from_acc = checkingAccount_oscar + to_acc = savingAccount + result = bill.transfer(from_acc, to_acc, transfer_amount) + From 912f40432016613f81960b9e0066c07d3f054539 Mon Sep 17 00:00:00 2001 From: Rohit_Sonawane Date: Tue, 22 May 2018 23:08:57 -0400 Subject: [PATCH 2/5] adding transfer function --- abcbank/customer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/abcbank/customer.py b/abcbank/customer.py index 7cfd62a..e56be31 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -50,6 +50,22 @@ def withdrawalOrDepositText(self, transaction): else: return "N/A" + def transfer(self, from_acc, to_acc, transfer_amount): + result = False + try: + if len(self.accounts) > 1: + if from_acc.sumTransactions() >= transfer_amount: + from_acc.withdraw(transfer_amount) + to_acc.deposit(transfer_amount) + result = True + else: + raise ValueError("Amount in the from account is not sufficient") + else: + raise ValueError("More than one account needed for transfer") + except Exception as error: + print "ERROR : " + str(error) + return result + def _toDollars(number): return "${:1.2f}".format(number) From 5ed7f796960ad1d1c8c72f8ed30869958fe0e4d2 Mon Sep 17 00:00:00 2001 From: Rohit_Sonawane Date: Tue, 22 May 2018 23:09:51 -0400 Subject: [PATCH 3/5] refractoring code --- abcbank/bank.py | 1 - 1 file changed, 1 deletion(-) diff --git a/abcbank/bank.py b/abcbank/bank.py index 44711fe..ec7185a 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -18,7 +18,6 @@ def totalInterestPaid(self): return total def getFirstCustomer(self): try: - self.customers = None return self.customers[0].name except Exception as e: print(e) From 8a7ffacdf3f901e2bb6e61748a5be3e7cdb24fb2 Mon Sep 17 00:00:00 2001 From: Rohit_Sonawane Date: Tue, 22 May 2018 23:10:22 -0400 Subject: [PATCH 4/5] adding functionality for max saving account interest change --- abcbank/account.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index e010009..5fcff40 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,5 @@ -from abcbank.transaction import Transaction +from transaction import Transaction +from date_provider import DateProvider CHECKING = 0 SAVINGS = 1 @@ -20,24 +21,31 @@ def withdraw(self, amount): if (amount <= 0): raise ValueError("amount must be greater than zero") else: - self.transactions.append(Transaction(-amount)) + if self.sumTransactions() >= amount: + self.transactions.append(Transaction(-amount)) + else: + raise ValueError("Not sufficient amount in the account to withdraw") def interestEarned(self): - amount = self.sumTransactions() + days_in_year = 365 + actual_amount = self.sumTransactions() + amount = actual_amount if self.accountType == SAVINGS: - if (amount <= 1000): - return amount * 0.001 - else: - return 1 + (amount - 1000) * 0.002 + for day in range((self.transactions[-1].transactionDate - self.transactions[0].transactionDate).days): + if amount <= 1000: + amount += amount * 0.001/days_in_year + else: + amount += 1 + (amount - 1000) * 0.002/days_in_year 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 + for each_transaction in self.transactions: + if (DateProvider.now() - each_transaction.transactionDate).days <= 10: + amount += amount * 0.001/days_in_year + else: + amount += amount * 0.05/days_in_year else: - return amount * 0.001 + for day in range((self.transactions[-1].transactionDate - self.transactions[0].transactionDate).days): + amount += amount * 0.001/days_in_year + return amount - actual_amount 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 ce00a8be2ee2055f62844dd2a54679e408ce3d39 Mon Sep 17 00:00:00 2001 From: Rohit_Sonawane Date: Tue, 22 May 2018 23:10:43 -0400 Subject: [PATCH 5/5] refactoring code --- tests/bank_tests.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/bank_tests.py b/tests/bank_tests.py index 6de98db..4b51a14 100644 --- a/tests/bank_tests.py +++ b/tests/bank_tests.py @@ -1,10 +1,8 @@ from nose.tools import assert_equals - from account import Account, CHECKING, MAXI_SAVINGS, SAVINGS from bank import Bank from customer import Customer - def test_customer_summary(): bank = Bank() john = Customer("John").openAccount(Account(CHECKING))