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.

46 lines
1.0 KiB

  1. // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. package util
  7. import (
  8. "testing"
  9. )
  10. var hashTests = []struct {
  11. data []byte
  12. seed uint32
  13. hash uint32
  14. }{
  15. {nil, 0xbc9f1d34, 0xbc9f1d34},
  16. {[]byte{0x62}, 0xbc9f1d34, 0xef1345c4},
  17. {[]byte{0xc3, 0x97}, 0xbc9f1d34, 0x5b663814},
  18. {[]byte{0xe2, 0x99, 0xa5}, 0xbc9f1d34, 0x323c078f},
  19. {[]byte{0xe1, 0x80, 0xb9, 0x32}, 0xbc9f1d34, 0xed21633a},
  20. {[]byte{
  21. 0x01, 0xc0, 0x00, 0x00,
  22. 0x00, 0x00, 0x00, 0x00,
  23. 0x00, 0x00, 0x00, 0x00,
  24. 0x00, 0x00, 0x00, 0x00,
  25. 0x14, 0x00, 0x00, 0x00,
  26. 0x00, 0x00, 0x04, 0x00,
  27. 0x00, 0x00, 0x00, 0x14,
  28. 0x00, 0x00, 0x00, 0x18,
  29. 0x28, 0x00, 0x00, 0x00,
  30. 0x00, 0x00, 0x00, 0x00,
  31. 0x02, 0x00, 0x00, 0x00,
  32. 0x00, 0x00, 0x00, 0x00,
  33. }, 0x12345678, 0xf333dabb},
  34. }
  35. func TestHash(t *testing.T) {
  36. for i, x := range hashTests {
  37. h := Hash(x.data, x.seed)
  38. if h != x.hash {
  39. t.Fatalf("test-%d: invalid hash, %#x vs %#x", i, h, x.hash)
  40. }
  41. }
  42. }