aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib-python/2.7/test/test_complex.py')
-rw-r--r--lib-python/2.7/test/test_complex.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib-python/2.7/test/test_complex.py b/lib-python/2.7/test/test_complex.py
index c0383b27e6..02b292f4bb 100644
--- a/lib-python/2.7/test/test_complex.py
+++ b/lib-python/2.7/test/test_complex.py
@@ -8,6 +8,13 @@ INF = float("inf")
NAN = float("nan")
# These tests ensure that complex math does the right thing
+# decorator for skipping tests on non-IEEE 754 platforms
+have_getformat = hasattr(float, "__getformat__")
+requires_IEEE_754 = unittest.skipUnless(have_getformat and
+ float.__getformat__("double").startswith("IEEE"),
+ "test requires IEEE 754 doubles")
+
+
class ComplexTest(unittest.TestCase):
def assertAlmostEqual(self, a, b):
@@ -441,6 +448,28 @@ class ComplexTest(unittest.TestCase):
b = 'y %s x' % op
self.assertTrue(type(eval(a)) is type(eval(b)) is xcomplex)
+ @requires_IEEE_754
+ def test_constructor_special_numbers(self):
+ class complex2(complex):
+ pass
+ for x in 0.0, -0.0, INF, -INF, NAN:
+ for y in 0.0, -0.0, INF, -INF, NAN:
+ z = complex(x, y)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+ z = complex2(x, y)
+ self.assertIs(type(z), complex2)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+ z = complex(complex2(x, y))
+ self.assertIs(type(z), complex)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+ z = complex2(complex(x, y))
+ self.assertIs(type(z), complex2)
+ self.assertFloatsAreIdentical(z.real, x)
+ self.assertFloatsAreIdentical(z.imag, y)
+
def test_hash(self):
for x in xrange(-30, 30):
self.assertEqual(hash(x), hash(complex(x, 0)))