第六周第一次作业

11-1城市和国家:

代码

函数:

def city_country( city, country):
res = city + " , " + country
return res


测试函数:

from test import city_country
import unittest

class City_countryTestCase( unittest. TestCase):

def test_city_country( self):
formatted = city_country ( ' santiago ' , ' chile ' )
self. assertEqual (formatted, ' santiago,chile ' )

unittest. main ()



测试结果:



11-2 人口数量

函数:


def city_country_population( city, country, population):
res = city + " , " + country + " - population " + str (population)
return res


测试函数

from test import city_country_population
import unittest

class City_countryTestCase( unittest. TestCase):

def test_city_country_population( self):
formatted = city_country_population ( ' santiago ' , ' chile ' , 50000000 )
self. assertEqual (formatted, ' santiago,chile - population 50000000 ' )

unittest. main ()


测试结果:



11-3雇员

函数:


class Employee():

def __init__( self, last_name, first_name, annual_salary):
self.last_name = last_name
self.first_name = first_name
self.annual_salary = annual_salary


def give_raise( self, raise_amount = 5000):
self.annual_salary += raise_amount


测试函数:


import unittest
from test import Employee

class TestEmployee( unittest. TestCase):

def setUp( self):
first_name = " fn "
last_name = " ln "
annual_salary = 100000

self.myEmployee = Employee (last_name, first_name, annual_salary)

def test_give_default_raise( self):
self.myEmployee. give_raise ()
self. assertEqual ( self .myEmployee.annual_salary, 105000 )

def test_give_custom_raise( self):
self.myEmployee. give_raise ( 10000 )
self. assertEqual ( self .myEmployee.annual_salary, 110000 )

unittest. main ()


测试结果:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值