Python类和unittest
我正在为新手学习python,我遇到了一个问题,我必须创建一个类和子类,这很好(我想我做得不错) 但是我现在必须使用pythonPython类和unittest,python,unit-testing,class,subclass,Python,Unit Testing,Class,Subclass,我正在为新手学习python,我遇到了一个问题,我必须创建一个类和子类,这很好(我想我做得不错) 但是我现在必须使用pythonunittest模块进行一些测试,我不知道如何实现这一点,如果有任何帮助,我将不胜感激 class BankAccount: def __init__(self): self.balance = 0 def withdraw(self,amount): if self.balance - amount <= 0:
unittest
模块进行一些测试,我不知道如何实现这一点,如果有任何帮助,我将不胜感激
class BankAccount:
def __init__(self):
self.balance = 0
def withdraw(self,amount):
if self.balance - amount <= 0:
print "Overdrawn, please try another option."
else:
self.balance -= amount
return self.balance
def deposit(self, amount):
self.balance += amount
return self.balance
def interest(self, amount):
percent = self.balance / 100.0 * amount
self.balance = self.balance + percent
return self.balance
class CreditAccount(BankAccount):
def withdraw(self,amount):
if self.balance - amount <= 0:
self.balance = self.balance - amount - 5
print "Overdrawn, you have been charged £5 for this."
return self.balance
else:
self.balance -= amount
return self.balance
class StudentAccount(BankAccount):
def __init__(self):
self.balance = 500
def withdraw(self, amount):
if self.balance - amount >= -3000:
self.balance -= amount
return self.balance
else:
print "£3000 Overdraft limit reached"
return self.balance
account = BankAccount()
account1 = CreditAccount()
account2 = StudentAccount()
account2.deposit(500)
类别银行账户:
定义初始化(自):
自平衡=0
def提取(自身、金额):
如果self.balance-amount让我帮你开始
my_account = BankAccount()
balance = my_account.deposit(1000) # can also be accessed by my_account.balance
希望你能从这里开始我不知道从哪里开始不幸的是,我读过这一章,但我没有太多的意义也许读一下文档会有所帮助:我读过,但我会花更多的时间在上面,试着从那里开始发帖,谢谢你的邀请help@user1289022:你需要更加明确。有什么你不明白的?这里有很多。首先,我想用它来测试什么,它并没有真正指定,我有点希望有人能根据我的代码有一个想法。该任务仅说明unittest模块的“包含一些测试”。