forked from bsm/zetasketch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hll_test.go
57 lines (45 loc) · 1.44 KB
/
hll_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
package zetasketch_test
import (
"github.com/gowthamkommineni/zetasketch"
. "github.com/bsm/ginkgo"
. "github.com/bsm/gomega"
)
var _ = Describe("HLL", func() {
var subject *zetasketch.HLL
var _ zetasketch.Aggregator = subject
BeforeEach(func() {
subject = zetasketch.NewHLL(nil)
for i := 0; i < 1_000; i++ {
subject.Add(zetasketch.Uint64Value(uint64(i)))
}
for i := 500; i < 1_000; i++ {
subject.Add(zetasketch.Uint64Value(uint64(i)))
}
})
It("should count values", func() {
Expect(subject.NumValues()).To(BeNumerically("==", 1_500))
})
It("should estimate uniques", func() {
Expect(subject.Result()).To(BeNumerically("==", 1_000))
})
It("should merge", func() {
other := zetasketch.NewHLL(nil)
for i := 800; i < 1_200; i++ {
other.Add(zetasketch.Uint64Value(uint64(i)))
}
Expect(subject.Merge(other)).To(Succeed())
Expect(subject.NumValues()).To(BeNumerically("==", 1_900))
Expect(subject.Result()).To(BeNumerically("==", 1_207))
// `other` is not modified:
Expect(other.NumValues()).To(BeNumerically("==", 400))
Expect(other.Result()).To(BeNumerically("==", 400))
})
It("should marshal/unmarshal binary", func() {
data, err := subject.MarshalBinary()
Expect(err).NotTo(HaveOccurred())
subject = new(zetasketch.HLL)
Expect(subject.UnmarshalBinary(data)).To(Succeed())
Expect(subject.NumValues()).To(BeNumerically("==", 1_500))
Expect(subject.Result()).To(BeNumerically("==", 1_000))
})
})