go implementation of CodeDweller/mishmash.hpp/cpp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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