summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_complex.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-05-30 13:18:10 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-05-30 13:18:10 (GMT)
commit4ca7c3c089cf59d14a76f8035b360f4fbf98f9bb (patch)
tree12e13bfbc97606d0c62096d2f1e5ce536cc0d0e5 /Lib/test/test_complex.py
parent4b3035d0b8f10112e2e9f348ded2bd721ad6ddb8 (diff)
downloadcpython-4ca7c3c089cf59d14a76f8035b360f4fbf98f9bb.zip
cpython-4ca7c3c089cf59d14a76f8035b360f4fbf98f9bb.tar.gz
cpython-4ca7c3c089cf59d14a76f8035b360f4fbf98f9bb.tar.bz2
Issue #8748: Fix incorrect results from comparisons between an integer
and a complex instance. Based on a patch by Meador Inge.
Diffstat (limited to 'Lib/test/test_complex.py')
-rw-r--r--Lib/test/test_complex.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index f27593e..69e2715 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -129,7 +129,7 @@ class ComplexTest(unittest.TestCase):
self.assertTrue(a < 2.0j)
def test_richcompare(self):
- self.assertRaises(OverflowError, complex.__eq__, 1+1j, 1L<<10000)
+ self.assertEqual(complex.__eq__(1+1j, 1L<<10000), False)
self.assertEqual(complex.__lt__(1+1j, None), NotImplemented)
self.assertIs(complex.__eq__(1+1j, 1+1j), True)
self.assertIs(complex.__eq__(1+1j, 2+2j), False)
@@ -140,6 +140,23 @@ class ComplexTest(unittest.TestCase):
self.assertRaises(TypeError, complex.__gt__, 1+1j, 2+2j)
self.assertRaises(TypeError, complex.__ge__, 1+1j, 2+2j)
+ def test_richcompare_boundaries(self):
+ def check(n, deltas, is_equal, imag = 0.0):
+ for delta in deltas:
+ i = n + delta
+ z = complex(i, imag)
+ self.assertIs(complex.__eq__(z, i), is_equal(delta))
+ self.assertIs(complex.__ne__(z, i), not is_equal(delta))
+ # For IEEE-754 doubles the following should hold:
+ # x in [2 ** (52 + i), 2 ** (53 + i + 1)] -> x mod 2 ** i == 0
+ # where the interval is representable, of course.
+ for i in range(1, 10):
+ pow = 52 + i
+ mult = 2 ** i
+ check(2 ** pow, range(1, 101), lambda delta: delta % mult == 0)
+ check(2 ** pow, range(1, 101), lambda delta: False, float(i))
+ check(2 ** 53, range(-100, 0), lambda delta: True)
+
def test_mod(self):
self.assertRaises(ZeroDivisionError, (1+1j).__mod__, 0+0j)