1
我通过蟒蛇新秀的工作,和我遇到的,我不得不做出一个课堂上提问时,和子类这是很好的(我相信香港专业教育学院做了右)Python类和单元测试
但我现在必须包括一些python 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)
我想不出哪里unfortinatly这个开始,我读过章节,但我不能深入了解它 – Unknown 2012-03-27 03:01:20
也许阅读文档将有所帮助:http://docs.python.org/library/unittest.html#basic-example – Eddie 2012-03-27 03:10:13
我已阅读它,但也许我会花更多的时间在上面,尝试从那里开始和发布信息,谢谢你的帮助 – Unknown 2012-03-27 03:12:52