go implementation of CodeDweller/mishmash.hpp/cpp
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mishmash_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package mishmash
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestMishmash(t *testing.T) {
  7. want := "9d923077"
  8. if got := fmt.Sprintf("%08x", Mishmash("google.com")); want != got {
  9. t.Error("Parse() = got", got, "want", want)
  10. } else {
  11. fmt.Println("TestMishmash Passed")
  12. }
  13. }
  14. func TestSecondHash(t *testing.T) {
  15. want := "3fbdb348"
  16. hash := Mishmash("google.com")
  17. if got := fmt.Sprintf("%08x", Mishmash("google.com", uint64(hash))); want != got {
  18. t.Error("Parse() = got", got, "want", want)
  19. } else {
  20. fmt.Println("TestSecondHash Passed")
  21. }
  22. }
  23. func TestSeedOne(t *testing.T) {
  24. want := "cebf5691"
  25. if got := fmt.Sprintf("%08x", Mishmash("google.com", uint64(1))); want != got {
  26. t.Error("Parse() = got", got, "want", want)
  27. } else {
  28. fmt.Println("TestSeedOne Passed")
  29. }
  30. }
  31. func TestEngineAndAccumulator(t *testing.T) {
  32. want := "65df1304"
  33. test := "google.com"
  34. accum := Engine(test, len(test), 0)
  35. if got := fmt.Sprintf("%08x", Mishmash(test, accum)); want != got {
  36. t.Error("Parse() = got", got, "want", want)
  37. } else {
  38. fmt.Println("TestEngineAndAccumulator Passed")
  39. }
  40. }
  41. func BenchmarkHashGeneration(b *testing.B) {
  42. test := "google.com"
  43. for i := 0; i < b.N; i++ {
  44. accum := uint64(Mishmash(test, 0))<<32 | uint64(Mishmash(test, 1))
  45. fmt.Printf("%016x\n", accum)
  46. }
  47. }