示例#1
0
 def test_first_middle_last_name(self):
     """能够正确地处理像Wolfgang Amadeus Mozart这样的姓名吗"""
     formatted_name = get_formatted_name("wolfgang", "mozart", "amadeus")
     self.assertEqual(formatted_name, "Wolfgang Amadeus Mozart")
示例#2
0
 def test_get_first_middle_last_name(self):
     """测试是否能正确处理像Janis Joplin这样的姓名"""
     full_name = get_formatted_name("janis", "joplin")
     self.assertEqual(full_name, "Janis Joplin")
示例#3
0
 def test_first_last_name(self):
     """能够正确地处理像Janis Joplin这样的姓名吗?"""
     full_name = get_formatted_name("janis", "joplin")
     self.assertEqual(full_name, "Janis Joplin")
示例#4
0
    return full_name.title()


#再编写一个使用这个函数的程序
from name_founction 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("Please give me a last name: ")
    if last == "q":
        break

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

#11.1.1单元测试和测试用例
#11.1.2可通过的测试
#检查函数get_formatted_name()在给定名和姓是能否正确的工作

import unittest
from name_founction import get_formatted_name


class NamesTestCase(unittest.TestCase):
    """测试函数get_formatted_name()"""
    def test_first_last_name(self):
        """能够正确地处理像Janis Joplin这样的姓名吗?"""
        formatted_name = get_formatted_name("janis", "joplin")