def test_add(self): print("测试add函数") c1 = Count(10, 20) res1 = c1.add() print("计算实际结果:", res1) #步骤5:使用unittest提供的断言函数 self.assertEqual(res1, 30)
def test_mul2(self): print("测试两个浮点型数据mul") m2 = Count(20.45, 45.67) res2 = m2.mul() print("实际计算结果:", res2) if abs(res2 - 933.9515) < 0.01: res2 = 933.9515 self.assertEqual(res2, 933.9515)
def test_sub2(self): print("测试浮点数sub") s2 = Count(4589.87, 3978.78) res2 = s2.sub() print("实际计算结果:", res2) if abs(res2 - 611.09) < 0.01: res2 = 611.09 self.assertEqual(res2, 611.09)
def test_div2(self): print("测试两个浮点型数据div") d2 = Count(245.45, 34.67) res2 = d2.div() print("实际计算结果:", res2) if abs(res2 - 7.0796) < 0.01: res2 = 7.0796 self.assertEqual(res2, 7.0796)
def test_add(self): c1 = Count("你好", "Python!") res1 = c1.add() if res1 == "你好Python!": print("计算正确!") else: print("计算错误!") print("计算实际结果:", res1)
def test_add2(self): print("测试两个浮点型数据函数") c2 = Count(2167.45, 3978.78) res2 = c2.add() print("计算实际结果:", res2) if abs(res2 - 6146.23) < 0.001: res2 = 6146.23 self.assertEqual(res2, 6146.23)
def test_add(self): c1=Count(10,20) res1=c1.add() if res1==30: print("计算正确!") else: print("计算错误!") print("计算实际结果:",res1)
def test_mul1(self): print("测试两个整数mul") m1 = Count(10, 20) res1 = m1.mul() print("实际计算结果:", res1) self.assertEqual(res1, 200)
#使用普通方法对Count类进行测试 #此文件只对add函数进行浮点数加测试 from calculator.calcu import Count mytest = Count(10.56, 23.43) res2 = mytest.add() if abs(res2 - 33.99) <= 0.001: print("计算正确!") else: print("计算错误!") print("计算实际结果:", res2)
def test_sub1(self): print("测试整数sub") s1 = Count(100, 20) res1 = s1.sub() print("实际计算结果:", res1) self.assertEqual(res1, 80)
def test_div1(self): print("测试两个整数div") d1 = Count(100, 20) res1 = d1.div() print("实际计算结果:", res1) self.assertEqual(res1, 5)
def test_add1(self): print("测试两个整数函数") c1 = Count(10, 20) res1 = c1.add() print("计算实际结果:", res1) self.assertEqual(res1, 30)
def test_add3(self): print("测试两个字符串函数") c3 = Count("你好", "测试") res3 = c3.add() print("实际计算结果:", res3) self.assertEqual(res3, "你好测试")