-
Notifications
You must be signed in to change notification settings - Fork 0
/
gkquantile_test.go
77 lines (58 loc) · 1.29 KB
/
gkquantile_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
package gkquantile
import "testing"
import "math/rand"
func Test1(t *testing.T) {
tt := NewGKSummary(0.025)
for i := 1; i < 10; i++ {
tt.Add(float64(i))
}
v := tt.Query(0.95)
if v != 8 {
t.Error("Expected 8, got ", v)
}
}
func TestRand(t *testing.T) {
tt := NewGKSummary(0.025)
r := rand.New(rand.NewSource(99))
for i := 1; i < 1000; i++ {
tt.Add(r.ExpFloat64() * 1000)
}
v := tt.Query(0.50)
if (v - 758.575157) > 0.000001 {
t.Error("Expected 758.575157, got ", v)
}
}
func TestRandLen(t *testing.T) {
tt := NewGKSummary(0.01)
r := rand.New(rand.NewSource(99))
for i := 1; i < 1000; i++ {
tt.Add(r.ExpFloat64() * 1000)
}
if len(tt.Items) != 131 {
t.Error("Expected 131, got ", len(tt.Items))
}
}
func Benchmark_1mln_025(t *testing.B) {
tt := NewGKSummary(0.025)
r := rand.New(rand.NewSource(99))
for i := 1; i < 1000000; i++ {
tt.Add(r.ExpFloat64() * 1000)
}
_ = tt.Query(0.95)
}
func Benchmark_1mln_010(t *testing.B) {
tt := NewGKSummary(0.010)
r := rand.New(rand.NewSource(99))
for i := 1; i < 1000000; i++ {
tt.Add(r.ExpFloat64() * 1000)
}
_ = tt.Query(0.95)
}
func Benchmark_1mln_001(t *testing.B) {
tt := NewGKSummary(0.001)
r := rand.New(rand.NewSource(99))
for i := 1; i < 1000000; i++ {
tt.Add(r.ExpFloat64() * 1000)
}
_ = tt.Query(0.95)
}