mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Add test for hash commutativity.
This commit is contained in:
parent
2dfc168bc3
commit
82cb9a235d
1 changed files with 10 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import operator
|
||||||
import copy
|
import copy
|
||||||
import pickle
|
import pickle
|
||||||
import os
|
import os
|
||||||
|
from random import randrange, shuffle
|
||||||
|
|
||||||
class PassThru(Exception):
|
class PassThru(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
@ -399,6 +400,15 @@ class TestFrozenSet(TestJointOps):
|
||||||
self.assertEqual(hash(self.thetype('abcdeb')),
|
self.assertEqual(hash(self.thetype('abcdeb')),
|
||||||
hash(self.thetype('ebecda')))
|
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):
|
def test_copy(self):
|
||||||
dup = self.s.copy()
|
dup = self.s.copy()
|
||||||
self.assertEqual(id(self.s), id(dup))
|
self.assertEqual(id(self.s), id(dup))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue