package hash_test import ( "bytes" "testing" "git.akyoto.dev/go/hash" ) var hashes = map[uint64][]byte{} func TestTinyCollisions(t *testing.T) { for size := 1; size < 8; size++ { tmp := make([]byte, size) index := 0 for i := 0; i < 256; i++ { tmp[index] += 1 h := hash.Bytes(tmp) previous, found := hashes[h] if found && !bytes.Equal(tmp, previous) { t.Fatalf("collision between %v and %v:\nhash %064b", previous, tmp, h) } save := make([]byte, size) copy(save, tmp) hashes[h] = save index = (index + 1) % size } } } func TestZeroedCollisions(t *testing.T) { zero := make([]byte, 8192) for size := 1; size <= len(zero); size++ { tmp := zero[:size] h := hash.Bytes(tmp) previous, found := hashes[h] if found && !bytes.Equal(tmp, previous) { t.Fatalf("collision between %v and %v:\nhash %064b", previous, tmp, h) } hashes[h] = tmp } }