summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2010-12-04 13:27:34 (GMT)
committerEric Smith <eric@trueblade.com>2010-12-04 13:27:34 (GMT)
commit70099a1555d0f0bbea3553e59746d505c510fafe (patch)
treeda521e85070db2ae9fa8cd20be330a632016bffd /Lib/test
parent7b1bee47ae553af0a81b9f76bd5d71f07b755a90 (diff)
downloadcpython-70099a1555d0f0bbea3553e59746d505c510fafe.zip
cpython-70099a1555d0f0bbea3553e59746d505c510fafe.tar.gz
cpython-70099a1555d0f0bbea3553e59746d505c510fafe.tar.bz2
Removed static function complex_format, moved it into complex_repr. Modified tests to check both str and repr, which are the same for complex.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_complex.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 2352ef1..548726b 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -381,29 +381,33 @@ class ComplexTest(unittest.TestCase):
for num in nums:
self.assertAlmostEqual((num.real**2 + num.imag**2) ** 0.5, abs(num))
- def test_repr(self):
- self.assertEqual(repr(1+6j), '(1+6j)')
- self.assertEqual(repr(1-6j), '(1-6j)')
+ def test_repr_str(self):
+ def test(v, expected, test_fn=self.assertEqual):
+ test_fn(repr(v), expected)
+ test_fn(str(v), expected)
- self.assertNotEqual(repr(-(1+0j)), '(-1+-0j)')
+ test(1+6j, '(1+6j)')
+ test(1-6j, '(1-6j)')
+
+ test(-(1+0j), '(-1+-0j)', test_fn=self.assertNotEqual)
+
+ test(complex(1., INF), "(1+infj)")
+ test(complex(1., -INF), "(1-infj)")
+ test(complex(INF, 1), "(inf+1j)")
+ test(complex(-INF, INF), "(-inf+infj)")
+ test(complex(NAN, 1), "(nan+1j)")
+ test(complex(1, NAN), "(1+nanj)")
+ test(complex(NAN, NAN), "(nan+nanj)")
+
+ test(complex(0, INF), "infj")
+ test(complex(0, -INF), "-infj")
+ test(complex(0, NAN), "nanj")
self.assertEqual(1-6j,complex(repr(1-6j)))
self.assertEqual(1+6j,complex(repr(1+6j)))
self.assertEqual(-6j,complex(repr(-6j)))
self.assertEqual(6j,complex(repr(6j)))
- self.assertEqual(repr(complex(1., INF)), "(1+infj)")
- self.assertEqual(repr(complex(1., -INF)), "(1-infj)")
- self.assertEqual(repr(complex(INF, 1)), "(inf+1j)")
- self.assertEqual(repr(complex(-INF, INF)), "(-inf+infj)")
- self.assertEqual(repr(complex(NAN, 1)), "(nan+1j)")
- self.assertEqual(repr(complex(1, NAN)), "(1+nanj)")
- self.assertEqual(repr(complex(NAN, NAN)), "(nan+nanj)")
-
- self.assertEqual(repr(complex(0, INF)), "infj")
- self.assertEqual(repr(complex(0, -INF)), "-infj")
- self.assertEqual(repr(complex(0, NAN)), "nanj")
-
def test_neg(self):
self.assertEqual(-(1+6j), -1-6j)