]> granicus.if.org Git - python/commitdiff
Add test for hash commutativity.
authorRaymond Hettinger <python@rcn.com>
Tue, 5 Jul 2005 05:34:43 +0000 (05:34 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 5 Jul 2005 05:34:43 +0000 (05:34 +0000)
Lib/test/test_set.py

index 26e38abb21fa7193dd533ff52ed2e2e9474aa6b2..46e4000e0fdf0fb916223de60dcff849f613e932 100644 (file)
@@ -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))