作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2146
1、测试随机生成
import unittestfrom f4_1 import createOperatorclass testCreateOperator(unittest.TestCase): def test_CreateOperator(self): print("单元测试开始:") operator = ["+", "-", "*", "/"] self.assertIn(createOperator(self),operator)if __name__ == '__main__': unittest.main()
效果
二、测试生成四则运算试题
import unittestfrom f4_1 import mainclass testmain(unittest.TestCase): def test_main(self): print("单元测试开始:") self.assertIn(main(),20)if __name__ == '__main__': unittest.main()