-
Notifications
You must be signed in to change notification settings - Fork 0
/
tick_test.go
60 lines (52 loc) · 1.4 KB
/
tick_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
package gomet
import (
"testing"
"time"
)
// test case:
// |**|.
func TestTick_1G1W1S(t *testing.T) {
period := time.Second
now := time.Now()
tick := newTick(now.Add(period), period)
tick.set("g", 1, "st", now, period, true)
equald(t, tick.Lasted("g", "st"), 0)
equalf(t, tick.Load("g", "st"), 1)
equalf(t, tick.Scale("g"), 1)
g := tick.Groups["g"]
equald(t, g.Lasted("st"), 0)
equalf(t, g.Load("st"), 1)
equalf(t, g.Scale(period), 1)
}
// test case:
// |**|.
// |++|.
func TestTick_1G2W2S(t *testing.T) {
period := time.Second
now := time.Now()
tick := newTick(now.Add(period), period)
tick.set("g", 1, "st1", now, period, true)
tick.set("g", 2, "st2", now, period, true)
equald(t, tick.Lasted("g", "st1"), 0)
equald(t, tick.Lasted("g", "st2"), 0)
equalf(t, tick.Load("g", "st1"), 0.5)
equalf(t, tick.Load("g", "st2"), 0.5)
equalf(t, tick.Scale("g"), 2)
}
// test case:
// |**|.
// |++|.
// | *|.
func TestTick_1G3W2S(t *testing.T) {
period := time.Second
now := time.Now()
tick := newTick(now.Add(period), period)
tick.set("g", 1, "st1", now, period, true)
tick.set("g", 2, "st2", now, period, true)
tick.set("g", 3, "st1", now, 500*time.Millisecond, true)
equald(t, tick.Lasted("g", "st1"), 0)
equald(t, tick.Lasted("g", "st2"), 0)
equalf(t, tick.Load("g", "st1"), (1.0+0.0+0.5)/(1.0+1.0+0.5))
equalf(t, tick.Load("g", "st2"), (0.0+1.0+0.0)/(1.0+1.0+0.5))
equalf(t, tick.Scale("g"), 2.5)
}