此作业的要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/7629
结对伙伴:罗杨美惠
要求1 对每个功能,先给出测试用例,然后再编码功能。请注意把测试用例视为功能需求完成的检验指标。 (40分)
功能一测试:
功能二测试:
要求2 在博客报告测试用例全部fail 到 全部pass 的过程,报告事实 (fail到修改代码或者测试用例,到pass) 以及收获。 除了最初的框架,测试用例中存在一次性pass没有经过fail的,也报告一次性通过,给出如此优秀地实现了这部分功能的代码。由2位同学中的一位发布博客提交到作业,指明自己的结对伙伴;另一位在作业中引用这一博客,指明自己的结对伙伴。(40分)
功能1
(1)功能一测试
起初输入f4,打印出现表达式后,无“?”,按照要求需要换行输出“?”,且在“?”之后输入表达式答案,于是尝试修改代码为:
print('?')
这样并没有解决 在“?”输出后,又输出了换行最后我们修改代码为
print('?', end="")
这样可以去掉换行,解决了问题,运行截图为:
(2)功能二测试
我们随机生成了20个算式后,没有出现一共答对多少道题,没有对正确题目进行统计输出,优化后的代码为:
if x == zhi: global rightCount rightCount += 1 print('答对啦,你真是个天才!')
for i in range(20): integer() i += 1 print('你一共答对', rightCount, '道题', '共20道题')
经过优化后可以输出正确的题目数量,符合题目要求,运行截图为:
(3)TDD(UnitTest)关键代码:
def test_result_integer(self): print("表达式求值功能单元测试开始:") f1 = input("输入一个四则运算:") zhi = input("输入一个正确的答案:") self.assertEqual(zhi, Test()._test_answer(x = f1)) print("表达式求值功能单元测试结束。", end=' ') print("表达式求值功能测试完成", end=' ')
表达式求值测试成功截图:
git链接:https://e.coding.net/xulijun/danyuanceshi.git