-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCountMinSketch_test.go
More file actions
67 lines (60 loc) · 1.12 KB
/
CountMinSketch_test.go
File metadata and controls
67 lines (60 loc) · 1.12 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
package promsketch
import (
"fmt"
"math/rand"
"testing"
"time"
)
func TestCountMinSketch(t *testing.T) {
fmt.Println("Hello TestCountMinSketch")
cases := []struct {
key string
cnt float64
}{
{"notfound", 1},
{"hello", 1},
{"count", 3},
{"min", 4},
{"world", 10},
{"cheatcheat", 3},
{"cheatcheat", 7},
{"min", 2},
{"hello", 2},
{"tigger", 34},
{"flow", 9},
{"miss", 4},
{"hello", -30},
{"world", 10},
{"hello", 10},
}
expected := []struct {
key string
cnt float64
}{
{"notfound", 1},
{"hello", -17},
{"count", 3},
{"min", 6},
{"world", 20},
{"cheatcheat", 10},
{"tigger", 34},
{"flow", 9},
{"miss", 4},
}
seed1 := make([]uint32, CM_ROW_NO)
rand.Seed(time.Now().UnixNano())
for r := 0; r < CM_ROW_NO; r++ {
seed1[r] = rand.Uint32()
}
s, _ := NewCountMinSketch(CM_ROW_NO, CM_COL_NO, seed1)
for _, c := range cases {
s.CMProcessing(c.key, c.cnt)
}
for i, c := range expected {
got := s.EstimateStringSum(c.key)
// fmt.Println("key = ", c.key, "cm got = ", got)
if c.cnt != got {
t.Logf("case %d '%s' got %f, expect %f", i, c.key, got, c.cnt)
}
}
}