Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82cb9a2

Browse files
committed
Add test for hash commutativity.
1 parent 2dfc168 commit 82cb9a2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_set.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
import pickle
77
import os
8+
from random import randrange, shuffle
89

910
class PassThru(Exception):
1011
pass
@@ -399,6 +400,15 @@ def test_hash(self):
399400
self.assertEqual(hash(self.thetype('abcdeb')),
400401
hash(self.thetype('ebecda')))
401402

403+
# make sure that all permutations give the same hash value
404+
n = 100
405+
seq = [randrange(n) for i in xrange(n)]
406+
results = set()
407+
for i in xrange(200):
408+
shuffle(seq)
409+
results.add(hash(self.thetype(seq)))
410+
self.assertEqual(len(results), 1)
411+
402412
def test_copy(self):
403413
dup = self.s.copy()
404414
self.assertEqual(id(self.s), id(dup))

0 commit comments

Comments
 (0)