[Python-checkins] python/dist/src/Lib/test test_set.py,1.8,1.9

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Dec 30 21:01:39 EST 2003


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv16030

Modified Files:
	test_set.py 
Log Message:
Strengthen the test for hash effectiveness

Index: test_set.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_set.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** test_set.py	17 Dec 2003 20:43:32 -0000	1.8
--- test_set.py	31 Dec 2003 02:01:33 -0000	1.9
***************
*** 390,399 ****
      def test_hash_effectiveness(self):
          n = 13
-         rng = range(n)
          hashvalues = set()
          for i in xrange(2**n):
!             combination = [j for j in rng if (1<<j)&i]
!             hashvalues.add(hash(self.thetype(combination)))
!         self.assert_(len(hashvalues) >= 2**(n-2))
  
  class FrozenSetSubclass(frozenset):
--- 390,399 ----
      def test_hash_effectiveness(self):
          n = 13
          hashvalues = set()
+         addhashvalue = hashvalues.add
+         elemmasks = [(i+1, 1<<i) for i in range(n)]
          for i in xrange(2**n):
!             addhashvalue(hash(frozenset([e for e, m in elemmasks if m&i])))
!         self.assertEqual(len(hashvalues), 2**n)
  
  class FrozenSetSubclass(frozenset):





More information about the Python-checkins mailing list