# 【第六周】第十一章全部习题

11-1 城市和国家

city_functions.py

def union(city,country):
return city + ',' + country


test_cities.py

import unittest
from city_functions import union

class Test(unittest.TestCase):
def test1(self):
form = union('Santiago', 'Chile')
self.assertEqual(form, 'Santiago,Chile')

unittest.main

11-2 人口数量

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

import unittest
from city_functions import union

class Test(unittest.TestCase):
def test1(self):
form = union('Santiago', 'Chile',population=5000000)
self.assertEqual(form, 'Santiago,Chile- population 5000000')

unittest.main


11-3 雇员

class Employee:
def __init__(self, first_name, last_name, salary=0):
self.first_name = first_name
self.last_name = last_name
self.salary = salary

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

import unittest
from city_functions import Employee

class Test(unittest.TestCase):
def setUp(self):
self.e1 = Employee('Bob', 'Stevin')
self.e2 = Employee('Stuart', 'Kevin', 5000)

def test_give_default_raise(self):
self.assertEqual(str(self.e1.give_raise()), '5000')

def test_give_custom_raise(self):
self.assertEqual(str(self.e2.give_raise(3000)), '3000')