diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-04-19 18:51:48 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-04-19 18:51:48 (GMT) |
commit | e941d97d123377c9e2c9f4cfec2e9827df0467c4 (patch) | |
tree | bff8904bbe7b9ea8d4c6b09fc6a84cb7e6ab1842 /Lib/test/test_math.py | |
parent | c7bef374029a69719d8ba7f7d5ed9b056b2d0457 (diff) | |
download | cpython-e941d97d123377c9e2c9f4cfec2e9827df0467c4.zip cpython-e941d97d123377c9e2c9f4cfec2e9827df0467c4.tar.gz cpython-e941d97d123377c9e2c9f4cfec2e9827df0467c4.tar.bz2 |
Additional tests for math.pow, and extra special-case
handling code in math.pow, in the hope of making all
tests pass on the alpha Tru64 buildbot.
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r-- | Lib/test/test_math.py | 134 |
1 files changed, 124 insertions, 10 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index faf11e6..0d35130 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -102,7 +102,7 @@ class MathTests(unittest.TestCase): self.ftest('atan(0)', math.atan(0), 0) self.ftest('atan(1)', math.atan(1), math.pi/4) self.ftest('atan(inf)', math.atan(INF), math.pi/2) - self.ftest('atan(-inf)', math.atan(-INF), -math.pi/2) + self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2) self.assert_(math.isnan(math.atan(NAN))) def testAtanh(self): @@ -387,14 +387,128 @@ class MathTests(unittest.TestCase): self.assert_(math.isnan(math.pow(2, NAN))) self.assert_(math.isnan(math.pow(0, NAN))) self.assertEqual(math.pow(1, NAN), 1) - self.assertEqual(1**NAN, 1) - self.assertEqual(1**INF, 1) - self.assertEqual(1**NINF, 1) - self.assertEqual(1**0, 1) - self.assertEqual(1.**NAN, 1) - self.assertEqual(1.**INF, 1) - self.assertEqual(1.**NINF, 1) - self.assertEqual(1.**0, 1) + + # pow(0., x) + self.assertEqual(math.pow(0., INF), 0.) + self.assertEqual(math.pow(0., 3.), 0.) + self.assertEqual(math.pow(0., 2.3), 0.) + self.assertEqual(math.pow(0., 2.), 0.) + self.assertEqual(math.pow(0., 0.), 1.) + self.assertEqual(math.pow(0., -0.), 1.) + self.assertRaises(ValueError, math.pow, 0., -2.) + self.assertRaises(ValueError, math.pow, 0., -2.3) + self.assertRaises(ValueError, math.pow, 0., -3.) + self.assertRaises(ValueError, math.pow, 0., NINF) + self.assert_(math.isnan(math.pow(0., NAN))) + + # pow(INF, x) + self.assertEqual(math.pow(INF, INF), INF) + self.assertEqual(math.pow(INF, 3.), INF) + self.assertEqual(math.pow(INF, 2.3), INF) + self.assertEqual(math.pow(INF, 2.), INF) + self.assertEqual(math.pow(INF, 0.), 1.) + self.assertEqual(math.pow(INF, -0.), 1.) + self.assertEqual(math.pow(INF, -2.), 0.) + self.assertEqual(math.pow(INF, -2.3), 0.) + self.assertEqual(math.pow(INF, -3.), 0.) + self.assertEqual(math.pow(INF, NINF), 0.) + self.assert_(math.isnan(math.pow(INF, NAN))) + + # pow(-0., x) + self.assertEqual(math.pow(-0., INF), 0.) + self.assertEqual(math.pow(-0., 3.), -0.) + self.assertEqual(math.pow(-0., 2.3), 0.) + self.assertEqual(math.pow(-0., 2.), 0.) + self.assertEqual(math.pow(-0., 0.), 1.) + self.assertEqual(math.pow(-0., -0.), 1.) + self.assertRaises(ValueError, math.pow, -0., -2.) + self.assertRaises(ValueError, math.pow, -0., -2.3) + self.assertRaises(ValueError, math.pow, -0., -3.) + self.assertRaises(ValueError, math.pow, -0., NINF) + self.assert_(math.isnan(math.pow(-0., NAN))) + + # pow(NINF, x) + self.assertEqual(math.pow(NINF, INF), INF) + self.assertEqual(math.pow(NINF, 3.), NINF) + self.assertEqual(math.pow(NINF, 2.3), INF) + self.assertEqual(math.pow(NINF, 2.), INF) + self.assertEqual(math.pow(NINF, 0.), 1.) + self.assertEqual(math.pow(NINF, -0.), 1.) + self.assertEqual(math.pow(NINF, -2.), 0.) + self.assertEqual(math.pow(NINF, -2.3), 0.) + self.assertEqual(math.pow(NINF, -3.), -0.) + self.assertEqual(math.pow(NINF, NINF), 0.) + self.assert_(math.isnan(math.pow(NINF, NAN))) + + # pow(-1, x) + self.assertEqual(math.pow(-1., INF), 1.) + self.assertEqual(math.pow(-1., 3.), -1.) + self.assertRaises(ValueError, math.pow, -1., 2.3) + self.assertEqual(math.pow(-1., 2.), 1.) + self.assertEqual(math.pow(-1., 0.), 1.) + self.assertEqual(math.pow(-1., -0.), 1.) + self.assertEqual(math.pow(-1., -2.), 1.) + self.assertRaises(ValueError, math.pow, -1., -2.3) + self.assertEqual(math.pow(-1., -3.), -1.) + self.assertEqual(math.pow(-1., NINF), 1.) + self.assert_(math.isnan(math.pow(-1., NAN))) + + # pow(1, x) + self.assertEqual(math.pow(1., INF), 1.) + self.assertEqual(math.pow(1., 3.), 1.) + self.assertEqual(math.pow(1., 2.3), 1.) + self.assertEqual(math.pow(1., 2.), 1.) + self.assertEqual(math.pow(1., 0.), 1.) + self.assertEqual(math.pow(1., -0.), 1.) + self.assertEqual(math.pow(1., -2.), 1.) + self.assertEqual(math.pow(1., -2.3), 1.) + self.assertEqual(math.pow(1., -3.), 1.) + self.assertEqual(math.pow(1., NINF), 1.) + self.assertEqual(math.pow(1., NAN), 1.) + + # pow(x, 0) should be 1 for any x + self.assertEqual(math.pow(2.3, 0.), 1.) + self.assertEqual(math.pow(-2.3, 0.), 1.) + self.assertEqual(math.pow(NAN, 0.), 1.) + self.assertEqual(math.pow(2.3, -0.), 1.) + self.assertEqual(math.pow(-2.3, -0.), 1.) + self.assertEqual(math.pow(NAN, -0.), 1.) + + # pow(x, y) is invalid if x is negative and y is not integral + self.assertRaises(ValueError, math.pow, -1., 2.3) + self.assertRaises(ValueError, math.pow, -15., -3.1) + + # pow(x, NINF) + self.assertEqual(math.pow(1.9, NINF), 0.) + self.assertEqual(math.pow(1.1, NINF), 0.) + self.assertEqual(math.pow(0.9, NINF), INF) + self.assertEqual(math.pow(0.1, NINF), INF) + self.assertEqual(math.pow(-0.1, NINF), INF) + self.assertEqual(math.pow(-0.9, NINF), INF) + self.assertEqual(math.pow(-1.1, NINF), 0.) + self.assertEqual(math.pow(-1.9, NINF), 0.) + + # pow(x, INF) + self.assertEqual(math.pow(1.9, INF), INF) + self.assertEqual(math.pow(1.1, INF), INF) + self.assertEqual(math.pow(0.9, INF), 0.) + self.assertEqual(math.pow(0.1, INF), 0.) + self.assertEqual(math.pow(-0.1, INF), 0.) + self.assertEqual(math.pow(-0.9, INF), 0.) + self.assertEqual(math.pow(-1.1, INF), INF) + self.assertEqual(math.pow(-1.9, INF), INF) + + # the following tests have been commented out since they don't + # really belong here: the implementation of ** for floats is + # independent of the implemention of math.pow + #self.assertEqual(1**NAN, 1) + #self.assertEqual(1**INF, 1) + #self.assertEqual(1**NINF, 1) + #self.assertEqual(1**0, 1) + #self.assertEqual(1.**NAN, 1) + #self.assertEqual(1.**INF, 1) + #self.assertEqual(1.**NINF, 1) + #self.assertEqual(1.**0, 1) def testRadians(self): self.assertRaises(TypeError, math.radians) @@ -421,7 +535,7 @@ class MathTests(unittest.TestCase): self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1) self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0) self.assertEquals(math.sinh(INF), INF) - self.assertEquals(math.sinh(-INF), -INF) + self.assertEquals(math.sinh(NINF), NINF) self.assert_(math.isnan(math.sinh(NAN))) def testSqrt(self): |