hw6(第六周)

# [11-1, 11-2]
import unittest
# 11-1, 11-2
def city_country(city, country):
    return city + ', ' + country

def city_country2(city, country, population):
    return city + ', ' + country + ' - population ' + str(population)

def city_country3(city, country, population=5000000):
    return city + ', ' + country + ' - population ' + str(population)

class Test(unittest.TestCase):
    def test_city_country(self):
        self.assertEqual(city_country('Santiago', 'Chile'), 'Santiago, Chile')

    def test_city_country2(self):
        self.assertEqual(city_country2('Santiago', 'Chile'), 'Santiago, Chile - population 5000000')

    def test_city_country3(self):
        self.assertEqual(city_country3('Santiago', 'Chile'), 'Santiago, Chile - population 5000000')

    def test_city_country_population(self):
        self.assertEqual(city_country3('Santiago', 'Chile', population=5000000), 'Santiago, Chile - population 5000000')

unittest.main()

# [11-3]
# 11-3
import unittest
class Employee:
    def __init__(self, last_name, first_name, salary):
        self.last_name = last_name
        self.first_name = first_name
        self.salary = salary

    def give_raise(self, increament=5000):
        self.salary += increament

class TestEmployee(unittest.TestCase):
    def setUp(self):
        self.employee = Employee('A', 'B', 1000)
        self.employee2 = Employee('C', 'D', 1000)

    def test_give_default_raise(self):
        self.employee.give_raise()
        self.assertEqual(self.employee.salary, 6000)

    def test_give_custom_raise(self):
        self.employee2.give_raise(3000)
        self.assertEqual(self.employee2.salary, 4000)

unittest.main()

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭