[Python-checkins] python/dist/src/Lib/test test_set.py,1.17,1.18

rhettinger@users.sourceforge.net rhettinger at users.sourceforge.net
Tue Jul 5 07:34:45 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22257

Modified Files:
	test_set.py 
Log Message:
Add test for hash commutativity.

Index: test_set.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_set.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- test_set.py	18 Jun 2005 21:00:26 -0000	1.17
+++ test_set.py	5 Jul 2005 05:34:43 -0000	1.18
@@ -5,6 +5,7 @@
 import copy
 import pickle
 import os
+from random import randrange, shuffle
 
 class PassThru(Exception):
     pass
@@ -399,6 +400,15 @@
         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))



More information about the Python-checkins mailing list