class TestCalculator(unittest.TestCase): def setUp(self): self.cal = Calculator(8,4) def tearDown(self): pass def test_add(self): result = self.cal.add() self.assertEqual(result,12) def test_sub(self): result = self.cal.sub() self.assertEqual(result,4) def test_mul(self): result = self.cal.mul() self.assertEqual(result,32) def test_div(self): result = self.cal.div() self.assertEqual(result,1)
class CountTest(unittest.TestCase): """docstring for CountTest""" # 初始化计算器 def setUp(self): self.cal = Calculator(8, 4) def tearDown(self): pass def test_add(self): result = self.cal.add() self.assertEqual(result, 12) def test_sub(self): result = self.cal.sub() self.assertEqual(result, 4) def test_mul(self): result = self.cal.mul() self.assertEqual(result, 32) def test_div(self): result = self.cal.div() self.assertEqual(result, 2)
def test_add(self): try: c = Calculator(2,4) result = c.add() assert(result == 6),'Integer addition result error!' except AssertionError as msg: print(msg) else: print('test pass!')
def setUp(self): self.cal = Calculator(8, 4)
def test_add(self): c = Calculator(2, 4) result = c.add() self.assertEqual(result, 6)
def test_div(self): c = Calculator(8, 3) result = c.div() self.assertNotEqual(result, 999)
def test_mul(self): c = Calculator(2, 4) result = c.mul() self.assertEqual(result, 8)
def test_sub(self): c = Calculator(8, 3) result = c.sub() self.assertEqual(result, 5)