-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffhash_test.go
54 lines (44 loc) · 1.01 KB
/
ffhash_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
package ffhash
import (
"testing"
"flag"
"os"
"math/rand"
"time"
)
var rng *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
func TestMain(m *testing.M) {
flag.Parse()
os.Exit(m.Run())
}
func TestFairFast(t *testing.T) {
var totalBuckets uint64 = Fact(4)
k_0_4 := fairfast(0, 4, 0, totalBuckets)
k_1_4 := fairfast(1, 4, 0, totalBuckets)
k_7_4 := fairfast(7, 4, 0, totalBuckets)
k_8_4 := fairfast(8, 4, 0, totalBuckets)
if k_0_4 != 3 {
t.Fail()
}
if k_1_4 != 2 {
t.Fail()
}
if k_7_4 != 1 {
t.Fail()
}
if k_8_4 != 3 {
t.Fail()
}
}
func BenchmarkFFHashBest(b *testing.B) {
for i := 0; i < b.N; i++ {
randomKey := uint64(rng.Uint32()) << 32 + uint64(rng.Uint32())
Sum64(randomKey, uint64(3))
}
}
func BenchmarkFFHashWorst(b *testing.B) {
for i := 0; i < b.N; i++ {
randomKey := uint64(rng.Uint32()) << 32 + uint64(rng.Uint32())
Sum64(randomKey, uint64(18))
}
}