-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsllb_test.go
41 lines (36 loc) · 875 Bytes
/
sllb_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
package sllb
import (
"fmt"
"math"
"math/rand"
"testing"
)
func sumFromIndex(counts []uint64, index uint64) uint64 {
var count uint64
for i := int(index); i < len(counts); i++ {
count += counts[i]
}
return count
}
func TestInsertEstimate(t *testing.T) {
sllb, err := New(0.008)
if err != nil {
t.Error("Expected no error on NewSlidingHyperLogLog, got", err)
}
counts := make([]uint64, 100)
for i := 0; i < len(counts); i++ {
for j := 0; j <= rand.Intn(100000); j++ {
e := fmt.Sprintf("e-%d-%d", i, j)
sllb.Insert(uint64(i), []byte(e))
counts[i]++
}
}
for i := uint64(0); i <= uint64(len(counts)); i++ {
est := sllb.Estimate(i)
exp := sumFromIndex(counts, i)
offset := uint64(math.Abs(5 * float64(exp) / 100))
if est < exp-offset || est > exp+offset {
t.Errorf("%d Expected error <= 5.0%% for %d, got %d", i, exp, est)
}
}
}