第十一章作业

"""11.1 城市和国家"""
#city_functions.py
def city_country(city, country):
result = city +", " + country
return result

#test_cities.py
import unittest
from chapter11 import city_country

class CityTestCase(unittest.TestCase):
def test_city(self):
formatted_city = city_country('Santiago', 'Chile')
self.assertEqual(formatted_city, 'Santiago, Chile')

unittest.main()

        

"""11.2 人口数量"""

#city_functions.py

def city_country(city, country, population):
result = city +", " + country + " - population " + str(population)

return result

#test_cities.py
import unittest
from city_functions import city_country

class CityTestCase(unittest.TestCase):
def test_city(self):
formatted_city = city_country('Santiago', 'Chile')
self.assertEqual(formatted_city, 'Santiago, Chile')

unittest.main()


#city_functions.py

def city_country(city, country, population = ''):

if population:
result = city +", " + country + " - population " + str(population)
else:
result = city +", " + country
return result

#test_cities.py
import unittest
from city_functions import city_country

class CityTestCase(unittest.TestCase):
def test_city(self):
formatted_city = city_country('Santiago', 'Chile')
self.assertEqual(formatted_city, 'Santiago, Chile')

unittest.main()


#city_functions.py

def city_country(city, country, population = ''):

if population:
result = city +", " + country + " - population " + str(population)
else:
result = city +", " + country
return result

#test_cities.py
import unittest
from city_functions import city_country

class CityTestCase(unittest.TestCase):
def test_city(self):
formatted_city = city_country('Santiago', 'Chile')

self.assertEqual(formatted_city, 'Santiago, Chile')

        def test_city_country_population(self):
formatted_city = city_country('Santiago', 'Chile', '5000000')
self.assertEqual(formatted_city, 'Santiago, Chile - population 5000000')

unittest.main()


"""11.3 雇员"""

#employee.py

class Employee():
def __init__(self, first_name, last_name, salary):
self.first_name = first_name
self.last_name = last_name
self.salary = salary
def give_rasie(self, inc = '5000'):
self.salary = str(int(self.salary)+int(inc))


#test_employee.py

import unittest
from chapter11 import Employee


class TestEmployee(unittest.TestCase):
def setUp(self):
self.my_employee = Employee('Janis', 'Joplin', '100000')
self.salary = ['105000', '120000']
def test_give_default_raise(self):
self.my_employee.give_rasie()
self.assertIn(self.salary[0], self.my_employee.salary)
def test_give_custom_raise(self):
self.my_employee.give_rasie(20000)
self.assertIn(self.salary[1], self.my_employee.salary)


unittest.main()


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭