summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_complex.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-04-25 10:11:40 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-04-25 10:11:40 (GMT)
commitde8a710849827f8e55e73d59bca41d2594a9db99 (patch)
tree9bb8a084734eb0be3b73e858522501477101b69f /Lib/test/test_complex.py
parent193152c17479732f2fd9bd5d14ae4db119727bec (diff)
downloadcpython-de8a710849827f8e55e73d59bca41d2594a9db99.zip
cpython-de8a710849827f8e55e73d59bca41d2594a9db99.tar.gz
cpython-de8a710849827f8e55e73d59bca41d2594a9db99.tar.bz2
Merged revisions 71869 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r71869 | mark.dickinson | 2009-04-25 10:47:00 +0100 (Sat, 25 Apr 2009) | 2 lines Fix typo in complex parsing code; expand tests. ........
Diffstat (limited to 'Lib/test/test_complex.py')
-rw-r--r--Lib/test/test_complex.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index d029d86..87e2584 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -410,10 +410,11 @@ class ComplexTest(unittest.TestCase):
@unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
"test requires IEEE 754 doubles")
def test_repr_roundtrip(self):
- # complex(repr(z)) should recover z exactly, even for complex numbers
- # involving an infinity, nan, or negative zero
- vals = [0.0, 1e-200, 0.0123, 3.1415, 1e50, INF, NAN]
+ vals = [0.0, 1e-500, 1e-315, 1e-200, 0.0123, 3.1415, 1e50, INF, NAN]
vals += [-v for v in vals]
+
+ # complex(repr(z)) should recover z exactly, even for complex
+ # numbers involving an infinity, nan, or negative zero
for x in vals:
for y in vals:
z = complex(x, y)
@@ -421,6 +422,21 @@ class ComplexTest(unittest.TestCase):
self.assertFloatsAreIdentical(z.real, roundtrip.real)
self.assertFloatsAreIdentical(z.imag, roundtrip.imag)
+ # if we predefine some constants, then eval(repr(z)) should
+ # also work, except that it might change the sign of zeros
+ inf, nan = float('inf'), float('nan')
+ infj, nanj = complex(0.0, inf), complex(0.0, nan)
+ for x in vals:
+ for y in vals:
+ z = complex(x, y)
+ roundtrip = eval(repr(z))
+ # adding 0.0 has no effect beside changing -0.0 to 0.0
+ self.assertFloatsAreIdentical(0.0 + z.real,
+ 0.0 + roundtrip.real)
+ self.assertFloatsAreIdentical(0.0 + z.imag,
+ 0.0 + roundtrip.imag)
+
+
def test_main():
support.run_unittest(ComplexTest)