Ejemplo n.º 1
0
class EmployeeTestCase(unittest.TestCase):
    def setUp(self):
        self.my_employee = Employee('Maria', 'Maximovich', 10000)

    def test_give_default_raise(self):
        self.my_employee.give_raise()
        self.assertEqual(self.my_employee.annual_salary, 15000)

    def test_give_custom_raise(self):
        self.my_employee.give_raise(10000)
        self.assertEqual(self.my_employee.annual_salary, 20000)
Ejemplo n.º 2
0
class EmployeeTestCase(unittest.TestCase):
    def setUp(self):  #setUp()方法创建一个实例供后面测试使用,可以避免反复创造的麻烦
        self.fault = Employee('zhang', 'san', 3000)
        #setUp()方法创建实例时变量名前缀含‘self’(即存储在属性中)
    def test_give_default_raise(self):  #因此可以在这个类的任何地方使用
        self.fault.give_raise()  #调用setUp()方法创建的实例类似C语言的结构体调用
        self.assertEqual(self.fault.money, 8000)  #要先‘。实例名’+实例所在类的对应方法

    def test_give_custom_raise(self):
        self.fault.give_raise(10000)
        self.assertEqual(self.fault.money, 13000)
Ejemplo n.º 3
0
class TestEmployee(unittest.TestCase):
    def setUp(self):
        self.employee1 = Employee('qiu', 'bin', 10000)
        self.salarys = 7000

    def test_give_default_raise(self):
        self.employee1.give_raise()
        self.assertEqual(self.employee1.salary, 15000)

    def test_give_custom_raise(self):
        self.employee1.give_raise(self.salarys)
        self.assertEqual(self.employee1.salary, 17000)
Ejemplo n.º 4
0
class TestRaiseSalary(unittest.TestCase):

    def setUp(self):
        self.sam = Employee('sam', 'smith', 30000)


    def test_give_default_raise(self):
        self.sam.give_raise()
        self.assertEqual(self.sam.annual_salary, 35000)


    def test_give_custome_raise(self):
        self.sam.give_raise(500)
        self.assertEqual(self.sam.annual_salary, 30500)
Ejemplo n.º 5
0
class TestEmployeeSalary(unittest.TestCase):
    """Tests for the class Employee."""
    def setUp(self):
        """Create a test employee to use in tests."""
        self.brandon = Employee('brandon', 'lee', 57000.00)

    def test_give_default_raise(self):
        """Test that by default, a raise of $5000.00 is given."""
        self.brandon.give_raise()
        self.assertEqual(self.brandon.salary, 62000.00)

    def test_give_custom_raise(self):
        """Test that giving a custom raise works."""
        self.brandon.give_raise(3000)
        self.assertEqual(self.brandon.salary, 60000.00)
Ejemplo n.º 6
0
class TestEmployeeSalary(unittest.TestCase):
	"""Tests for the class Employee."""
	
	def setUp(self):
		"""
		Create an employee and and their values.
		"""
		self.new_employee = Employee('tom', 'gundersen', '400000')
	
	def test_default_raise(self):
		self.new_employee.give_raise()
		self.assertEqual(self.new_employee.salary, 450000)
	
	def test_custom_raise(self):
		self.new_employee.give_raise(80000)
		self.assertEqual(self.new_employee.salary, 480000)
Ejemplo n.º 7
0
class TestEmployee(unittest.TestCase):
    """employee的测试类"""
    def setUp(self):
        """创建一个employee的类"""
        self.myemployee = Employee('单建昌', 22, 4000)
        self.add = 3000

    def test_wage_add(self):
        """测试默认增加值"""
        self.myemployee.give_raise()
        self.assertEqual(9000, self.myemployee.wage)

    def test_wage_add_adjust(self):
        """测试自设值"""
        self.myemployee.give_raise(4000)
        self.assertEqual(8000, self.myemployee.wage)
Ejemplo n.º 8
0
from employee_class import Employee

new_employee = Employee('tom', 'gundersen', '400000')

print("The employee's name is " + new_employee.get_full_name())

increase = '80000'

print(new_employee.get_full_name() + " was given a raise of " + increase + ".")

new_employee.give_raise(increase)
print("Their new salary is " + str(new_employee.get_salary()) + ".")