示例#1
0
 def test_exceptions(self):
     try:
         math.sqrt(-1.0)
     except ValueError:
         pass
     else:
         self.fail("sqrt(-1) didn't raise ValueError")
示例#2
0
 def testSqrt(self):
     self.assertRaises(TypeError, math.sqrt)
     self.ftest('sqrt(0)', math.sqrt(0), 0)
     self.ftest('sqrt(1)', math.sqrt(1), 1)
     self.ftest('sqrt(4)', math.sqrt(4), 2)
     self.assertEqual(math.sqrt(INF), INF)
     self.assertRaises(ValueError, math.sqrt, NINF)
     self.assertTrue(math.isnan(math.sqrt(NAN)))
示例#3
0
 def testSqrt(self):
     self.assertRaises(TypeError, math.sqrt)
     self.ftest('sqrt(0)', math.sqrt(0), 0)
     self.ftest('sqrt(1)', math.sqrt(1), 1)
     self.ftest('sqrt(4)', math.sqrt(4), 2)
     self.assertEqual(math.sqrt(INF), INF)
     self.assertRaises(ValueError, math.sqrt, NINF)
     self.assertTrue(math.isnan(math.sqrt(NAN)))
示例#4
0
        def test_exceptions(self):
            try:
                x = math.exp(-1000000000)
            except:
                # mathmodule.c is failing to weed out underflows from libm, or
                # we've got an fp format with huge dynamic range
                self.fail("underflowing exp() should not have raised "
                          "an exception")
            if x != 0:
                self.fail("underflowing exp() should have returned 0")

            # If this fails, probably using a strict IEEE-754 conforming libm, and x
            # is +Inf afterwards.  But Python wants overflows detected by default.
            try:
                x = math.exp(1000000000)
            except OverflowError:
                pass
            else:
                self.fail("overflowing exp() didn't trigger OverflowError")

            # If this fails, it could be a puzzle.  One odd possibility is that
            # mathmodule.c's macros are getting confused while comparing
            # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
            # as a result (and so raising OverflowError instead).
            try:
                x = math.sqrt(-1.0)
            except ValueError:
                pass
            else:
                self.fail("sqrt(-1) didn't raise ValueError")
示例#5
0
        def test_exceptions(self):
            try:
                x = math.exp(-1000000000)
            except:
                # mathmodule.c is failing to weed out underflows from libm, or
                # we've got an fp format with huge dynamic range
                self.fail("underflowing exp() should not have raised "
                          "an exception")
            if x != 0:
                self.fail("underflowing exp() should have returned 0")

            # If this fails, probably using a strict IEEE-754 conforming libm, and x
            # is +Inf afterwards.  But Python wants overflows detected by default.
            try:
                x = math.exp(1000000000)
            except OverflowError:
                pass
            else:
                self.fail("overflowing exp() didn't trigger OverflowError")

            # If this fails, it could be a puzzle.  One odd possibility is that
            # mathmodule.c's macros are getting confused while comparing
            # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
            # as a result (and so raising OverflowError instead).
            try:
                x = math.sqrt(-1.0)
            except ValueError:
                pass
            else:
                self.fail("sqrt(-1) didn't raise ValueError")