-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_test.go
More file actions
67 lines (59 loc) · 1.11 KB
/
hash_test.go
File metadata and controls
67 lines (59 loc) · 1.11 KB
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
66
67
package stablemap
import (
"hash/maphash"
"testing"
"github.com/stretchr/testify/require"
)
func TestMakeDefaultHash(t *testing.T) {
v := "foo"
s := maphash.MakeSeed()
h1 := MakeDefaultHashFunc[string](s)(v)
h2 := maphash.Comparable(s, v)
require.Equal(t, h2, h1)
}
func TestHashSplit(t *testing.T) {
tests := []struct {
name string
input uint64
wantH1 uintptr
wantH2 uint8
}{
{
name: "Zero value",
input: 0,
wantH1: 0,
wantH2: 0,
},
{
name: "Max H2 (7 bits)",
input: 0x7F, // 0111 1111
wantH1: 0,
wantH2: 0x7F,
},
{
name: "First bit of H1",
input: 1 << 7, // 1000 0000
wantH1: 1,
wantH2: 0,
},
{
name: "Max uint64",
input: 0xFFFFFFFFFFFFFFFF,
wantH1: uintptr(0xFFFFFFFFFFFFFFFF >> 7),
wantH2: 0x7F,
},
{
name: "Random pattern",
input: 0xABCD1234567890EF,
wantH1: uintptr(0xABCD1234567890EF >> 7),
wantH2: 0xEF & 0x7F, // 0x6F
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h1, h2 := HashSplit(tt.input)
require.Equal(t, tt.wantH1, h1)
require.Equal(t, tt.wantH2, h2)
})
}
}