(self)
| 340 | class 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 | |
| 358 | if __name__ == "__main__": |
| 359 | unittest.main() |
nothing calls this directly
no test coverage detected