forked from orkestr8/fsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflap_test.go
50 lines (39 loc) · 869 Bytes
/
flap_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
package fsm // import "github.com/orkestr8/fsm"
import (
"testing"
"github.com/stretchr/testify/require"
)
func index(a int, b ...int) []Index {
out := []Index{Index(a)}
for _, bb := range b {
out = append(out, Index(bb))
}
return out
}
func TestHistory(t *testing.T) {
require.True(t, equals(index(1, 2, 3), index(1, 2, 3)))
require.False(t, equals(index(2, 3), index(1, 2, 3)))
}
func TestFlap(t *testing.T) {
const (
a Index = iota
b
c
x
y
)
counter := newFlaps()
require.Equal(t, 0, counter.count(a, b))
counter.record(a, b)
counter.record(b, a)
counter.record(a, c)
counter.record(a, b)
counter.record(b, a)
counter.record(a, b)
counter.record(b, a)
require.Equal(t, 2, counter.count(a, b))
require.Equal(t, 2, counter.count(b, a))
counter.record(a, b)
counter.record(b, a)
require.Equal(t, 3, counter.count(a, b))
}