Issue #20162: test_hash_distribution() uses subTest() to mention the prefix in

the error message.
This commit is contained in:
Victor Stinner 2014-01-07 14:40:51 +01:00
parent 1500d49c22
commit cc26310e2e

View file

@ -330,15 +330,16 @@ class HashDistributionTestCase(unittest.TestCase):
base = "abcdefghabcdefg" base = "abcdefghabcdefg"
for i in range(1, len(base)): for i in range(1, len(base)):
prefix = base[:i] prefix = base[:i]
s15 = set() with self.subTest(prefix=prefix):
s255 = set() s15 = set()
for c in range(256): s255 = set()
h = hash(prefix + chr(c)) for c in range(256):
s15.add(h & 0xf) h = hash(prefix + chr(c))
s255.add(h & 0xff) s15.add(h & 0xf)
# SipHash24 distribution depends on key, usually > 60% s255.add(h & 0xff)
self.assertGreater(len(s15), 8, prefix) # SipHash24 distribution depends on key, usually > 60%
self.assertGreater(len(s255), 128, prefix) self.assertGreater(len(s15), 8, prefix)
self.assertGreater(len(s255), 128, prefix)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()