#练习 11-1:
# #存储在名为city_functions.py的模块中
# def city_country(city,country):
# loc = f'{city},{country}'
# return loc.title()
# #创建一个名为test_cities.py的程序,对刚才的程序进行测试
# import unittest
# from city_functtions import city_country as cc
# class CityTestCase(unittest.TestCase):
# """用于测试city_country"""
# def test_city_country(self):
# """能够正确处理像,newyork,america的位置吗?"""
# loction = cc('newyork','america')
# self.assertEqual(loction,'Newyork,America')
# if __name__ == '__main__':
# unittest.main()
#练习 11-2:
# #存储在名为city_functions.py的模块中
# def city_country(city,country,population=''):
# if population:
# loc = f'{city},{country}-population {population}'
# else:
# loc = f'{city},{country}'
# return loc.title()
# #创建一个名为test_cities.py的程序,对刚才的程序进行测试
# import unittest
# class CityTestCase(unittest.TestCase):
# """用于测试city_country"""
# def test_city_country(self):
# """能够正确处理像,newyork,america的例子吗?"""
# loction = city_country('newyork','america')
# self.assertEqual(loction,'Newyork,America')
# def test_city_country_population(self):
# """能够正确处理像,newyork,america-Population 5000000的例子吗?"""
# example = city_country('newyork', 'america',5000000)
# self.assertEqual(example, "Newyork,America-Population 5000000")
# if __name__ == '__main__':
# unittest.main()
#练习 11-3:
# import unittest
# class Employee:
# def __init__(self,first_name,last_name,yearly_salary):
# """将三个变量存储在属性里,以供随时调用"""
# self.first_name = first_name
# self.last_name = last_name
# self.yearly_salary = yearly_salary
# def give_raise(self,amount = 5000):
# """每次将年薪增加五千美元"""
# self.yearly_salary += amount
# class TestEmployee(unittest.TestCase):
# def setUp(self):
# """
# 创建一个调查对象和一组答案,供使用的测试方法使用
# """
# self.my_employee = Employee('华','李',50000)
# def test_give_default_raise(self):
# """
# 测试增加五千年薪是否可行
# """
# self.my_employee.give_raise()
# self.assertTrue(self.my_employee.yearly_salary == 55000)
# def test_give_custom_raise(self):
# """
# 测试自定义增加年薪是否可行
# """
# self.my_employee.give_raise(100000)
# self.assertTrue(self.my_employee.yearly_salary == 150000)
# if __name__ == '__main__':
# unittest.main()