-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_test.go
65 lines (55 loc) · 1.08 KB
/
hash_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
56
57
58
59
60
61
62
63
64
65
package hash
import (
"testing"
)
func TestHashString(t *testing.T) {
hashkeyInit(1)
t.Log(hash("sss", 0))
}
func TestHashInt(t *testing.T) {
hashkeyInit(1)
t.Log(hash(int(111), 0))
}
func TestHashUint(t *testing.T) {
hashkeyInit(1)
t.Log(hash(uint(111), 0))
}
type something struct {
a, b, c, d, e, f, g, h int
}
func TestHashStruct(t *testing.T) {
hashkeyInit(1)
t.Log(hash(something{a: 1}, 0))
}
func TestHashStructPtr(t *testing.T) {
hashkeyInit(1)
t.Log(hash(&something{a: 1}, 0))
}
func TestHashStructPtr2(t *testing.T) {
hashkeyInit(1)
t.Log(hash(&something{a: 2}, 0))
}
func TestHashSlice(t *testing.T) {
hashkeyInit(1)
arr := [5]int{1, 0, 0, 0, 0}
s1 := arr[:]
s2 := arr[1:]
s3 := arr[1:]
h1 := hash(s1, 0)
h2 := hash(s2, 0)
h3 := hash(s3, 0)
if h2 != h3 {
t.Fatalf("%q(%d) != %q(%d)\n", s2, h2, s3, h3)
}
if h1 == h2 || h1 == h3 {
t.Fatalf("unexpected equivalent hashes %q(%d) == %q(%d)\n",
s1, h1, s2, h2)
}
}
func TestHashStructWithSlice(t *testing.T) {
hashkeyInit(1)
t.Log(hash(struct {
a int
b []int
}{a: 1, b: []int{1, 0, 0, 0, 0}}, 0))
}