= =

……

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()
阅读更多
想对作者说点什么? 我来说一句

2008061023_CC_第六周作业

2011年04月04日 168KB 下载

MIT6.828 HW6: Threads and Locking

locking

bysui bysui

2016-05-31 14:59:06

阅读数:934

汉王中文系统 V2.00版

2018年01月25日 287KB 下载

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

不良信息举报

hw6(第六周)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭