]> granicus.if.org Git - python/commitdiff
Issue 10625: Add tests for negative zeros in complex str and repr.
authorEric Smith <eric@trueblade.com>
Sat, 4 Dec 2010 15:26:13 +0000 (15:26 +0000)
committerEric Smith <eric@trueblade.com>
Sat, 4 Dec 2010 15:26:13 +0000 (15:26 +0000)
Lib/test/test_complex.py

index f9bed06a00fcd42da84c40f65d5bf58495394e1a..6b34ddc0a68a6813110b0790841e6a1409d52c90 100644 (file)
@@ -408,6 +408,22 @@ class ComplexTest(unittest.TestCase):
         self.assertEqual(-6j,complex(repr(-6j)))
         self.assertEqual(6j,complex(repr(6j)))
 
+    @support.requires_IEEE_754
+    def test_negative_zero_repr_str(self):
+        def test(v, expected, test_fn=self.assertEqual):
+            test_fn(repr(v), expected)
+            test_fn(str(v), expected)
+
+        test(complex(0., 1.),   "1j")
+        test(complex(-0., 1.),  "(-0+1j)")
+        test(complex(0., -1.),  "-1j")
+        test(complex(-0., -1.), "(-0-1j)")
+
+        test(complex(0., 0.),   "0j")
+        test(complex(0., -0.),  "-0j")
+        test(complex(-0., 0.),  "(-0+0j)")
+        test(complex(-0., -0.), "(-0-0j)")
+
     def test_neg(self):
         self.assertEqual(-(1+6j), -1-6j)