| func TestMishmash(t *testing.T) { | func TestMishmash(t *testing.T) { | ||||
| want := "9d923077" | want := "9d923077" | ||||
| if got := fmt.Sprintf("%08x", Mishmash([]byte("google.com"))); want != got { | |||||
| if got := fmt.Sprintf("%08x", Mishmash("google.com")); want != got { | |||||
| t.Error("Parse() = got", got, "want", want) | t.Error("Parse() = got", got, "want", want) | ||||
| } else { | } else { | ||||
| fmt.Println("TestMishmash Passed") | fmt.Println("TestMishmash Passed") | ||||
| func TestSecondHash(t *testing.T) { | func TestSecondHash(t *testing.T) { | ||||
| want := "3fbdb348" | want := "3fbdb348" | ||||
| hash := Mishmash([]byte("google.com")) | |||||
| if got := fmt.Sprintf("%08x", Mishmash([]byte("google.com"), uint64(hash))); want != got { | |||||
| hash := Mishmash("google.com") | |||||
| if got := fmt.Sprintf("%08x", Mishmash("google.com", uint64(hash))); want != got { | |||||
| t.Error("Parse() = got", got, "want", want) | t.Error("Parse() = got", got, "want", want) | ||||
| } else { | } else { | ||||
| fmt.Println("TestSecondHash Passed") | fmt.Println("TestSecondHash Passed") | ||||
| func TestSeedOne(t *testing.T) { | func TestSeedOne(t *testing.T) { | ||||
| want := "cebf5691" | want := "cebf5691" | ||||
| if got := fmt.Sprintf("%08x", Mishmash([]byte("google.com"), uint64(1))); want != got { | |||||
| if got := fmt.Sprintf("%08x", Mishmash("google.com", uint64(1))); want != got { | |||||
| t.Error("Parse() = got", got, "want", want) | t.Error("Parse() = got", got, "want", want) | ||||
| } else { | } else { | ||||
| fmt.Println("TestSeedOne Passed") | fmt.Println("TestSeedOne Passed") | ||||
| func TestEngineAndAccumulator(t *testing.T) { | func TestEngineAndAccumulator(t *testing.T) { | ||||
| want := "65df1304" | want := "65df1304" | ||||
| test := []byte("google.com") | |||||
| test := "google.com" | |||||
| accum := Engine(test, len(test), 0) | accum := Engine(test, len(test), 0) | ||||
| if got := fmt.Sprintf("%08x", Mishmash(test, accum)); want != got { | if got := fmt.Sprintf("%08x", Mishmash(test, accum)); want != got { | ||||
| t.Error("Parse() = got", got, "want", want) | t.Error("Parse() = got", got, "want", want) | ||||
| fmt.Println("TestEngineAndAccumulator Passed") | fmt.Println("TestEngineAndAccumulator Passed") | ||||
| } | } | ||||
| } | } | ||||
| func BenchmarkHashGeneration(b *testing.B) { | |||||
| test := "google.com" | |||||
| for i := 0; i < b.N; i++ { | |||||
| accum := uint64(Mishmash(test, 0))<<32 | uint64(Mishmash(test, 1)) | |||||
| fmt.Printf("%016x\n", accum) | |||||
| } | |||||
| } |