Python编程作业【第六周】(二)

11-1 cities and countries

def get_city(city, country):
    city_country = city + ", " + country
    return city_country.title()
import unittest
from func import get_city

class NameTestCase(unittest.TestCase):

    def test_the_string(self):
        format_name = get_city("Beijing", "China")
        self.assertEqual(format_name, "Beijing, China")

unittest.main()

11-2 population

def get_city(city, country, population):
    city_country = city + ", " + country + " - " + population
    return city_country.title()
def get_city(city, country, population = '10000000'):
    city_country = city + ", " + country + " - " + population
    return city_country.title()
import unittest
from func import get_city

class NameTestCase(unittest.TestCase):

    def test_the_string(self):
        format_name = get_city("Beijing", "China")
        self.assertEqual(format_name, "Beijing, China - 10000000")

unittest.main()

11-3 employee

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_raise(self, add = 5000):
        self.salary += add
        return self.salary
import unittest
from func import Employee

class TestMyCase(unittest.TestCase):
    def setUp(self):
        self.emp = Employee("Binqi", "Zhao", 100)
    def test_give_default_raise(self):
        format_ans = self.emp.salary
        self.assertEqual(format_ans, 100)
    def test_give_add_raise(self):
        format_ans = self.emp.give_raise(2333)
        self.assertEqual(format_ans, 2433)

unittest.main()
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhaobinqi_98/article/details/79947185
个人分类: Python作业
想对作者说点什么? 我来说一句

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

关闭
关闭
关闭