-
Notifications
You must be signed in to change notification settings - Fork 15
/
hasher_test.go
56 lines (50 loc) · 1.13 KB
/
hasher_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
package bloomfilter
import (
"fmt"
"reflect"
"testing"
)
func TestHasher(t *testing.T) {
for _, hash := range defaultHashers {
array1 := []byte{1, 2, 3}
if !reflect.DeepEqual(hash(array1), hash(array1)) {
t.Error("undeterministic")
}
}
}
func BenchmarkHasher(b *testing.B) {
for k, hash := range defaultHashers {
b.Run(fmt.Sprintf("hasher %d", k), func(b *testing.B) {
for i := 0; i < b.N; i++ {
array1 := []byte{1, 2, 3}
hash(array1)
}
})
}
}
func TestDefaultHashFactory(t *testing.T) {
for _, hash := range DefaultHashFactory(23) {
array1 := []byte{1, 2, 3}
if !reflect.DeepEqual(hash(array1), hash(array1)) {
t.Error("undeterministic")
}
}
}
func TestOptimalHashFactory(t *testing.T) {
for _, hash := range OptimalHashFactory(23) {
array1 := []byte{1, 2, 3}
if !reflect.DeepEqual(hash(array1), hash(array1)) {
t.Error("undeterministic")
}
}
}
func BenchmarkOptimalHashFactory(b *testing.B) {
for k, hash := range OptimalHashFactory(23) {
b.Run(fmt.Sprintf("hasher %d", k), func(b *testing.B) {
for i := 0; i < b.N; i++ {
array1 := []byte{1, 2, 3}
hash(array1)
}
})
}
}