zoukankan      html  css  js  c++  java
  • 20190919-4 单元测试,结对

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/7629

    git地址:https://e.coding.net/wangzw877/unittest.git

    一、测试用例及测试结果

    1.功能一测试用例

      1).输入f4,预计结果输出四则运算题目及 '?'

      

      2).输入正确结果,预计打印“答对啦!你真是个天才!”,然后继续输出下一道题目

      

      3).输入错误结果,预计打印“再想想吧,答案似乎是xx喔!”,然后继续输出下一道题目

       

     2.功能二测试用例

      1).输入f4,存在合理的有括号的四则运算题目

      

       2).答完设置的题目最后会提示做对的题目数量和题目总数量

      

     3.功能三测试用例

      1).输入f4 -c -1或f4 -c test后,提示“题目数量必须是正整数”

      

       2).输入f4 -c 10,自动生成“题目打印.txt”文件,打印10道题目

      

     二、代码中函数的详细测试

      单元测试是用来对一个模块、一个函数或者一个类来进行正确性检验的测试工作,为了编写单元测试,只需要引入Python自带的unittest模块。

      测试程序代码:

    # -*- coding: utf-8 -*-
    import unittest
    from f4 import *
    
    
    class F4Test(unittest.TestCase):
        def test_f4(self):
            pass
    
        def test01_create_equation(self):           # 测试顺序按函数名字字典顺序进行
            print("create_equation函数单元测试开始:")
            self.assertIsNotNone(create_equation())
            print("OK")
            print("create_equation函数单元测试结束。
    ")
    
        def test02_reverse_polish(self):
            eq = []
            print("reverse_polish函数单元测试开始:")
            equation = input("输入一个四则运算(括号请使用英文版的括号):")
            _eq_ans = input("输入正确的逆波兰表达式:")
            list(equation)          # 输入的表达式是str类型,该函数处理的是含有整型和字符型的list类型
            for temp in equation:
                if '0' <= temp <= '9':
                    eq.append(int(temp))
                else:
                    eq.append(temp)
            re_equation = reverse_polish(eq)
            str_equation = "".join('%s' % id for id in re_equation)
            self.assertEqual(_eq_ans, str_equation)
            print("OK")
            print("reverse_polish函数单元测试结束。
    ")
    
        def test03_calculate(self):
            eq = []
            print("calculate函数单元测试开始:")
            equation = input("输入一个可计算的逆波兰表达式:")
            _eq_ans = input("输入该表达式的正确结果:")
            list(equation)  # 输入的表达式是str类型,该函数处理的是含有整型和字符型的list类型
            for temp in equation:
                if '0' <= temp <= '9':
                    eq.append(int(temp))
                else:
                    eq.append(temp)
            result = calculate(eq)
            self.assertEqual(float(_eq_ans), result)
            print("OK")
            print("calculate函数单元测试结束。
    ")
    
    
    if __name__ == "__main__":
        unittest.main()
    View Code

      1.无括号的表达式

      

       2.有括号的表达式

      

     结论:测试均通过。

  • 相关阅读:
    转载 自定义ListView背景
    Android 在模拟器上创建sd卡
    转载 Android TextView加下划线
    转载 Dom4j生成xml
    转载 在Struts2中使用servlet 配置问题
    android开发不错的地方
    bat demo1自定义变量
    redhat 5下安装SVN
    linux 忘记root密码
    DEBUG Sigar no libsigarx86linux.so in java.library.path
  • 原文地址:https://www.cnblogs.com/wangzw822/p/11579833.html
Copyright © 2011-2022 走看看