-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhll_update_test.go
103 lines (84 loc) · 1.63 KB
/
hll_update_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package goriak
import (
"testing"
)
func TestHllBasics(t *testing.T) {
res, err := Bucket("hll-test", "hlls").
UpdateHyperLogLog().
Add([]byte{1}).
Add([]byte{2}).
Add([]byte{3}).
Add([]byte{4}).
ReturnBody(true).
Run(con())
if err != nil {
t.Error(err)
}
if res.Cardinality != 4 {
t.Error("unexpected cardinality")
}
if res.NotFound == true {
t.Error("not found was true")
}
// Get same
res2, err := Bucket("hll-test", "hlls").
GetHyperLogLog(res.Key).
Run(con())
if res2.Cardinality != 4 {
t.Error("unexpected cardinality")
}
if res.NotFound == true {
t.Error("not found was true")
}
if res2.Key != res.Key {
t.Error("unexpected key")
}
// Add one more
res3, err := Bucket("hll-test", "hlls").
UpdateHyperLogLog().
Add([]byte{5}).
Key(res.Key).
ReturnBody(true).
Run(con())
if err != nil {
t.Error(err)
}
if res3.Cardinality != 5 {
t.Error("unexpected cardinality")
}
if res3.NotFound == true {
t.Error("not found was true")
}
if res3.Key != res.Key {
t.Error("unexpected key")
}
}
func TestHllWithoutReturn(t *testing.T) {
res, err := Bucket("hll-test", "hlls").
UpdateHyperLogLog().
Add([]byte{1}).
Run(con())
if err != nil {
t.Error(err)
}
if res != nil {
t.Error("res was not nil")
}
}
func TestHllAddMultiple(t *testing.T) {
res, err := Bucket("hll-test", "hlls").
UpdateHyperLogLog().
AddMultiple([]byte{1}, []byte{2}, []byte{3}).
AddMultiple([]byte{1}, []byte{2}, []byte{3}).
ReturnBody(true).
Run(con())
if err != nil {
t.Error(err)
}
if res == nil {
t.Error("res was nil")
}
if res.Cardinality != 3 {
t.Error("unexpected val")
}
}