-
Notifications
You must be signed in to change notification settings - Fork 2
/
windows_test.go
59 lines (50 loc) · 1.23 KB
/
windows_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
package window
import (
"github.com/stretchr/testify/suite"
"testing"
"time"
)
type WindowsTestSuite struct {
suite.Suite
}
func (o *WindowsTestSuite) TestAll() {
var (
w *TimeWindow
added bool
)
windows := NewWindows()
prefix := "test-windows"
w1 := NewTimeWindow(prefix, 1*time.Second, 5*time.Second)
w2 := NewTimeWindow(prefix, 3*time.Second, 7*time.Second)
w3 := NewTimeWindow(prefix, 2*time.Second, 6*time.Second)
added = windows.Add(w1)
o.T().Logf("w=%s||added=%v", w1, added)
o.Require().True(added)
o.Require().Len(windows, 1)
added = windows.Add(w1)
o.T().Logf("w=%s||added=%v", w1, added)
o.Require().False(added)
o.Require().Len(windows, 1)
added = windows.Add(w2)
o.T().Logf("w=%s||added=%v", w2, added)
o.Require().True(added)
o.Require().Len(windows, 2)
w = windows.Peek()
o.Require().Equal(w1, w)
added = windows.Add(w3)
o.T().Logf("w=%s||added=%v", w3, added)
o.Require().True(added)
o.Require().Len(windows, 3)
w = windows.Peek()
o.Require().Equal(w1, w)
//从小到大 pop
w = windows.PopFront()
o.Require().Equal(w1, w)
w = windows.PopFront()
o.Require().Equal(w3, w)
w = windows.PopFront()
o.Require().Equal(w2, w)
}
func TestWindows(t *testing.T) {
suite.Run(t, new(WindowsTestSuite))
}