Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_cmath.py @ 66064:fdcaac0e010a
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).
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sun, 07 Nov 2010 14:14:27 +0000 |
| parents | 1cf43c6e6566 |
| children | e8f1ef5fd423 |
line wrap: on
line diff
--- a/Lib/test/test_cmath.py Sun Nov 07 12:57:04 2010 +0000 +++ b/Lib/test/test_cmath.py Sun Nov 07 14:14:27 2010 +0000 @@ -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)
