11-3 雇员:
编写一个名为Employee 的类,其方法__init__()接受名、姓和年薪,并将它们都存储在属性中。编写一个名为give_raise()的方法,它默认将年薪增加5000美元,但也能够接受其他的年薪增加量。为Employee 编写一个测试用例,其中包含两个测试方法:test_give_default_raise()和test_give_custom_raise()。使用方法setUp(),以免在每个测试方法中都创建新的雇员实例。运行这个测试用例,确认两个测试都通过了。
class Employee():
def __init__(self,first,last,salary):
self.first=first
self.last=last
self.salary=salary
def give_raise(self,increasement=5000): """如果没有给一个值,则默认值为5000"""
self.increasement=increasement
self.salary+=increasement
return self.salary
# def show_info(self): """这段注释掉的是我用来测试这个类有没有写错的"""
# print(self.first+" "+self.last+" "+str(self.salary))
# johnsmith=Employee('john','smith',10000)
# johnsmith.show_info()
</