aboutsummaryrefslogtreecommitdiff
path: root/internal/hash/hash_func_test.go
blob: 15919c3af71d37de200bfdd2af684b0d882dd6da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package hash

import "testing"

func TestDefaultHash(t *testing.T) {
	testCases := []struct {
		key  string
		hash uint32
	}{
		{"", 0},
		{"A", 65},
		{"AA", 2210},
		{"AAA", 72995},
		{"AAAA", 2408900},
		{"AAAAA", 79493765},
		{"AAAAAA", 2623294310},
		{"AAAAAAA", 669366375},
		{"AAAAAAAA", 614253960},
	}
	for _, tc := range testCases {
		t.Run(tc.key, func(t *testing.T) {
			x := defaultHash([]byte(tc.key))
			if x != tc.hash {
				t.Errorf("got %v, want %v", x, tc.hash)
			}
		})
	}
}

func BenchmarkDefaultHash(b *testing.B) {
	key := []byte("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG")
	for i := 0; i < b.N; i++ {
		defaultHash(key)
	}
}