-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-2.py
35 lines (22 loc) · 1.15 KB
/
11-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
11-2 人口数量 :
修改前面的函数,使其包含第三个必不可少的形参 population ,
并返回一个格式为 City, Country - population xxx 的字符串,
如 Santiago, Chile - population 5000000 。
运行 test_cities.py ,确认测试 test_city_country() 未通过。
修改上述函数,将形参 population 设置为可选的。
再次运行 test_cities.py ,确认测试 test_city_country() 又通过了。
再编写一个名为 test_city_country_population() 的测试,
核实可以使用类似于 'santiago' 、 'chile' 和 'population=5000000' 这样的值来调用这个函数。
再次运行 test_cities.py ,确认测试 test_city_country_population() 通过了。
"""
import unittest
from city_functions import CountryAndNation
class CityTest(unittest.TestCase):
def test_city_country(self):
format_name = CountryAndNation('santiago', 'chile')
self.assertEqual(format_name, 'Santiago,Chile')
def test_city_country_population(self):
format_name = CountryAndNation('santiago', 'chile', 5000000)
self.assertEqual(format_name, 'Santiago,Chile - population 5000000')
unittest.main()