summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_richcmp.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-05-08 04:38:29 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-05-08 04:38:29 (GMT)
commite63415ead8aeaaf072142c177a71b5a3e3327187 (patch)
treea139373bd30a2a90d511e6711387c5deda1699bc /Lib/test/test_richcmp.py
parent66a7e57c7e8aab2bf187991aa5c2aa5e21b44c2c (diff)
downloadcpython-e63415ead8aeaaf072142c177a71b5a3e3327187.zip
cpython-e63415ead8aeaaf072142c177a71b5a3e3327187.tar.gz
cpython-e63415ead8aeaaf072142c177a71b5a3e3327187.tar.bz2
SF patch #421922: Implement rich comparison for dicts.
d1 == d2 and d1 != d2 now work even if the keys and values in d1 and d2 don't support comparisons other than ==, and testing dicts for equality is faster now (especially when inequality obtains).
Diffstat (limited to 'Lib/test/test_richcmp.py')
-rw-r--r--Lib/test/test_richcmp.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py
index 7884c7e..4e7d459 100644
--- a/Lib/test/test_richcmp.py
+++ b/Lib/test/test_richcmp.py
@@ -221,6 +221,33 @@ def recursion():
check('not a==b')
if verbose: print "recursion tests ok"
+def dicts():
+ # Verify that __eq__ and __ne__ work for dicts even if the keys and
+ # values don't support anything other than __eq__ and __ne__. Complex
+ # numbers are a fine example of that.
+ import random
+ imag1a = {}
+ for i in range(50):
+ imag1a[random.randrange(100)*1j] = random.randrange(100)*1j
+ items = imag1a.items()
+ random.shuffle(items)
+ imag1b = {}
+ for k, v in items:
+ imag1b[k] = v
+ imag2 = imag1b.copy()
+ imag2[k] = v + 1.0
+ verify(imag1a == imag1a, "imag1a == imag1a should have worked")
+ verify(imag1a == imag1b, "imag1a == imag1b should have worked")
+ verify(imag2 == imag2, "imag2 == imag2 should have worked")
+ verify(imag1a != imag2, "imag1a != imag2 should have worked")
+ for op in "<", "<=", ">", ">=":
+ try:
+ eval("imag1a %s imag2" % op)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed("expected TypeError from imag1a %s imag2" % op)
+
def main():
basic()
tabulate()
@@ -229,5 +256,6 @@ def main():
testvector()
misbehavin()
recursion()
+ dicts()
main()