《Python编程:从入门到实践》答案(第十一章)

人80%的行为出自于习惯。每个月改正一个习惯可让人一年拥有12个好习惯。十年下来这个人会有质的飞越。

 

#city_functions.py
def country_city():
	city=input("Enter your city: ")
	country=inpout("Enter your country: ")
	hometown=city+' '+country
	return hometown.title()
#text_city_functions.py
import unittest
from city_functions import country_city

class CityCountryTest(unittest.TestCase):	
	def test_city_country(self):
		'''测试城市和国家功能'''
		output=country_city('santiago','chile')
		self.arrestEqual(output,'Santiago Chile')
unittest.main()

 

#city_functions.py
def country_city(city,country,population):
	hometown=city+','+country+'- population '+population
	return hometown.title()
#test_cities.py
import unittest
from city_functions import country_city
class CityCountryTest(unittest.TestCase):	
	def test_city_country(self):
		'''测试城市和国家功能'''
		output=country_city('santiago','chile')
		self.assertEqual(output,'Santiago Chile')
unittest.main()

 

#city_functions.py
def country_city(city,country,population=''):
	if population:
		
		hometown=city+' '+country+'-population '+population
	else:
		hometown=city+' '+country
	return hometown.title()
#test_cities.py
import unittest
from city_functions import country_city
class CityCountryTest(unittest.TestCase):	
	def test_city_country(self):
		'''测试城市和国家功能'''
		output=country_city('santiago','chile')
		self.assertEqual(output,'Santiago Chile')
unittest.main()
#test_cities.py
import unittest
from city_functions import country_city
class CityCountryTest(unittest.TestCase):	
	def test_city_country(self):
		'''测试城市和国家功能'''
		output=country_city('santiago','chile')
		self.assertEqual(output,'Santiago Chile')
	def test_city_country_population(self):
		'''测试有人口的输入是否可行'''
		output=country_city('santiago','chile','500000')
		self.assertEqual(output,'Santiago Chile-Population 500000')
unittest.main()

#employee.py
class Employee():
	def __init__(self,firstname,lastname,salary):
		self.firstname=firstname
		self.lastname=lastname
		self.salary=int(salary)
	def give_raise(self,increase=''):
		if increase!='':
			self.salary+=int(increase)
		else:
			self.salary+=5000
#testEmployee.py
import unittest
from employee import Employee

class EmployeeTest(unittest.TestCase):
	def setUp(self):
		self.test_employee=Employee('zhang','chenchen',13000)
		
	def test_give_default_raise(self):
		self.test_employee.give_raise(8000)
		
	def test_give_custom_raise(self):
		self.test_employee.give_raise()
unittest.main()

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页