-
Notifications
You must be signed in to change notification settings - Fork 8
/
calcs_test.go
158 lines (132 loc) · 3.47 KB
/
calcs_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package tachymeter_test
import (
//"fmt"
"sort"
"testing"
"time"
"github.com/jamiealquiza/tachymeter"
)
func TestCalc(t *testing.T) {
ta := tachymeter.New(&tachymeter.Config{Size: 30})
// These end up overwritten; we're
// putting 32 events in a size 30 Tachymeter.
ta.AddTime(12 * time.Millisecond)
ta.AddTime(96 * time.Millisecond)
ta.AddTime(9 * time.Millisecond)
ta.AddTime(4 * time.Millisecond)
ta.AddTime(88 * time.Millisecond)
ta.AddTime(37 * time.Millisecond)
ta.AddTime(42 * time.Millisecond)
ta.AddTime(77 * time.Millisecond)
ta.AddTime(93 * time.Millisecond)
ta.AddTime(89 * time.Millisecond)
ta.AddTime(12 * time.Millisecond)
ta.AddTime(36 * time.Millisecond)
ta.AddTime(54 * time.Millisecond)
ta.AddTime(21 * time.Millisecond)
ta.AddTime(17 * time.Millisecond)
ta.AddTime(14 * time.Millisecond)
ta.AddTime(67 * time.Millisecond)
ta.AddTime(9 * time.Millisecond)
ta.AddTime(4 * time.Millisecond)
ta.AddTime(88 * time.Millisecond)
ta.AddTime(37 * time.Millisecond)
ta.AddTime(42 * time.Millisecond)
ta.AddTime(77 * time.Millisecond)
ta.AddTime(93 * time.Millisecond)
ta.AddTime(89 * time.Millisecond)
ta.AddTime(12 * time.Millisecond)
ta.AddTime(36 * time.Millisecond)
ta.AddTime(54 * time.Millisecond)
ta.AddTime(21 * time.Millisecond)
ta.AddTime(17 * time.Millisecond)
ta.AddTime(14 * time.Millisecond)
ta.AddTime(67 * time.Millisecond)
metrics := ta.Calc()
if metrics.Samples != 30 {
t.Error("Expected 30, got ", metrics.Samples)
}
if metrics.Count != 32 {
t.Error("Expected 32, got ", metrics.Count)
}
expectedDurs := []time.Duration{
4000000,
4000000,
9000000,
9000000,
12000000,
12000000,
14000000,
14000000,
17000000,
17000000,
21000000,
21000000,
36000000,
36000000,
37000000,
37000000,
42000000,
42000000,
54000000,
54000000,
67000000,
67000000,
77000000,
77000000,
88000000,
88000000,
89000000,
89000000,
93000000,
93000000,
}
sort.Sort(ta.Times)
for n, d := range ta.Times {
if d != expectedDurs[n] {
t.Errorf("Expected %d, got %d\n", expectedDurs[n], d)
}
}
if metrics.Time.Cumulative != 1320000000 {
t.Errorf("Expected 1320000000, got %d\n", metrics.Time.Cumulative)
}
if metrics.Time.Avg != 44000000 {
t.Errorf("Expected 44000000, got %d\n", metrics.Time.Avg)
}
if metrics.Time.P50 != 37000000 {
t.Errorf("Expected 37000000, got %d\n", metrics.Time.P50)
}
if metrics.Time.P75 != 77000000 {
t.Errorf("Expected 77000000, got %d\n", metrics.Time.P75)
}
if metrics.Time.P95 != 93000000 {
t.Errorf("Expected 93000000, got %d\n", metrics.Time.P95)
}
if metrics.Time.P99 != 93000000 {
t.Errorf("Expected 93000000, got %d\n", metrics.Time.P99)
}
if metrics.Time.P999 != 93000000 {
t.Errorf("Expected 93000000, got %d\n", metrics.Time.P999)
}
if metrics.Time.Long5p != 93000000 {
t.Errorf("Expected 93000000, got %d\n", metrics.Time.Long5p)
}
if metrics.Time.Short5p != 4000000 {
t.Errorf("Expected 4000000, got %d\n", metrics.Time.Short5p)
}
if metrics.Time.Max != 93000000 {
t.Errorf("Expected 93000000, got %d\n", metrics.Time.Max)
}
if metrics.Time.Min != 4000000 {
t.Errorf("Expected 4000000, got %d\n", metrics.Time.Min)
}
if metrics.Time.Range != 89000000 {
t.Errorf("Expected 89000000, got %d\n", metrics.Time.Range)
}
if metrics.Time.StdDev != 30772281 {
t.Errorf("Expected abc, got %d\n", metrics.Time.StdDev)
}
if metrics.Rate.Second != 22.72727272727273 {
t.Errorf("Expected 22.73, got %0.2f\n", metrics.Rate.Second)
}
}