-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlog_test.go
42 lines (33 loc) · 1.01 KB
/
log_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
package cml
import (
"math"
"testing"
)
func eval(got uint, expected uint) bool {
return uint(math.Abs(float64(expected-got))) <= (expected / 100)
}
// Ensures that Add adds to the set and Count returns the correct
// approximation.
func TestLogAddAndCount(t *testing.T) {
log, _ := NewForCapacity16(10000000, 0.01)
log.Update([]byte("b"))
log.Update([]byte("c"))
log.Update([]byte("b"))
log.Update([]byte("d"))
log.BulkUpdate([]byte("a"), 1000000)
if count := log.Query([]byte("a")); !eval(uint(count), 1000000) {
t.Errorf("expected 1000000, got %d", uint(count))
}
if count := log.Query([]byte("b")); !eval(uint(count), 2) {
t.Errorf("expected 2, got %d", uint(count))
}
if count := log.Query([]byte("c")); !eval(uint(count), 1) {
t.Errorf("expected 1, got %d", uint(count))
}
if count := log.Query([]byte("d")); !eval(uint(count), 1) {
t.Errorf("expected 1, got %d", uint(count))
}
if count := log.Query([]byte("x")); !eval(uint(count), 4) {
t.Errorf("expected 0, got %d", uint(count))
}
}