MCPcopy Index your code
hub / github.com/python/cpython / test_hash_distribution

Method test_hash_distribution

Lib/test/test_hash.py:342–356  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

340class HashDistributionTestCase(unittest.TestCase):
341
342 def test_hash_distribution(self):
343 # check for hash collision
344 base = "abcdefghabcdefg"
345 for i in range(1, len(base)):
346 prefix = base[:i]
347 with self.subTest(prefix=prefix):
348 s15 = set()
349 s255 = set()
350 for c in range(256):
351 h = hash(prefix + chr(c))
352 s15.add(h & 0xf)
353 s255.add(h & 0xff)
354 # SipHash24 distribution depends on key, usually > 60%
355 self.assertGreater(len(s15), 8, prefix)
356 self.assertGreater(len(s255), 128, prefix)
357
358if __name__ == "__main__":
359 unittest.main()

Callers

nothing calls this directly

Calls 4

setFunction · 0.85
assertGreaterMethod · 0.80
subTestMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected