11-1,城市和国家
import unittest
from city_functions import city_country
class TestCase(unittest.TestCase):
def test_format(self):
formatname = city_country('Santiago', 'Chile')
self.assertEqual(formatname, 'Santiago,Chile')
def city_country(city, country, population):
return city + ',' + country +' - population ' + str(population)
![](https://i-blog.csdnimg.cn/blog_migrate/2dafdd2122e61589f4fcdf44c5469505.png)
11-2,人口数量
import unittest
from city_functions import city_country
class TestCase(unittest.TestCase):
def test_format(self):
formatname = city_country('Santiago', 'Chile', 5000000)
self.assertEqual(formatname, 'Santiago,Chile')
def city_country(city, country, population):
return city + ',' + country +' - population ' + str(population)
![](https://i-blog.csdnimg.cn/blog_migrate/b2c4f9112986ce64995392ec2274718f.png)
def city_country(city, country, population = 0):
if population:
return city + ',' + country +' - population ' + str(population)
else:
return city + ',' + country
import unittest
from city_functions import city_country
class TestCase(unittest.TestCase):
def test_format(self):
formatname = city_country('Santiago', 'Chile')
self.assertEqual(formatname, 'Santiago,Chile')
import unittest
from city_functions import city_country
class TestCase(unittest.TestCase):
def test_format(self):
formatname = city_country('Santiago', 'Chile')
self.assertEqual(formatname, 'Santiago,Chile')
def test_city_country_population(self):
formatname = city_country('Santiago', 'Chile', 5000000)
self.assertEqual(formatname, 'Santiago,Chile - population 5000000')
![](https://i-blog.csdnimg.cn/blog_migrate/777e91fa3f746487f393a86331106d79.png)
11-3,雇员
import unittest
from city_functions import Employee
class TestCase(unittest.TestCase):
def setUp(self):
self.info = Employee('Li', 'Ming', 10)
def test_give_default_raise(self):
self.info.give_raise()
salary = self.info.salary
self.assertEqual(salary, 5000 + 10)
def test_give_custom_raise(self):
self.info.give_raise(10)
salary = self.info.salary
self.assertEqual(salary, 10 + 10)
![](https://i-blog.csdnimg.cn/blog_migrate/bcf752cf17b9b4533b686a9ac1793e0b.png)