[Python-checkins] r86299 - in python/branches/py3k/Lib/test: cmath_testcases.txt test_cmath.py test_math.py

victor.stinner python-checkins at python.org
Sun Nov 7 15:14:28 CET 2010


Author: victor.stinner
Date: Sun Nov 7 15:14:27 2010
New Revision: 86299
Log:
Issue #10337: skip tests of tanh() sign in test_math and test_cmath if tanh()
doesn't preserve the zero sign (if TANH_PRESERVES_ZERO_SIGN define is 0).
Modified:
 python/branches/py3k/Lib/test/cmath_testcases.txt
 python/branches/py3k/Lib/test/test_cmath.py
 python/branches/py3k/Lib/test/test_math.py
Modified: python/branches/py3k/Lib/test/cmath_testcases.txt
==============================================================================
--- python/branches/py3k/Lib/test/cmath_testcases.txt	(original)
+++ python/branches/py3k/Lib/test/cmath_testcases.txt	Sun Nov 7 15:14:27 2010
@@ -1858,11 +1858,14 @@
 -- tanh: Hyperbolic Tangent --
 ------------------------------
 
--- zeros
-tanh0000 tanh 0.0 0.0 -> 0.0 0.0
-tanh0001 tanh 0.0 -0.0 -> 0.0 -0.0
-tanh0002 tanh -0.0 0.0 -> -0.0 0.0
-tanh0003 tanh -0.0 -0.0 -> -0.0 -0.0
+-- Disabled test: replaced by test_math.testTanhSign()
+-- and test_cmath.testTanhSign()
+
+-- -- zeros
+-- tanh0000 tanh 0.0 0.0 -> 0.0 0.0
+-- tanh0001 tanh 0.0 -0.0 -> 0.0 -0.0
+-- tanh0002 tanh -0.0 0.0 -> -0.0 0.0
+-- tanh0003 tanh -0.0 -0.0 -> -0.0 -0.0
 
 -- random inputs
 tanh0004 tanh -21.200500450664993 -1.6970729480342996 -> -1.0 1.9241352344849399e-19
Modified: python/branches/py3k/Lib/test/test_cmath.py
==============================================================================
--- python/branches/py3k/Lib/test/test_cmath.py	(original)
+++ python/branches/py3k/Lib/test/test_cmath.py	Sun Nov 7 15:14:27 2010
@@ -1,8 +1,9 @@
 from test.support import run_unittest
-from test.test_math import parse_testfile, test_file
+from test.test_math import parse_testfile, test_file, requires_IEEE_754
 import unittest
 import cmath, math
 from cmath import phase, polar, rect, pi
+import sysconfig
 
 INF = float('inf')
 NAN = float('nan')
@@ -61,6 +62,12 @@
 def tearDown(self):
 self.test_values.close()
 
+ def assertComplexIdentical(self, a, b):
+ """Fail if two complex numbers value or sign is different."""
+ self.assertEqual(a, b)
+ self.assertEqual(math.copysign(1., a.real), math.copysign(1., b.real))
+ self.assertEqual(math.copysign(1., a.imag), math.copysign(1., b.imag))
+
 def rAssertAlmostEqual(self, a, b, rel_err = 2e-15, abs_err = 5e-323,
 msg=None):
 """Fail if the two floating-point numbers are not almost equal.
@@ -473,6 +480,15 @@
 self.assertTrue(cmath.isinf(complex(NAN, INF)))
 self.assertTrue(cmath.isinf(complex(INF, NAN)))
 
+ @requires_IEEE_754
+ @unittest.skipIf(sysconfig.get_config_var('TANH_PRESERVES_ZERO_SIGN') == 0,
+ "system tanh() function doesn't copy the sign")
+ def testTanhSign(self):
+ self.assertComplexIdentical(cmath.tanh(complex(0., .0j)), complex(0., .0j))
+ self.assertComplexIdentical(cmath.tanh(complex(0., -.0j)), complex(0., -.0j))
+ self.assertComplexIdentical(cmath.tanh(complex(-0., .0j)), complex(-0., .0j))
+ self.assertComplexIdentical(cmath.tanh(complex(-0., -.0j)), complex(-0., -.0j))
+
 
 def test_main():
 run_unittest(CMathTests)
Modified: python/branches/py3k/Lib/test/test_math.py
==============================================================================
--- python/branches/py3k/Lib/test/test_math.py	(original)
+++ python/branches/py3k/Lib/test/test_math.py	Sun Nov 7 15:14:27 2010
@@ -8,6 +8,7 @@
 import sys
 import random
 import struct
+import sysconfig
 
 eps = 1E-05
 NAN = float('nan')
@@ -891,11 +892,15 @@
 self.ftest('tanh(inf)', math.tanh(INF), 1)
 self.ftest('tanh(-inf)', math.tanh(NINF), -1)
 self.assertTrue(math.isnan(math.tanh(NAN)))
+
+ @requires_IEEE_754
+ @unittest.skipIf(sysconfig.get_config_var('TANH_PRESERVES_ZERO_SIGN') == 0,
+ "system tanh() function doesn't copy the sign")
+ def testTanhSign(self):
 # check that tanh(-0.) == -0. on IEEE 754 systems
- if float.__getformat__("double").startswith("IEEE"):
- self.assertEqual(math.tanh(-0.), -0.)
- self.assertEqual(math.copysign(1., math.tanh(-0.)),
- math.copysign(1., -0.))
+ self.assertEqual(math.tanh(-0.), -0.)
+ self.assertEqual(math.copysign(1., math.tanh(-0.)),
+ math.copysign(1., -0.))
 
 def test_trunc(self):
 self.assertEqual(math.trunc(1), 1)
@@ -1008,8 +1013,7 @@
 self.fail(message)
 self.ftest("%s:%s(%r)" % (id, fn, ar), result, er)
 
- @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
- "test requires IEEE 754 doubles")
+ @requires_IEEE_754
 def test_mtestfile(self):
 ALLOWED_ERROR = 20 # permitted error, in ulps
 fail_fmt = "{}:{}({!r}): expected {!r}, got {!r}"


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /