-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmurmurhash_test.go
More file actions
95 lines (84 loc) · 1.84 KB
/
murmurhash_test.go
File metadata and controls
95 lines (84 loc) · 1.84 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package featurevisor
import (
"testing"
)
func TestMurmurHashV3(t *testing.T) {
tests := []struct {
name string
key interface{}
seed uint32
expected uint32
}{
{
name: "empty string",
key: "",
seed: 0,
expected: 0x00000000,
},
{
name: "simple string",
key: "hello",
seed: 0,
expected: 613153351,
},
{
name: "string with seed",
key: "hello",
seed: 123,
expected: 1573043710,
},
{
name: "longer string",
key: "featurevisor",
seed: 0,
expected: 2801817157,
},
{
name: "byte slice",
key: []byte("hello"),
seed: 0,
expected: 613153351,
},
{
name: "number as string",
key: "12345",
seed: 0,
expected: 329585043,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := MurmurHashV3(tt.key, tt.seed)
if result != tt.expected {
t.Errorf("MurmurHashV3(%v, %d) = %d, want %d", tt.key, tt.seed, result, tt.expected)
}
})
}
}
func TestMurmurHashV3Consistency(t *testing.T) {
// Test that the same input always produces the same output
key := "test_key"
seed := uint32(42)
result1 := MurmurHashV3(key, seed)
result2 := MurmurHashV3(key, seed)
if result1 != result2 {
t.Errorf("MurmurHashV3 is not consistent: %d != %d", result1, result2)
}
}
func TestMurmurHashV3DifferentSeeds(t *testing.T) {
key := "test_key"
// Test that different seeds produce different results
result1 := MurmurHashV3(key, 0)
result2 := MurmurHashV3(key, 1)
if result1 == result2 {
t.Errorf("MurmurHashV3 with different seeds should produce different results: %d == %d", result1, result2)
}
}
func BenchmarkMurmurHashV3(b *testing.B) {
key := "benchmark_test_key"
seed := uint32(123)
b.ResetTimer()
for i := 0; i < b.N; i++ {
MurmurHashV3(key, seed)
}
}