-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhistogram_test.go
More file actions
80 lines (69 loc) · 1.88 KB
/
Copy pathhistogram_test.go
File metadata and controls
80 lines (69 loc) · 1.88 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
68
69
70
71
72
73
74
75
76
77
78
79
80
package histogram
import (
"math"
"testing"
)
func TestFastUnderflow(t *testing.T) {
f := GetFast()
defer PutFast(f)
q := f.Quantile(0.5)
if !math.IsNaN(q) {
t.Fatalf("unexpected quantile for empty histogram; got %v; want %v", q, nan)
}
for i := 0; i < maxSamples; i++ {
f.Update(float64(i))
}
qs := f.Quantiles(nil, []float64{0, 0.5, 1})
if qs[0] != 0 {
t.Fatalf("unexpected quantile value for phi=0; got %v; want %v", qs[0], 0)
}
if qs[1] != maxSamples/2 {
t.Fatalf("unexpected quantile value for phi=0.5; got %v; want %v", qs[1], maxSamples/2)
}
if qs[2] != maxSamples-1 {
t.Fatalf("unexpected quantile value for phi=1; got %v; want %v", qs[2], maxSamples-1)
}
}
func TestFastOverflow(t *testing.T) {
f := GetFast()
defer PutFast(f)
for i := 0; i < maxSamples*10; i++ {
f.Update(float64(i))
}
qs := f.Quantiles(nil, []float64{0, 0.5, 0.9999, 1})
if qs[0] != 0 {
t.Fatalf("unexpected quantile value for phi=0; got %v; want %v", qs[0], 0)
}
median := float64(maxSamples*10-1) / 2
if qs[1] < median*0.9 || qs[1] > median*1.1 {
t.Fatalf("unexpected quantile value for phi=0.5; got %v; want %v", qs[1], median)
}
if qs[2] < maxSamples*10*0.9 {
t.Fatalf("unexpected quantile value for phi=0.9999; got %v; want %v", qs[2], maxSamples*10*0.9)
}
if qs[3] != maxSamples*10-1 {
t.Fatalf("unexpected quantile value for phi=1; got %v; want %v", qs[3], maxSamples*10-1)
}
q := f.Quantile(nan)
if !math.IsNaN(q) {
t.Fatalf("unexpected value for phi=NaN; got %v; want %v", q, nan)
}
}
func TestFastRepeatableResults(t *testing.T) {
f := GetFast()
defer PutFast(f)
for i := 0; i < maxSamples*10; i++ {
f.Update(float64(i))
}
q1 := f.Quantile(0.95)
for j := 0; j < 10; j++ {
f.Reset()
for i := 0; i < maxSamples*10; i++ {
f.Update(float64(i))
}
q2 := f.Quantile(0.95)
if q2 != q1 {
t.Fatalf("unexpected quantile value; got %g; want %g", q2, q1)
}
}
}