-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_test.go
72 lines (64 loc) · 1.17 KB
/
sum_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
66
67
68
69
70
71
72
package murmurtest
import (
"math/rand"
"reflect"
"testing"
"testing/quick"
"time"
m1 "github.com/spaolacci/murmur3"
m2 "github.com/twmb/murmur3"
)
const (
size = 1023
base = 10000
)
type buf []byte
func (b buf) Generate(r *rand.Rand, _ int) reflect.Value {
n := rand.Intn(size)
ls := make([]byte, 0, n)
for i := 0; i < n; i++ {
ls = append(ls, byte(rand.Intn(256)))
}
return reflect.ValueOf(ls)
}
func TestSum(t *testing.T) {
rand.Seed(time.Now().Unix())
tests := []struct {
name string
runner interface{}
scale float64
}{
{
name: "sum32",
scale: base * 4,
runner: func(b buf) bool {
return m1.Sum32(b) == m2.Sum32(b)
},
},
{
name: "sum64",
scale: base * 2,
runner: func(b buf) bool {
return m1.Sum64(b) == m2.Sum64(b)
},
},
{
name: "sum128",
scale: base,
runner: func(b buf) bool {
h1a, h1b := m1.Sum128(b)
h2a, h2b := m2.Sum128(b)
return h1a == h2a && h1b == h2b
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if err := quick.Check(tt.runner, &quick.Config{MaxCountScale: tt.scale}); err != nil {
t.Error(err)
}
})
}
}