-
Notifications
You must be signed in to change notification settings - Fork 5
/
hashfunc_test.go
55 lines (42 loc) · 1.33 KB
/
hashfunc_test.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package hashmap
import (
"testing"
)
type HashKey struct {
key interface{}
}
func testKeyHash(t *testing.T, availableHash uint, hashKey uint) {
if hashKey != availableHash {
t.Errorf("Expected hash key %d, got %d", availableHash, hashKey)
}
}
func testBucketIdx(t *testing.T, availableIdx uint, bucketIdx uint) {
if bucketIdx != availableIdx {
t.Errorf("Expected bucket idx %d, got %d", availableIdx, bucketIdx)
}
}
func TestIntHash16(t *testing.T) {
hashKey, bucketIdx := hashFunc(16, 123112122)
testKeyHash(t, uint(249811310353814468), hashKey)
testBucketIdx(t, uint(4), bucketIdx)
}
func TestStringHash16(t *testing.T) {
hashKey, bucketIdx := hashFunc(16, "test_value")
testKeyHash(t, uint(11696809291008937669), hashKey)
testBucketIdx(t, uint(5), bucketIdx)
}
func TestSliceHash16(t *testing.T) {
hashKey, bucketIdx := hashFunc(16, []string{"test_value"})
testKeyHash(t, uint(13905799525442369900), hashKey)
testBucketIdx(t, uint(12), bucketIdx)
}
func TestMapHash16(t *testing.T) {
hashKey, bucketIdx := hashFunc(16, map[string]string{"key":"value"})
testKeyHash(t, uint(6432338246103250761), hashKey)
testBucketIdx(t, uint(9), bucketIdx)
}
func TestStructHash16(t *testing.T) {
hashKey, bucketIdx := hashFunc(16, HashKey{"key"})
testKeyHash(t, uint(2074006382534894026), hashKey)
testBucketIdx(t, uint(10), bucketIdx)
}