def test_maxi_savings_account(): bank = Bank() checkingAccount = Account(MAXI_SAVINGS) bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) year_behind = datetime.datetime.now() - datetime.timedelta(365) checkingAccount.deposit(3000.0, year_behind) assert_equals(bank.totalInterestPaid(), 150.0)
def test_threeAccounts(): bank = Bank() oscar = bank.addCustomer("Oscar") oscar_savings = oscar.openAccount('SAVINGS') oscar_checking = oscar.openAccount('CHECKING') oscar_checking = oscar.openAccount('MAXI_SAVINGS') assert_equals(oscar.numAccs(), 3)
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())
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_checking_account(): bank = Bank() bill = bank.addCustomer("Bill") bill_new_checking = bill.openAccount('CHECKING') bill_new_checking.deposit(100.00) bill_new_checking.account_age_in_days = 20 assert_equals(round(bank.totalInterestPaid(),3), .005)
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_savings_account(): bank = Bank() bill = bank.addCustomer("Bill") bill_new_maxi = bill.openAccount('MAXI_SAVINGS') bill_new_maxi.deposit(1500.0) bill_new_maxi.account_age_in_days = 10 assert_equals(round(bill_new_maxi.interestEarnedDaily(),2),1.9)
def test_maxi_savings_account(): bank = Bank() maxiAccount = MaxiSavingsAcc() bank.addCustomer(Customer("Bill").openAccount(maxiAccount)) maxiAccount.deposit(3100.0) maxiAccount.withdraw(100.0) assert_true(bank.totalYearlyInterest() < 150.0)
def test_checking_account(): bank = Bank() checkingAccount = CheckingAcc() bill = Customer("Bill").openAccount(checkingAccount) bank.addCustomer(bill) checkingAccount.deposit(100.0) assert_equals(bank.totalYearlyInterest(), 0.1)
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_checking_account(): bank = Bank() checkingAccount = Account(CHECKING) bill = Customer("Bill").openAccount(checkingAccount) bank.addCustomer(bill) year_behind = datetime.datetime.now() - datetime.timedelta(365) checkingAccount.deposit(100.0, year_behind) assert_equals(bank.totalInterestPaid(), 0.1)
def test_maxi_savings_account_with_withdrawals(): bank = Bank() checkingAccount = Account(MAXI_SAVINGS) bank.addCustomer(Customer("Bill").openAccount(checkingAccount)) year_behind = datetime.datetime.now() - datetime.timedelta(365) five_days_behind = datetime.datetime.now() - datetime.timedelta(5) checkingAccount.deposit(3000.0, year_behind) checkingAccount.withdraw(1000.0, five_days_behind) assert_almost_equals(bank.totalInterestPaid(), 147.97, places=2)
def test_statement(): henry = Bank().add_customer("Henry") henry.open_account('Checking', 100) henry.open_account('Savings', 4000).withdraw(200.0) assert_equals(henry.statement, "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_statement(): account = Bank().add_customer('Praveen').open_account('Checking', 5) account.withdraw(4) assert_equal(account.statement, """ Checking Account deposit $5.00 withdrawal $4.00 Total $1.00 """)
def test_transfer(): bank = Bank() bill = bank.addCustomer("Bill") bill_savings = bill.openAccount('SAVINGS') bill_checking = bill.openAccount('CHECKING') bill_savings.deposit(200.0) bill_checking.deposit(100.0) bill.makeTransfer(50.0,bill_savings,bill_checking) assert_equals(bill_checking.balance,50.0) assert_equals(bill_savings.balance,250.0)
def test_transfer(): holly = Bank().add_customer('Holly') holly.open_account('Savings', 2500) holly.open_account('Maxi Savings', 3000) # blow up if there are insufficient funds in the only account of a type assert_raises_regexp(StandardError, r'Insufficient funds: [$]2500.00 available; [$]3000.00 requested' , holly.transfer, 'Savings', 'Checking', 3000) second_savings_account = holly.open_account('Savings', 300) # blow up if there are insufficient funds in all accounts of a type assert_raises_regexp(StandardError, r'Insufficient funds: [$]2800.00 available; [$]3000.00 requested' , holly.transfer, 'Savings', 'Checking', 3000) second_savings_account.deposit(200) checking_account = holly.transfer('Savings', 'Checking', 3000) # Successful transfer into a new account assert_equals(''' Checking Account deposit $3000.00 Total $3000.00 ''', checking_account.statement) # Successful transfer into an existing account holly.transfer('Maxi Savings', 'Checking', 3000) assert_equals('Statement for Holly\n\nSavings Account\n deposit $2500.00\n withdrawal $2500.00\nTotal $0.00\n\nMaxi Savings Account\n deposit $3000.00\n withdrawal $3000.00\nTotal $0.00\n\nSavings Account\n deposit $300.00\n deposit $200.00\n withdrawal $500.00\nTotal $0.00\n\nChecking Account\n deposit $3000.00\n deposit $3000.00\nTotal $6000.00\n\nTotal In All Accounts $6000.00', str(holly)) # blow up if either the from or two account types are not recognized assert_raises_regexp(StandardError, 'Invalid account type Fandango', holly.transfer, 'Fandango', 'Checking', 1) assert_raises_regexp(StandardError, 'Invalid account type Fandango', holly.transfer, 'Checking', 'Fandango', 1)
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_statement(): bank = Bank() henry = bank.addCustomer("Henry") henry_checking=henry.openAccount('CHECKING') henry_savings = henry.openAccount('SAVINGS') henry_checkings.deposit(100.0) henry_savings.deposit(4000.0) henry_savings.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_interest(): """ @todo These tests cannnot go to Production without making them robust to leap years, which you could do simply by turning down the precision on assert_almost_equals: keeping the precision would require pretty rococo test code """ bank = Bank() one_year_ago = datetime.today() - timedelta(days = 365) two_years_ago = one_year_ago - timedelta(days = 365) # first customer with checking account bank.add_customer("Bill").open_account('Checking', 100.0, two_years_ago) # 10 ¢ interest expected_interest = 100* (pow(1 + 1./365000, 730) - 1) assert_almost_equal(expected_interest, bank.total_interest_paid) # second customer with savings account bank.add_customer("Jill").open_account('Savings', 1500.0, one_year_ago) # $2 interest expected_interest += 1500 * (pow(1 + (4./3)/365000, 365) - 1) assert_almost_equal(expected_interest, bank.total_interest_paid) # third customer with maxi savings account phil = bank.add_customer("Phil") maxi_savings_account = phil.open_account('Maxi Savings', 3000, datetime.today() - timedelta(days = 30)) expected_interest_plus_30_days_maxi = expected_interest + 3000 * (pow(1 + 50./365000, 30) - 1) assert_almost_equal(expected_interest_plus_30_days_maxi, bank.total_interest_paid) # third customer's maxi savings account suffers a withdrawal maxi_savings_account.withdraw(2000, datetime.today() - timedelta(days = 20)) # 3000@10 days maxi interest, 1000@10 days mini interest, 1000@10 days maxi interest maxi_interest = 3000 * (pow(1 + 50./365000, 10) - 1) maxi_interest += (1000 + maxi_interest) * (pow(1 + 1./365000, 10) - 1) maxi_interest += (1000 + maxi_interest) * (pow(1 + 50./365000, 10) - 1) expected_interest += maxi_interest assert_almost_equal(expected_interest, bank.total_interest_paid) # third customer has two accounts phil.open_account('Checking', 100.0, datetime.today() - timedelta(days = 30)) expected_interest += 100* (pow(1 + 1./365000, 30) - 1) assert_almost_equal(expected_interest, bank.total_interest_paid)
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() bill = bank.addCustomer("Bill") bill_new_maxi = bill.openAccount('MAXI_SAVINGS') bill_new_maxi.deposit(3000.0)
def test_customer_summary(): bank = Bank() john = bank.addCustomer('John') john_new_checking = john.openAccount('CHECKING') assert_equals(bank.customerSummary(),"Customer Summary\n - John (1 account)")
class TestBank: def setUp(self): self.bank = Bank() def tearDown(self): pass def test_customer_summary(self): john = Customer("John").openAccount(SavingsAc()) self.bank.addCustomer(john) assert_equals(self.bank.customerSummary(), "Customer Summary\n - John (1 account)") def test_checking_account(self): checkingAccount = CheckingAc() bill = Customer("Bill").openAccount(checkingAccount) self.bank.addCustomer(bill) txnDate = datetime.strptime('May 1 2016 10:14AM', '%b %d %Y %I:%M%p') checkingAccount.deposit(100.0, txnDate) txnDate = datetime.strptime('May 5 2016 3:21PM', '%b %d %Y %I:%M%p') checkingAccount.deposit(200.0, txnDate) #since we moved over to daily interest and the total interest # is calculated on a daily basis, this result will change # assert_equals(self.bank.totalInterestPaid(), 0.1) assert_equals(self.bank.totalInterestPaid(), 0.00410958904109589) def test_savings_account(self): savingsAccount = SavingsAc() self.bank.addCustomer(Customer("Bill").openAccount(savingsAccount)) txnDate = datetime.strptime('May 1 2012 10:14AM', '%b %d %Y %I:%M%p') savingsAccount.deposit(100.0, txnDate) assert_equals(self.bank.totalInterestPaid(), 0.40273972602739727) def test_maxi_savings_account(self): maxiSavingsAccount = MaxiSavingsAc() self.bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount)) txnDate = datetime.strptime('Feb 5 2012 4:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.deposit(3000.0,txnDate) # Different interest after maxi interst calculation logic is changed # assert_equals(self.bank.totalInterestPaid(), 170.0) assert_equals(self.bank.totalInterestPaid(), 639.4520547945206) def test_maxi_savings_account_recent_withdrawal(self): maxiSavingsAccount = MaxiSavingsAc() self.bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount)) txnDate = datetime.strptime('Feb 5 2012 3:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.deposit(200.0, txnDate) txnDate = datetime.strptime('Feb 5 2012 4:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.deposit(3000.0, txnDate) # Putting a date in the future, which should fail elsewhere in the ideal # scenario, but this is to ensure that this test case passes for a longtime txnDate = datetime.strptime('May 9 2016 3:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.withdraw(100.0, txnDate) assert_equals(self.bank.totalInterestPaid(), 0.008493150684931507) def test_maxi_savings_account_nonrecent_withdrawal(self): maxiSavingsAccount = MaxiSavingsAc() self.bank.addCustomer(Customer("Bill").openAccount(maxiSavingsAccount)) txnDate = datetime.strptime('Feb 5 2012 3:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.deposit(200.0, txnDate) txnDate = datetime.strptime('Feb 5 2012 4:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.deposit(3000.0, txnDate) txnDate = datetime.strptime('Mar 19 2012 3:21PM', '%b %d %Y %I:%M%p') maxiSavingsAccount.withdraw(100.0, txnDate) assert_equals(self.bank.totalInterestPaid(), 642.5068493150685)
def test_open_account(): oscar = Bank().add_customer("Oscar") oscar.open_account('Savings') oscar.open_account('Checking') oscar.open_account('Maxi Savings') assert_equals(len(oscar.accounts), 3)
def test_customer_summary(): bank = Bank() bank.add_customer('John').open_account('Checking') assert_equals("Customer Summary\n - John (1 account)", bank.customer_summary)
def test_interest(): account = Bank().add_customer('Penelope').open_account('Maxi Savings') account.deposit(5000, datetime.today() - timedelta(2)) expected_interest = 5000*(pow(1 + 50./365000, 2) - 1) assert_almost_equal(expected_interest, account.interest_earned()) account.withdraw(4000, datetime.today() - timedelta(1)) # one day of 5 % interest on $5000 expected_interest = 5000*(pow(1 + 50./365000, 1) - 1) # one day of 1 mil interest on $1000 expected_interest += (1000 + expected_interest)*(pow(1 + 1./365000, 1) - 1) # @todo this blows up at midnight, as another day's interest gets added assert_almost_equal(expected_interest, account.interest_earned()) account = Bank().add_customer('Dick').open_account('Maxi Savings') account.deposit(5000, datetime.today() - timedelta(16)) expected_interest = 5000*(pow(1 + 50./365000, 16) - 1) assert_almost_equal(expected_interest, account.interest_earned()) account.withdraw(4000, datetime.today() - timedelta(15)) # one day of 5 % interest on $5000 expected_interest = 5000*(pow(1 + 50./365000, 1) - 1) # ten days of 1 mil interest on $1000 + earned interest expected_interest += (1000 + expected_interest)*(pow(1 + 1./365000, 10) - 1) # five days of 5 % interest on $1000 + earned interest expected_interest += (1000 + expected_interest)*(pow(1 + 50./365000, 5) - 1) assert_almost_equal(expected_interest, account.interest_earned()) # check interest over one year against the interest function one_year_ago = datetime.now() - timedelta(365) # the leap day can cause an error up to about 1/3 % checking_account = Bank().add_customer('Xinqi').open_account('Checking', 1000, one_year_ago) expected_interest = 1000*(pow(1 + 1./365000, 365) - 1) assert_almost_equal(expected_interest, checking_account.interest_earned()) savings_account = Bank().add_customer('Yong').open_account('Savings', 5000, one_year_ago) # one fifth is at 0.001, four-fifths is at 0.002, so 0.0018 is the rate expected_interest = 5000*(pow(1 + 1.8/365000, 365) - 1) assert_almost_equal(expected_interest, savings_account.interest_earned())
def setUp(self): self.bank = Bank()
def test_transactions(): account = Bank().add_customer('Kavita').open_account('Savings', 5) assert_equal([transaction.amount for transaction in account._transactions], [5,]) account.withdraw(5) assert_equal([transaction.amount for transaction in account._transactions], [5, -5,])
def test_customer_summary(): bank = Bank() john = Customer("John").openAccount(Account(CHECKING)) bank.addCustomer(john) assert_equals(bank.customerSummary(), "Customer Summary\n - John (1 account)")
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())