-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm_test.go
63 lines (57 loc) · 1.26 KB
/
fsm_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
package fsm
import (
"fmt"
"log"
"testing"
)
func TestFSM(t *testing.T) {
// 模拟转门
const (
// 状态
Locked = "Locked"
Unlocked = "Unlocked"
// 事件
Push = "push"
Coin = "Coin"
)
f := FSM{
Transitions: []Transition{
{From: Locked, Event: Coin, To: Unlocked},
{From: Unlocked, Event: Push, To: Locked},
},
Callbacks: []Callback{
OnEntry(Unlocked, func(t *Transition, _ ...interface{}) {
log.Println("进入了Unlocked状态")
}),
OnExit(Locked, func(t *Transition, _ ...interface{}) {
log.Println("离开了locked状态")
}),
OnEntry(Locked, func(t *Transition, _ ...interface{}) {
log.Println("进入了Locked状态")
}),
OnExit(Unlocked, func(t *Transition, _ ...interface{}) {
log.Println("离开了Unlocked状态")
}),
OnXXXEvent(Push, func(t *Transition, _ ...interface{}) {
log.Println("发生了Push事件")
}),
OnXXXEvent(Coin, func(t *Transition, _ ...interface{}) {
log.Println("发生了Coin事件")
}),
},
}
state := Locked
state = f.Trigger(state, Coin)
state = f.Trigger(state, Push)
log.Panicln(state)
}
func TestPtr(t *testing.T) {
s1 := struct {
Name string
Age int
}(struct {
Name string
Age int
}{Name: "xm", Age: 11})
fmt.Println(s1.Name)
}