第十一次高级编程作业

11-1 城市和国家
city_functions.py 部分

def city_functions(city,country):
    full_name = city.title() + ", "+country.title();
    return full_name

测试程序部分:

import unittest
from city_functions import city_function

class NamesTestCase(unittest.TestCase):
    def city_country_test(self):
        full_name = city_functions('shenzhen', 'china')
        self.assertEqual(full_name, 'Shenzhen, China')
if __name__ == '__main__':
    unittest.main()

11-2 人口数量
city_functions.py部分

def city_function(city,country,population):
    full_name = city + ", "+country + " - population " + population;
    return full_name.title()

测试函数部分

import unittest
from city_functions import city_function

class NamesTestCase(unittest.TestCase):
    def city_country_test(self):
        full_name = city_functions('Santiago', 'Chile', '5000000')
        self.assertEqual(full_name, 'Santiago, Chile - population 5000000')
if __name__ == '__main__':
    unittest.main()

11-3 雇员
myEmployee.py部分

class AnonymousSurvey():
    def __init__(self, myname,myage,mysalary):
        self.naem = myname
        self.age = myage
        self.salary = mysalary
    def give_raise(self,inc=5000):
        self.salary = self.salary + inc;

测试函数部分

import unittest
from myEmployee import employee
class TestEmployee(unittest.TestCase):
    def setUp(self):
        self.my_employee = employee("Tim",30,5000)
    def test_give_default_raise():
        self.my_employeegive_raise()
        self.assertIn(self.my_employee(10000, self.my_employee.salary))
    def test_give_custom_raise():
        self.my_employeegive_raise(1000)
        self.assertIn(self.my_employee(11000, self.my_employee.salary))

unittest.main()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值