Andela Cirriculum


#1

Howdy!
i'm having difficulty getting past the third quiz on object oriented programming.
i'm getting the following errors under the test result:

1 . test_current_account_can_withdraw_valid_cash_amounts
Failure in line 29, in test_current_account_can_withdraw_valid_cash_amounts self.assertEquals(self.ca.balance, 22564, msg='Incorrect balance after withdrawal') AssertionError: Incorrect balance after withdrawal
2 . test_current_account_cannot_withdraw_more_than_current_balance
Failure in line 24, in test_current_account_cannot_withdraw_more_than_current_balance self.assertEquals(message, 'Cannot withdraw beyond the current account balance', msg='No overdrafts') AssertionError: No overdrafts
3 . test_savings_account_can_withdraw_valid_amounts_successfully
Failure in line 53, in test_savings_account_can_withdraw_valid_amounts_successfully self.assertEquals(2257, self.sa.balance, msg="Incorrect balance after withdrawal") AssertionError: Incorrect balance after withdrawal
4 . test_savings_account_cannot_withdraw_more_than_current_balance
Failure in line 48, in test_savings_account_cannot_withdraw_more_than_current_balance self.assertEquals(message, 'Cannot withdraw beyond the current account balance', msg='No overdrafts') AssertionError: No overdrafts

these are the tests being performed on my code:

import unittest

class CurrentAccountTestCases(unittest.TestCase):
  def setUp(self):
    self.ca = CurrentAccount()
    
  def tearDown(self):
    del self.ca

  def test_current_account_is_instance_of_bank_account(self):
    self.assertTrue(isinstance(self.ca, BankAccount), msg='CurrentAccount is not a subclass of BankAccount')
  
  def test_current_account_can_deposit_valid_amounts(self):
    balance = self.ca.deposit(1500)
    self.assertEquals(balance, 1500)
  
  def test_current_account_cannot_withdraw_more_than_current_balance(self):
    message = self.ca.withdraw(1500)
    self.assertEquals(message, 'Cannot withdraw beyond the current account balance', msg='No overdrafts')
  
  def test_current_account_can_withdraw_valid_cash_amounts(self):
    self.ca.deposit(23001)
    self.ca.withdraw(437)
    self.assertEquals(self.ca.balance, 22564, msg='Incorrect balance after withdrawal')
    
class SavingsAccountTestCases(unittest.TestCase):
  def setUp(self):
    self.sa = SavingsAccount()
    
  def tearDown(self):
    del self.sa
  
  def test_savings_account_is_instance_of_bank_account(self):
    self.assertTrue(isinstance(self.sa, BankAccount), msg='SavingsAccount is not a subclass of BankAccount')

  def test_savings_account_can_deposit_valid_amounts(self):
    init_balance = self.sa.balance
    balance = self.sa.deposit(1500)
    self.assertEquals(balance, (1500 + init_balance), msg='Balance does not match deposit')

  def test_savings_account_cannot_withdraw_more_than_current_balance(self):
    message = self.sa.withdraw(1500)
    self.assertEquals(message, 'Cannot withdraw beyond the current account balance', msg='No overdrafts')

  def test_savings_account_can_withdraw_valid_amounts_successfully(self):
    self.sa.deposit(2300)
    self.sa.withdraw(543)
    self.assertEquals(2257, self.sa.balance, msg="Incorrect balance after withdrawal")

I have tested my code in my PC with all the tests on the andela quiz and it works just fine. Any help on where my code is wrong will be greatly appreciated. thanks if you have an improvement of my code, I also wouldn't mind. this is my code:

class BankAccount(object):
	balance = 0
	def withdraw(self,cWithdraw):
		self.cWithdraw = cWithdraw
		if (self.cWithdraw>BankAccount.balance):
			pass
			#print ("cannot withdraw beyond the current account balance")
		elif (self.cWithdraw<0):
			pass
			#return "invalid withdraw amount"
		else:
			BankAccount.balance = BankAccount.balance - cWithdraw
			totals = BankAccount.balance
			BankAccount.balance = 0
			return totals

    def deposit(self,cDeposit):
	self.cDeposit = cDeposit
	if (self.cDeposit < 0):
		pass
		#return "invalid deposit amount"
	else:
		BankAccount.balance =BankAccount.balance + cDeposit
		return BankAccount.balance
class SavingsAccount(BankAccount):
	balance = 0
	def __init__(self):
		self.balance=500
		self.ba = BankAccount()

    def deposit(self, cDeposit):
	self.cDeposit = cDeposit + self.balance
	tTotal = self.ba.deposit(self.cDeposit)
	return tTotal

def withdraw(self,cWithdraw):
	self.cWithdraw = cWithdraw
	if ((BankAccount.balance - self.cWithdraw) <=500):
		pass
		#print ("cannot withdraw beyond the minimum account balance")
	else:
		tTotal = self.ba.withdraw(self.cWithdraw)
		SavingsAccount.balance = tTotal
		return tTotal
class CurrentAccount(BankAccount):
	def __init__(self):
		self.ba = BankAccount()

    def deposit(self, cDeposit):
	self.cDeposit = cDeposit
	tTotal = self.ba.deposit(self.cDeposit)
	return tTotal

def withdraw(self,cWithdraw):
	self.cWithdraw = cWithdraw
	tTotal = self.ba.withdraw(self.cWithdraw)
	CurrentAccount.balance = tTotal
	return tTotal

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.