测试代码(测试函数)

 

测试函数:

name_function.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 21:54
# @Author  : solo
# @Site    : 
# @File    : name_function.py
# @Software: PyCharm

def get_formatted_name(first,middle,last,lll):
    full_name = first + ' ' + middle + ' '+ last + lllc
    return full_name.title()

 

names.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 21:56
# @Author  : solo
# @Site    : 
# @File    : names.py
# @Software: PyCharm

from  name_function import get_formatted_name

print("Enter 'q' at any time to quit.")
while True:
    first = input("\nplease give me a first name:")
    if first == 'q':
        break
    last = input("\nplease give me a last name:")
    if last == 'q':
        break

    get_formatted_name = get_formatted_name(first,last)
    print("\tNeatly formatteb name: " + get_formatted_name + ".")

 

执行结果:

Enter 'q' at any time to quit.

please give me a first name:jamea

please give me a last name:kason
    Neatly formatteb name: Jamea Kason.

please give me a first name:q

Process finished with exit code 0

 

 

 

单元测试和测试用例

 

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 22:06
# @Author  : solo
# @Site    : 
# @File    : test_name_function.py
# @Software: PyCharm

import unittest
from name_function import get_formatted_name

class NamesTestCase(unittest.TestCase):
    """测试name_function.py"""
    def test_first_last_name(self):
        """能否正确的处理名字?"""
        formatted_name = get_formatted_name('janis','joplin')
        self.assertEqual(formatted_name,'Janis Joplin')

unittest.main()

执行结果:

----------------------------------------------------------------------

Ran 0 tests in 0.000s

OK

 

转载于:https://www.cnblogs.com/aszeno/p/10415827.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值