-
Notifications
You must be signed in to change notification settings - Fork 43
/
histogram_test.go
51 lines (44 loc) · 1.2 KB
/
histogram_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
package main
import "testing"
func TestHistogram(t *testing.T) {
h := histogram{}
for i := 1; i <= 1000; i++ {
h.Add(float64(i))
}
if got, want := h.Total(), 500500.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
if got, want := h.Average(), 500.5; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
if got, want := h.Min(), 1.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
if got, want := h.Max(), 1000.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
percentiles := h.Percentiles(5, 50, 99, 100)
if got, want := percentiles[0], 51.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
if got, want := percentiles[1], 501.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
if got, want := percentiles[2], 991.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
if got, want := percentiles[3], 1000.0; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
}
func TestHistogramVariance(t *testing.T) {
h := histogram{}
h.Add(5)
h.Add(6)
h.Add(7)
h.Add(8)
h.Add(9)
if got, want := h.Variance(), 2.; got != want {
t.Errorf("got: %0.4f; want: %0.4f", got, want)
}
}