import unittest from parameterized import parameterized def cacl(a, b): return a+b class MyCacl(unittest.TestCase): @parameterized.expand( [ (1, 2, 3), # 整数相加 (1.5, 2, 3.5), # 小数加整数 (1.5, 2.6, 4.1), # 小数相加 (-1, 2, 1), # 负数加整数 (-1,1.5,0.5), # 负数加小数 (-1,-2,-3), # 负数相加 (0,1,1), # 0加整数 (0,0.5,0.5), # 0加小数 (0,-1,-1), # 0加负数 (1,"",1), # 整数加空 (1,"a",1), # 整数加字母 (1,"$",1) # 整数加特殊字符 ] ) def test_cacl(self, a, b, c): res = cacl(a, b) self.assertEqual(res, c) if __name__ == '__main__': unittest.main()