指示没有透支的python unittest错误
我一直在进行测试,每次运行代码时,都会显示以下错误代码: 测试\u储蓄\u账户\u不能\u提取\u超过\u当前\u余额失败 在第48行,在 测试储蓄账户不能提取超过当前余额的存款 self.assertEquals(消息“不能超过当前帐户提取” 余额',msg='No overdrafts')断言错误:无透支**指示没有透支的python unittest错误,python,oop,python-unittest,Python,Oop,Python Unittest,我一直在进行测试,每次运行代码时,都会显示以下错误代码: 测试\u储蓄\u账户\u不能\u提取\u超过\u当前\u余额失败 在第48行,在 测试储蓄账户不能提取超过当前余额的存款 self.assertEquals(消息“不能超过当前帐户提取” 余额',msg='No overdrafts')断言错误:无透支** 因为您的默认余额是500,您的金额是1500,所以它将返回的字符串是“不能超过最低帐户余额提取”,而不是您期望的“不能超过当前帐户余额提取”您需要问一个特定的问题。 class Ban
因为您的默认余额是500,您的金额是1500,所以它将返回的字符串是“不能超过最低帐户余额提取”,而不是您期望的“不能超过当前帐户余额提取”您需要问一个特定的问题。
class BankAccount:
def withdraw(self):
pass
def deposit(self):
pass
class SavingsAccount(BankAccount):
def __init__(self, balance=500):
self.balance = balance
def deposit(self, amount):
if (amount <= 0):
return "Invalid deposit amount"
else:
self.balance += amount
return self.balance
def withdraw(self, amount):
if(amount <= 0):
return "Invalid withdraw amount"
elif(self.balance <= 500):
return "Cannot withdraw beyond the minimum account balance"
elif(amount > self.balance):
return "Cannot withdraw beyond the current account balance"
else:
self.balance -= amount
return self.balance
class CurrentAccount(BankAccount):
def __init__(self, balance=0):
self.balance = balance
def deposit(self, amount):
if (amount <= 0):
return "Invalid deposit amount"
else:
self.balance += amount
return self.balance
def withdraw(self, amount):
if (amount <= 0):
return "Invalid withdraw amount"
elif (amount >= self.balance):
return "Cannot withdraw beyond the current account balance"
else:
self.balance -= amount
return self.balance
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")