コード例 #1
0
 def test_neg_zero(self):
     """
     测试前者负数、后者为0相除
     :return:
     """
     actual_result = MathCalculate(-1, 0).divide()
     expect_result = ZeroDivisionError
     msg = '测试前者负数、后者为0相除'
     fail_msg = '前者负数、后者为0相除测试失败'
     try:
         self.assertIsInstance(actual_result, expect_result, msg=fail_msg)
     except AssertionError as e:
         print('具体异常为:{}'.format(e))
         self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'fail', e))
         raise e
     else:
         self.file.write('{},执行结果:{}\n'.format(msg, 'pass'))
コード例 #2
0
    def test_neg_pos(self):
        """
        测试前者负数、后者正数相减
        :return:
        """
        actual_result = MathCalculate(-1, 2).minus()
        expect_result = -3
        msg = '前者负数、后者正数相减测试'
        fail_msg = '前者负数、后者正数相减测试失败'

        try:
            self.assertEqual(actual_result, expect_result, msg=fail_msg)
        except AssertionError as e:
            self.file.write('{},执行结果为:{},具体异常为:{}\n'.format(msg, 'Fail', e))
            raise e
        else:
            self.file.write('{},执行结果为:{}\n'.format(msg, 'Pass'))
コード例 #3
0
 def test_neg_pos(self):
     """
     测试前者负数、后者正数相除
     :return:
     """
     actual_result = MathCalculate(-1, 2).divide()
     expect_result = -0.5
     msg = '测试前者负数、后者正数相除'
     fail_msg = '前者负数、后者正数相除测试失败'
     try:
         self.assertEqual(actual_result, expect_result, msg=fail_msg)
     except AssertionError as e:
         print('具体异常为:{}'.format(e))
         self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'fail', e))
         raise e
     else:
         self.file.write('{},执行结果:{}\n'.format(msg, 'pass'))
コード例 #4
0
    def test_zero_zero(self):
        """
        测试两个0相减
        :return:
        """
        actual_result = MathCalculate(0, 0).minus()
        expect_result = 0
        msg = '两个0相减测试'
        fail_msg = '两个0相减测试失败'

        try:
            self.assertEqual(actual_result, expect_result, msg=fail_msg)
        except AssertionError as e:
            self.file.write('{},执行结果为:{},具体异常为:{}\n'.format(msg, 'Fail', e))
            raise e
        else:
            self.file.write('{},执行结果为:{}\n'.format(msg, 'Pass'))