File tree Expand file tree Collapse file tree 3 files changed +172
-0
lines changed
Expand file tree Collapse file tree 3 files changed +172
-0
lines changed Original file line number Diff line number Diff line change 1+ package controller
2+
3+ import (
4+ "encoding/json"
5+ "io/ioutil"
6+ "path/filepath"
7+ "reflect"
8+ "testing"
9+ )
10+
11+ type StateTransitions struct {
12+ Event * Event `json:"event"`
13+ State * State `json:"state"`
14+ }
15+
16+ func Test_transitions (t * testing.T ) {
17+ path := filepath .Join ("testdata" , "stateTransitions.json" )
18+ bytes , err := ioutil .ReadFile (path )
19+ if err != nil {
20+ t .Fatal (err )
21+ }
22+ stateTransitions := make ([]StateTransitions , 0 )
23+ json .Unmarshal (bytes , & stateTransitions )
24+
25+ config := DefaultConfig ().Game
26+ e := NewEngine (config )
27+ for _ , s := range stateTransitions {
28+
29+ if s .Event != nil {
30+ e .Process (* s .Event )
31+
32+ if s .State != nil && ! reflect .DeepEqual (* e .State , * s .State ) {
33+ t .Errorf ("\n Expected: %v\n got: %v" , * s .State , * e .State )
34+ }
35+ }
36+
37+ if s .State != nil {
38+ e .State = s .State
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 11package controller
22
33import (
4+ "encoding/json"
45 "github.com/pkg/errors"
56 "time"
67)
@@ -169,3 +170,19 @@ func newTeamInfo() (t TeamInfo) {
169170 t .OnPositiveHalf = true
170171 return
171172}
173+
174+ func (t TeamInfo ) String () string {
175+ bytes , e := json .Marshal (t )
176+ if e != nil {
177+ return e .Error ()
178+ }
179+ return string (bytes )
180+ }
181+
182+ func (s State ) String () string {
183+ bytes , e := json .Marshal (s )
184+ if e != nil {
185+ return e .Error ()
186+ }
187+ return string (bytes )
188+ }
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "state" : {
4+ "stage" : " First Half Pre" ,
5+ "gameState" : " Halted" ,
6+ "gameStateForTeam" : null ,
7+ "gameTimeElapsed" : 0 ,
8+ "gameTimeLeft" : 0 ,
9+ "matchDuration" : 0 ,
10+ "teamState" : {
11+ "Blue" : {
12+ "name" : " " ,
13+ "goals" : 0 ,
14+ "goalie" : 0 ,
15+ "yellowCards" : 0 ,
16+ "yellowCardTimes" : [],
17+ "redCards" : 0 ,
18+ "timeoutsLeft" : 4 ,
19+ "timeoutTimeLeft" : 300000000000 ,
20+ "onPositiveHalf" : false
21+ },
22+ "Yellow" : {
23+ "name" : " " ,
24+ "goals" : 0 ,
25+ "goalie" : 0 ,
26+ "yellowCards" : 0 ,
27+ "yellowCardTimes" : [],
28+ "redCards" : 0 ,
29+ "timeoutsLeft" : 4 ,
30+ "timeoutTimeLeft" : 300000000000 ,
31+ "onPositiveHalf" : true
32+ }
33+ }
34+ }
35+ },
36+ {
37+ "event" : {
38+ "command" : {
39+ "commandType" : " stop"
40+ }
41+ },
42+ "state" : {
43+ "stage" : " First Half Pre" ,
44+ "gameState" : " Stopped" ,
45+ "gameStateForTeam" : null ,
46+ "gameTimeElapsed" : 0 ,
47+ "gameTimeLeft" : 0 ,
48+ "matchDuration" : 0 ,
49+ "teamState" : {
50+ "Blue" : {
51+ "name" : " " ,
52+ "goals" : 0 ,
53+ "goalie" : 0 ,
54+ "yellowCards" : 0 ,
55+ "yellowCardTimes" : [],
56+ "redCards" : 0 ,
57+ "timeoutsLeft" : 4 ,
58+ "timeoutTimeLeft" : 300000000000 ,
59+ "onPositiveHalf" : false
60+ },
61+ "Yellow" : {
62+ "name" : " " ,
63+ "goals" : 0 ,
64+ "goalie" : 0 ,
65+ "yellowCards" : 0 ,
66+ "yellowCardTimes" : [],
67+ "redCards" : 0 ,
68+ "timeoutsLeft" : 4 ,
69+ "timeoutTimeLeft" : 300000000000 ,
70+ "onPositiveHalf" : true
71+ }
72+ }
73+ }
74+ },
75+ {
76+ "event" : {
77+ "command" : {
78+ "commandType" : " forceStart"
79+ }
80+ },
81+ "state" : {
82+ "stage" : " First Half Pre" ,
83+ "gameState" : " Running" ,
84+ "gameStateForTeam" : null ,
85+ "gameTimeElapsed" : 0 ,
86+ "gameTimeLeft" : 0 ,
87+ "matchDuration" : 0 ,
88+ "teamState" : {
89+ "Blue" : {
90+ "name" : " " ,
91+ "goals" : 0 ,
92+ "goalie" : 0 ,
93+ "yellowCards" : 0 ,
94+ "yellowCardTimes" : [],
95+ "redCards" : 0 ,
96+ "timeoutsLeft" : 4 ,
97+ "timeoutTimeLeft" : 300000000000 ,
98+ "onPositiveHalf" : false
99+ },
100+ "Yellow" : {
101+ "name" : " " ,
102+ "goals" : 0 ,
103+ "goalie" : 0 ,
104+ "yellowCards" : 0 ,
105+ "yellowCardTimes" : [],
106+ "redCards" : 0 ,
107+ "timeoutsLeft" : 4 ,
108+ "timeoutTimeLeft" : 300000000000 ,
109+ "onPositiveHalf" : true
110+ }
111+ }
112+ }
113+ }
114+ ]
You can’t perform that action at this time.
0 commit comments