zoukankan      html  css  js  c++  java
  • 测试代码(测试函数)

    测试函数:

    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("
    please give me a first name:")
        if first == 'q':
            break
        last = input("
    please give me a last name:")
        if last == 'q':
            break
    
        get_formatted_name = get_formatted_name(first,last)
        print("	Neatly 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
  • 相关阅读:
    虚拟内存思想
    虚拟内存映射 段分割 vm_area_struct
    进程、内存的理想与现实 VS 虚拟内存
    进程地址空间
    MMU CPU及思想
    链接器和加载器 好书
    编译器 链接器 加载器
    链接器简介
    C编译器、链接器、加载器详解
    静态库是.o文件的集合与弱符号
  • 原文地址:https://www.cnblogs.com/aszeno/p/10415827.html
Copyright © 2011-2022 走看看