summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-07-05 05:34:43 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-07-05 05:34:43 (GMT)
commit82cb9a235de45074d578d46bbf6680e726b13efd (patch)
tree564cc47075abcdfdd67ebdd1e75ee5b09df78bf5 /Lib
parent2dfc168bc3b92a0087a3a619b7f793240528936a (diff)
downloadcpython-82cb9a235de45074d578d46bbf6680e726b13efd.zip
cpython-82cb9a235de45074d578d46bbf6680e726b13efd.tar.gz
cpython-82cb9a235de45074d578d46bbf6680e726b13efd.tar.bz2
Add test for hash commutativity.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_set.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 26e38ab..46e4000 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -5,6 +5,7 @@ import operator
import copy
import pickle
import os
+from random import randrange, shuffle
class PassThru(Exception):
pass
@@ -399,6 +400,15 @@ class TestFrozenSet(TestJointOps):
self.assertEqual(hash(self.thetype('abcdeb')),
hash(self.thetype('ebecda')))
+ # make sure that all permutations give the same hash value
+ n = 100
+ seq = [randrange(n) for i in xrange(n)]
+ results = set()
+ for i in xrange(200):
+ shuffle(seq)
+ results.add(hash(self.thetype(seq)))
+ self.assertEqual(len(results), 1)
+
def test_copy(self):
dup = self.s.copy()
self.assertEqual(id(self.s), id(dup))