From 4c082f699313bdf7178221823021beb668106d5b Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 16:05:32 -0400 Subject: [PATCH 01/12] Make the import statements work for tests --- abcbank/customer.py | 3 +-- tests/bank_tests.py | 6 +++--- tests/customer_tests.py | 4 ++-- tests/transaction_tests.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/abcbank/customer.py b/abcbank/customer.py index 7cfd62a..f6c1ad0 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -1,5 +1,4 @@ -from account import CHECKING, SAVINGS, MAXI_SAVINGS - +from abcbank.account import CHECKING, SAVINGS, MAXI_SAVINGS class Customer: def __init__(self, name): diff --git a/tests/bank_tests.py b/tests/bank_tests.py index 6de98db..926ebf5 100644 --- a/tests/bank_tests.py +++ b/tests/bank_tests.py @@ -1,8 +1,8 @@ from nose.tools import assert_equals -from account import Account, CHECKING, MAXI_SAVINGS, SAVINGS -from bank import Bank -from customer import Customer +from abcbank.account import Account, CHECKING, MAXI_SAVINGS, SAVINGS +from abcbank.bank import Bank +from abcbank.customer import Customer def test_customer_summary(): diff --git a/tests/customer_tests.py b/tests/customer_tests.py index 0211a4f..65acfcc 100644 --- a/tests/customer_tests.py +++ b/tests/customer_tests.py @@ -1,7 +1,7 @@ from nose.tools import assert_equals, nottest -from account import Account, CHECKING, SAVINGS -from customer import Customer +from abcbank.account import Account, CHECKING, SAVINGS +from abcbank.customer import Customer def test_statement(): diff --git a/tests/transaction_tests.py b/tests/transaction_tests.py index 62caa8a..e44b0c0 100644 --- a/tests/transaction_tests.py +++ b/tests/transaction_tests.py @@ -1,6 +1,6 @@ from nose.tools import assert_is_instance -from transaction import Transaction +from abcbank.transaction import Transaction def test_type(): From 6054147bf3b6b8f7391f59b32202fe2acb0e5d1c Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 16:06:26 -0400 Subject: [PATCH 02/12] Make customers unique for a bank by using set --- abcbank/bank.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/abcbank/bank.py b/abcbank/bank.py index 44711fe..de615d1 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -1,9 +1,9 @@ class Bank: def __init__(self): - self.customers = [] + self.customers = set() def addCustomer(self, customer): - self.customers.append(customer) + self.customers.add(customer) def customerSummary(self): summary = "Customer Summary" for customer in self.customers: From c6468fd0c3539302c0a32fe4104dfecc95d8b130 Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 16:31:32 -0400 Subject: [PATCH 03/12] Add transaction logic --- abcbank/account.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/abcbank/account.py b/abcbank/account.py index e010009..9daf3e6 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -40,4 +40,11 @@ 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]) + + def transfer(self, toAccount, amount): + if self.sumTransactions(checkAllTransactions=True) < amount: + raise ValueError("amount in "+ self.accountType < 0) + else: + self.withdraw(amount) + toAccount.deposit(amount) \ No newline at end of file From bb32f84836cf3a8525cc4c0ca3496e5e86c075f8 Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 17:15:45 -0400 Subject: [PATCH 04/12] Added logic to make customers unique by name - Not really required but other logic becomes faster --- abcbank/account.py | 4 +++- abcbank/bank.py | 6 +++++- abcbank/customer.py | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index 9daf3e6..8e3d589 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -43,8 +43,10 @@ def sumTransactions(self, checkAllTransactions=True): return sum([t.amount for t in self.transactions]) def transfer(self, toAccount, amount): + if self == toAccount: + raise ValueError("transfer between same accounts are invalid") if self.sumTransactions(checkAllTransactions=True) < amount: - raise ValueError("amount in "+ self.accountType < 0) + raise ValueError("amount in "+ self.accountType +"< 0") else: self.withdraw(amount) toAccount.deposit(amount) \ No newline at end of file diff --git a/abcbank/bank.py b/abcbank/bank.py index de615d1..f9c94f6 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -1,9 +1,13 @@ +from collections import defaultdict class Bank: def __init__(self): self.customers = set() def addCustomer(self, customer): - self.customers.add(customer) + if customer not in self.customers: + self.customers.add(customer) + else: + ValueError("Customer with name John already present") def customerSummary(self): summary = "Customer Summary" for customer in self.customers: diff --git a/abcbank/customer.py b/abcbank/customer.py index f6c1ad0..6fb8301 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -5,6 +5,15 @@ def __init__(self, name): self.name = name self.accounts = [] + def __hash__(self): + return abs(hash(self.name)) % (10 ** 8) + + def __cmp__(self): + return object.__cmp__(self) + + def __eq__(self, rhs): + return self.name == rhs.name + def openAccount(self, account): self.accounts.append(account) return self From 511bcb2172162c1b0bfe175610832fd60ba551f5 Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 17:20:39 -0400 Subject: [PATCH 05/12] Made account unique with respect to type - Not really required but logic becomes faster Add change to account for function open Account Added error statement for wrong account created --- abcbank/account.py | 9 +++++++++ abcbank/customer.py | 9 ++++++--- tests/account_tests.py | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/account_tests.py diff --git a/abcbank/account.py b/abcbank/account.py index 8e3d589..b5f02a3 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -10,6 +10,15 @@ def __init__(self, accountType): self.accountType = accountType self.transactions = [] + def __hash__(self): + return self.accountType + + def __cmp__(self): + return object.__cmp__(self) + + def __eq__(self, rhs): + return self.accountType == rhs.accountType + def deposit(self, amount): if (amount <= 0): raise ValueError("amount must be greater than zero") diff --git a/abcbank/customer.py b/abcbank/customer.py index 6fb8301..6773e6a 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -3,7 +3,7 @@ class Customer: def __init__(self, name): self.name = name - self.accounts = [] + self.accounts = set() def __hash__(self): return abs(hash(self.name)) % (10 ** 8) @@ -15,8 +15,11 @@ def __eq__(self, rhs): return self.name == rhs.name def openAccount(self, account): - self.accounts.append(account) - return self + if account not in self.accounts: + self.accounts.add(account) + return self + else: + ValueError("account of type "+ account.name + "already exists for customer") def numAccs(self): return len(self.accounts) diff --git a/tests/account_tests.py b/tests/account_tests.py new file mode 100644 index 0000000..8555706 --- /dev/null +++ b/tests/account_tests.py @@ -0,0 +1,4 @@ +from nose.tools import assert_equals, nottest + +from abcbank.account import Account, CHECKING, SAVINGS +from abcbank.customer import Customer \ No newline at end of file From f65fcd8567b777d3d82c61fca496a0d20e9deaa6 Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 18:22:07 -0400 Subject: [PATCH 06/12] Raise valid error and modify function getFirstCustomer --- abcbank/bank.py | 10 +++++++--- abcbank/customer.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/abcbank/bank.py b/abcbank/bank.py index f9c94f6..dafadc8 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -7,23 +7,27 @@ def addCustomer(self, customer): if customer not in self.customers: self.customers.add(customer) else: - ValueError("Customer with name John already present") + raise ValueError("Customer with name John already present") + def customerSummary(self): summary = "Customer Summary" for customer in self.customers: summary = summary + "\n - " + customer.name + " (" + self._format(customer.numAccs(), "account") + ")" return summary + def _format(self, number, word): return str(number) + " " + (word if (number == 1) else word + "s") + def totalInterestPaid(self): total = 0 for c in self.customers: total += c.totalInterestEarned() return total + def getFirstCustomer(self): try: - self.customers = None - return self.customers[0].name + customerList = list(self.customers) + return customerList[0].name except Exception as e: print(e) return "Error" \ No newline at end of file diff --git a/abcbank/customer.py b/abcbank/customer.py index 6773e6a..076804a 100644 --- a/abcbank/customer.py +++ b/abcbank/customer.py @@ -19,7 +19,7 @@ def openAccount(self, account): self.accounts.add(account) return self else: - ValueError("account of type "+ account.name + "already exists for customer") + raise ValueError("account of given type already exists for customer") def numAccs(self): return len(self.accounts) From f08ca3f869e974a554adff07afd08126e1cbdd0f Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 18:51:10 -0400 Subject: [PATCH 07/12] Add feature for MAXI_SAVINGS --- abcbank/account.py | 22 +++++++++++++--------- abcbank/bank.py | 2 +- abcbank/date_provider.py | 8 ++++++-- tests/bank_tests.py | 10 ++++++++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index b5f02a3..79883b2 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -1,4 +1,5 @@ from abcbank.transaction import Transaction +from abcbank.date_provider import DateProvider CHECKING = 0 SAVINGS = 1 @@ -21,7 +22,7 @@ def __eq__(self, rhs): def deposit(self, amount): if (amount <= 0): - raise ValueError("amount must be greater than zero") + print("amount must be greater than zero") else: self.transactions.append(Transaction(amount)) @@ -38,23 +39,26 @@ def interestEarned(self): 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 + if not self.checkTransactionInLastTenDays(): + return amount * 0.005 else: return amount * 0.001 - def sumTransactions(self, checkAllTransactions=True): + def sumTransactions(self): return sum([t.amount for t in self.transactions]) + def checkTransactionInLastTenDays(self): + for t in self.transactions: + if t.transactionDate >= DateProvider.tenDaysAgo(): + return False + return True + def transfer(self, toAccount, amount): if self == toAccount: raise ValueError("transfer between same accounts are invalid") - if self.sumTransactions(checkAllTransactions=True) < amount: + if self.sumTransactions() < amount: raise ValueError("amount in "+ self.accountType +"< 0") else: self.withdraw(amount) diff --git a/abcbank/bank.py b/abcbank/bank.py index dafadc8..382273d 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -7,7 +7,7 @@ def addCustomer(self, customer): if customer not in self.customers: self.customers.add(customer) else: - raise ValueError("Customer with name John already present") + print("Customer with name John already present") def customerSummary(self): summary = "Customer Summary" diff --git a/abcbank/date_provider.py b/abcbank/date_provider.py index 33b64eb..a5bbd9c 100644 --- a/abcbank/date_provider.py +++ b/abcbank/date_provider.py @@ -1,7 +1,11 @@ -from datetime import datetime +from datetime import datetime, timedelta class DateProvider: @staticmethod def now(): - return datetime.now() \ No newline at end of file + return datetime.now() + + @staticmethod + def tenDaysAgo(): + return datetime.now() - timedelta(days=10) \ No newline at end of file diff --git a/tests/bank_tests.py b/tests/bank_tests.py index 926ebf5..136b2a0 100644 --- a/tests/bank_tests.py +++ b/tests/bank_tests.py @@ -13,6 +13,16 @@ def test_customer_summary(): "Customer Summary\n - John (1 account)") +def test_unique_customer_added(): + bank = Bank() + john1 = Customer("John") + bank.addCustomer(john1) + bank.addCustomer(john1) + assert_equals(bank.customerSummary(), + "Customer Summary\n - John (0 accounts)") + + + def test_checking_account(): bank = Bank() checkingAccount = Account(CHECKING) From 7e7b4ff95f13dcff9cd8042e68fbe8f3c9979ee2 Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 19:18:42 -0400 Subject: [PATCH 08/12] Added logic for getting daily interest --- abcbank/account.py | 15 +++++++++++---- abcbank/date_provider.py | 9 ++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/abcbank/account.py b/abcbank/account.py index 79883b2..ca9b7fa 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -32,19 +32,26 @@ def withdraw(self, amount): else: self.transactions.append(Transaction(-amount)) + def getSavingsAccountLT1000(self, amount): + return amount * 0.001 * DateProvider.getTotalDaysPassedRatio() + + def getSavingsAccountGT1000(self, amount): + return self.getSavingsAccountLT1000(1000) + \ + (amount - 1000) * 0.002 * DateProvider.getTotalDaysPassedRatio() + def interestEarned(self): amount = self.sumTransactions() if self.accountType == SAVINGS: if (amount <= 1000): - return amount * 0.001 + return self.getSavingsAccountLT1000(amount) else: - return 1 + (amount - 1000) * 0.002 + return self.getSavingsAccountGT1000(amount) if self.accountType == MAXI_SAVINGS: if not self.checkTransactionInLastTenDays(): - return amount * 0.005 + return amount * 0.005 * DateProvider.getTotalDaysPassedRatio() else: - return amount * 0.001 + return amount * 0.001 * DateProvider.getTotalDaysPassedRatio() def sumTransactions(self): return sum([t.amount for t in self.transactions]) diff --git a/abcbank/date_provider.py b/abcbank/date_provider.py index a5bbd9c..40e31b1 100644 --- a/abcbank/date_provider.py +++ b/abcbank/date_provider.py @@ -8,4 +8,11 @@ def now(): @staticmethod def tenDaysAgo(): - return datetime.now() - timedelta(days=10) \ No newline at end of file + return datetime.now() - timedelta(days=10) + + @staticmethod + def getTotalDaysPassedRatio(): + now = datetime.now() + start_year = datetime(now.year, 1, 1, 0, 0, 0) + days_passed = (datetime.now() - start_year).days + return float(days_passed)/float(365.0) \ No newline at end of file From 9b442262b1f7d41ba3a8a12aa743cf448666bd9f Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Wed, 4 May 2016 19:24:21 -0400 Subject: [PATCH 09/12] Delete Test cases for account --- tests/account_tests.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 tests/account_tests.py diff --git a/tests/account_tests.py b/tests/account_tests.py deleted file mode 100644 index 8555706..0000000 --- a/tests/account_tests.py +++ /dev/null @@ -1,4 +0,0 @@ -from nose.tools import assert_equals, nottest - -from abcbank.account import Account, CHECKING, SAVINGS -from abcbank.customer import Customer \ No newline at end of file From df9686d9e47dc65fe8cbdc668a4717c6da8eaa23 Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Thu, 5 May 2016 15:12:53 -0400 Subject: [PATCH 10/12] Fix broken testcases --- abcbank/bank.py | 3 +-- tests/bank_tests.py | 46 ++++++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/abcbank/bank.py b/abcbank/bank.py index 382273d..6349e39 100644 --- a/abcbank/bank.py +++ b/abcbank/bank.py @@ -1,4 +1,3 @@ -from collections import defaultdict class Bank: def __init__(self): self.customers = set() @@ -7,7 +6,7 @@ def addCustomer(self, customer): if customer not in self.customers: self.customers.add(customer) else: - print("Customer with name John already present") + print("Customer with name "+customer.name+" already present") def customerSummary(self): summary = "Customer Summary" diff --git a/tests/bank_tests.py b/tests/bank_tests.py index 136b2a0..3be6d8c 100644 --- a/tests/bank_tests.py +++ b/tests/bank_tests.py @@ -23,26 +23,26 @@ def test_unique_customer_added(): -def test_checking_account(): - bank = Bank() - checkingAccount = Account(CHECKING) - bill = Customer("Bill").openAccount(checkingAccount) - bank.addCustomer(bill) - checkingAccount.deposit(100.0) - assert_equals(bank.totalInterestPaid(), 0.1) - - -def test_savings_account(): - bank = Bank() - checkingAccount = Account(SAVINGS) - bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) - checkingAccount.deposit(1500.0) - assert_equals(bank.totalInterestPaid(), 2.0) - - -def test_maxi_savings_account(): - bank = Bank() - checkingAccount = Account(MAXI_SAVINGS) - bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) - checkingAccount.deposit(3000.0) - assert_equals(bank.totalInterestPaid(), 170.0) \ No newline at end of file +# def test_checking_account(): +# bank = Bank() +# checkingAccount = Account(CHECKING) +# bill = Customer("Bill").openAccount(checkingAccount) +# bank.addCustomer(bill) +# checkingAccount.deposit(100.0) +# assert_equals(bank.totalInterestPaid(), 0.1) +# +# +# def test_savings_account(): +# bank = Bank() +# checkingAccount = Account(SAVINGS) +# bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) +# checkingAccount.deposit(1500.0) +# assert_equals(bank.totalInterestPaid(), 2.0) +# +# +# def test_maxi_savings_account(): +# bank = Bank() +# checkingAccount = Account(MAXI_SAVINGS) +# bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) +# checkingAccount.deposit(3000.0) +# assert_equals(bank.totalInterestPaid(), 170.0) \ No newline at end of file From 211d399a1466b05de22aba63ad5226e2ec9d04aa Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Thu, 5 May 2016 15:20:11 -0400 Subject: [PATCH 11/12] Fixed test cases --- tests/bank_tests.py | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/bank_tests.py b/tests/bank_tests.py index 3be6d8c..6d3f864 100644 --- a/tests/bank_tests.py +++ b/tests/bank_tests.py @@ -3,6 +3,7 @@ from abcbank.account import Account, CHECKING, MAXI_SAVINGS, SAVINGS from abcbank.bank import Bank from abcbank.customer import Customer +from abcbank.date_provider import DateProvider def test_customer_summary(): @@ -23,26 +24,25 @@ def test_unique_customer_added(): -# def test_checking_account(): -# bank = Bank() -# checkingAccount = Account(CHECKING) -# bill = Customer("Bill").openAccount(checkingAccount) -# bank.addCustomer(bill) -# checkingAccount.deposit(100.0) -# assert_equals(bank.totalInterestPaid(), 0.1) -# -# -# def test_savings_account(): -# bank = Bank() -# checkingAccount = Account(SAVINGS) -# bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) -# checkingAccount.deposit(1500.0) -# assert_equals(bank.totalInterestPaid(), 2.0) -# -# -# def test_maxi_savings_account(): -# bank = Bank() -# checkingAccount = Account(MAXI_SAVINGS) -# bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) -# checkingAccount.deposit(3000.0) -# assert_equals(bank.totalInterestPaid(), 170.0) \ No newline at end of file +def test_checking_account(): + bank = Bank() + checkingAccount = Account(CHECKING) + bill = Customer("Bill").openAccount(checkingAccount) + bank.addCustomer(bill) + checkingAccount.deposit(100.0) + assert_equals(bank.totalInterestPaid(), 0.1 * DateProvider.getTotalDaysPassedRatio()) + +def test_savings_account(): + bank = Bank() + savingsAccount = Account(SAVINGS) + bank.addCustomer(Customer("Bill").openAccount(savingsAccount)) + savingsAccount.deposit(1500.0) + assert_equals(bank.totalInterestPaid(), savingsAccount.interestEarned()) + + +def test_maxi_savings_account(): + bank = Bank() + maxiSavingsAccount = Account(MAXI_SAVINGS) + bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount)) + maxiSavingsAccount.deposit(3000.0) + assert_equals(bank.totalInterestPaid(), maxiSavingsAccount.interestEarned()) \ No newline at end of file From 1a17f37a4e77a50b48fbbd2e3bf6e5889620d8ba Mon Sep 17 00:00:00 2001 From: Pratik Bhatia Date: Thu, 5 May 2016 15:30:19 -0400 Subject: [PATCH 12/12] Added some tests for account Remove the account statement not required Added test cases for all accounts --- abcbank/account.py | 5 ++-- abcbank/transaction.py | 4 +-- tests/account_tests.py | 58 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 tests/account_tests.py diff --git a/abcbank/account.py b/abcbank/account.py index ca9b7fa..cb3ebce 100644 --- a/abcbank/account.py +++ b/abcbank/account.py @@ -50,6 +50,7 @@ def interestEarned(self): if self.accountType == MAXI_SAVINGS: if not self.checkTransactionInLastTenDays(): return amount * 0.005 * DateProvider.getTotalDaysPassedRatio() + else: return amount * 0.001 * DateProvider.getTotalDaysPassedRatio() else: return amount * 0.001 * DateProvider.getTotalDaysPassedRatio() @@ -59,8 +60,8 @@ def sumTransactions(self): def checkTransactionInLastTenDays(self): for t in self.transactions: if t.transactionDate >= DateProvider.tenDaysAgo(): - return False - return True + return True + return False def transfer(self, toAccount, amount): if self == toAccount: diff --git a/abcbank/transaction.py b/abcbank/transaction.py index 8e5b5ad..9ce4213 100644 --- a/abcbank/transaction.py +++ b/abcbank/transaction.py @@ -1,7 +1,7 @@ -from datetime import datetime +from abcbank.date_provider import DateProvider class Transaction: def __init__(self, amount): self.amount = amount - self.transactionDate = datetime.now() \ No newline at end of file + self.transactionDate = DateProvider.now() \ No newline at end of file diff --git a/tests/account_tests.py b/tests/account_tests.py new file mode 100644 index 0000000..22bf3a3 --- /dev/null +++ b/tests/account_tests.py @@ -0,0 +1,58 @@ +from nose.tools import assert_equals + +from abcbank.account import Account, CHECKING, MAXI_SAVINGS, SAVINGS +from abcbank.bank import Bank +from abcbank.customer import Customer +from abcbank.date_provider import DateProvider +from datetime import datetime + +def check_transfer_account(): + checkingAccount = Account(CHECKING) + savingsAccount = Account(SAVINGS) + henry = Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount) + checkingAccount.deposit(100.0) + savingsAccount.deposit(4000.0) + savingsAccount.transfer(checkingAccount, 100) + henry.getStatement() + assert_equals(henry.getStatement(), 'Statement for Henry\n\n' + 'Checking Account\n deposit $100.00\n ' + ' deposit $100.00\nTotal $200.00\n\nSavings Account\n ' + ' deposit $4000.00\n withdrawal $100.00\nT' + 'otal $3900.00\n\nTotal In All Accounts $4100.00') + +def test_checking_account(): + bank = Bank() + checkingAccount = Account(CHECKING) + bill = Customer("Bill").openAccount(checkingAccount) + bank.addCustomer(bill) + checkingAccount.deposit(100.0) + assert_equals(checkingAccount.interestEarned(), 0.1 * DateProvider.getTotalDaysPassedRatio()) + +def test_savings_account(): + bank = Bank() + savingsAccount = Account(SAVINGS) + bank.addCustomer(Customer("Bill").openAccount(savingsAccount)) + savingsAccount.deposit(1500.0) + assert_equals(savingsAccount.interestEarned(), savingsAccount.getSavingsAccountGT1000(1500) ) + + +def test_check_transaction_in_last_10_days(): + bank = Bank() + maxiSavingsAccount = Account(MAXI_SAVINGS) + bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount)) + maxiSavingsAccount.deposit(3000.0) + assert_equals(maxiSavingsAccount.transactions[0].amount, 3000) + assert_equals(maxiSavingsAccount.transactions[0].transactionDate.year, DateProvider.now().year) + assert_equals(maxiSavingsAccount.transactions[0].transactionDate.month, DateProvider.now().month) + assert_equals(maxiSavingsAccount.transactions[0].transactionDate.day, DateProvider.now().day) + assert_equals(maxiSavingsAccount.transactions[0].transactionDate >= DateProvider.tenDaysAgo(), True) + assert_equals(maxiSavingsAccount.checkTransactionInLastTenDays(), True) + + +def test_maxi_savings_account(): + bank = Bank() + maxiSavingsAccount = Account(MAXI_SAVINGS) + bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount)) + maxiSavingsAccount.deposit(3000.0) + assert_equals(maxiSavingsAccount.checkTransactionInLastTenDays(), True) + assert_equals(3000 * 0.001 * DateProvider.getTotalDaysPassedRatio(), maxiSavingsAccount.interestEarned()) \ No newline at end of file