mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
Strengthen the test for hash effectiveness
This commit is contained in:
parent
ed54d91ef5
commit
6e70accaff
1 changed files with 4 additions and 4 deletions
|
|
@ -389,12 +389,12 @@ class TestFrozenSet(TestJointOps):
|
||||||
|
|
||||||
def test_hash_effectiveness(self):
|
def test_hash_effectiveness(self):
|
||||||
n = 13
|
n = 13
|
||||||
rng = range(n)
|
|
||||||
hashvalues = set()
|
hashvalues = set()
|
||||||
|
addhashvalue = hashvalues.add
|
||||||
|
elemmasks = [(i+1, 1<<i) for i in range(n)]
|
||||||
for i in xrange(2**n):
|
for i in xrange(2**n):
|
||||||
combination = [j for j in rng if (1<<j)&i]
|
addhashvalue(hash(frozenset([e for e, m in elemmasks if m&i])))
|
||||||
hashvalues.add(hash(self.thetype(combination)))
|
self.assertEqual(len(hashvalues), 2**n)
|
||||||
self.assert_(len(hashvalues) >= 2**(n-2))
|
|
||||||
|
|
||||||
class FrozenSetSubclass(frozenset):
|
class FrozenSetSubclass(frozenset):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue