20190919-4 unit test, pair

See, this job requires: [ https://edu.cnblogs.com/campus/nenu/2019fall/homework/7629 ]

 

Twinning partner: Han Hao

 

 

• Require a test case.

Function 1

Function 2

Function 3 

 

 

• Requires 2 detailed test report

Function 1

(A) with Example No. 2, 3:

"?" "?" "?" At first input f4, print after expression, no, according to the requirements need to change the line output, and then enter the expression in the answer, then try to modify the code as follows:

print(generator + '=\n?')

But this makes the output, followed by another output newline, like this "?":

How to make the output does not wrap it? The investigation code is a key change:

print(generator + '=\n?', end="")

In the end, the perfect solution

 

(Ii) with Example No. 4

Adding a hot-tempered teacher or student, due to the expression received Chaogang, and angry that he did not enter the answer, just hit Enter, the result would happen then?

I guess he saw this would be more angry, or even smashed the computer, we want to prevent such a thing happens, then how to do it? The point of it!

while i < num:
    mid_experison = Exp_Generator.Generator()
    generator = mid_experison.generate()
    print(generator + '=\n?', end="")
    suffix_expression = middle_to_after(generator)
    value = cal_suffix_exp_value(suffix_expression)
    answer = input()
    if answer.strip() == '':
        print('仿佛你拒绝回答了这道题,没关系,我们换一道,加油')
        continue
    if '?' in answer:
        answer = answer.replace('?', '')
    print_result(float(answer), value)
    i += 1

最后输出是这样的:

 

 

 功能2

(一)用例编号7

表达式转换成逆波兰式功能测试成功:

 TDD(UnitTest)关键代码:

# 表达式转换成逆波兰式功能测试
    def test_middle_to_after(self):
        print("表达式转换成逆波兰式功能单元测试开始:")
        _eq = input("输入一个四则运算中缀表达式:")
        _eq_ans = input("输入此中缀表达式的后缀表达式:")
        self.assertEqual(_eq_ans, Test()._test_middle_to_after(eq=_eq))
        print("表达式转换成逆波兰式功能单元测试结束。", end='\n\n')
        print("表达式求值功能测试完成", end='\n\n')

 

(二)用例编号8

不含括号表达式计算测试:

 TDD(UnitTest)关键代码:

# 表达式求值功能测试(不含括号)
    def test_answer_nobra(self):
        print("表达式求值功能单元测试(不含括号)开始:")
        _eq = input("输入一个四则运算:")
        _eq_ans = input("输入一个正确的答案:")
        self.assertEqual(_eq_ans ,Test()._test_answer(eq = _eq))
        print("表达式求值功能单元测试结束。", end='\n\n')
        print("表达式求值功能测试完成", end='\n\n')

 

(三)用例编号9

含括号表达式计算测试:

  TDD(UnitTest)关键代码:

# 表达式求值功能测试(含括号)
def test_answer_bra(self):
    print("表达式求值功能单元测试(含括号)开始:")
    _eq = input("输入一个四则运算:")
    _eq_ans = input("输入一个正确的答案:")
    self.assertEqual(_eq_ans, Test()._test_answer(eq=_eq))
    print("表达式求值功能单元测试结束。", end='\n\n')
    print("表达式求值功能测试完成", end='\n\n')

 

整体单元测试:

 

 

 功能3

(一)用例编号10、11、12

运行出错,是因为程序要根据用户输入的数字,来决定要输出的表达式的行数,而python默认从终端读进来的参数是str类型,所以需要将str类型的参数转换为int类型才可以利用到循环控制中。

# 功能三输出一行计算表达式及结果
def print_exp_result(num):
    i = 0
    num = int(num)
    while i < num:
        generate = Exp_Generator.Generator()
        mid_experision = generate.generate()
        suffix_expression = middle_to_after(mid_experision)
        value = cal_suffix_exp_value(suffix_expression)
        mid_experision += '='
        print('%-15s %-15s' % (mid_experision, value))
        i += 1

修改成功后:

 

 收获

接触python时间不长,第一次用python写如此规模的程序,感受到了python语法如此简洁且资源库如此强大带来的方便。不过在本次编程由fail到pass过程中,之所以fail的原因,大部分还是对语言本身理解掌握不够、需求分析不彻底不充分,最大的收获是,问题驱动下的学习方式,比单纯为了学技术而学技术,更实际可靠。

 

 

• 要求4 版本控制。

代码地址:[https://e.coding.net/secret/ASETest1_3.git]

Guess you like

Origin www.cnblogs.com/liuxp775/p/11574505.html