Skip to content

Commit 70358ac

Browse files
committed
[test] Add tests for divB for ball placement
1 parent 34a8c8f commit 70358ac

7 files changed

+220
-9
lines changed

internal/app/controller/engine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ func (e *Engine) loadStages() {
4545

4646
func (e *Engine) ResetGame() {
4747
e.State = NewState()
48+
e.UiProtocol = []UiProtocolEntry{}
49+
e.State.Division = e.config.DefaultDivision
50+
e.Geometry = *e.config.DefaultGeometry[e.State.Division]
51+
4852
for _, team := range []Team{TeamBlue, TeamYellow} {
4953
e.State.TeamState[team].TimeoutTimeLeft = e.config.Normal.TimeoutDuration
5054
e.State.TeamState[team].TimeoutsLeft = e.config.Normal.Timeouts
5155
e.State.TeamState[team].MaxAllowedBots = e.config.MaxBots[e.State.Division]
5256
}
53-
54-
e.UiProtocol = []UiProtocolEntry{}
55-
e.State.Division = e.config.DefaultDivision
56-
e.Geometry = *e.config.DefaultGeometry[e.State.Division]
5757
}
5858

5959
// Tick updates the times of the state and removes cards, if necessary

internal/app/controller/engine_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,28 @@ func processTransitionFile(t *testing.T, fileName string) {
8484
if err != nil {
8585
t.Fatal(err)
8686
}
87+
8788
stateTransitions := new(StateTransitions)
8889
if err := yaml.UnmarshalStrict(bytes, &stateTransitions); err != nil {
8990
t.Fatal("Could not unmarshal state transitions:", err)
9091
}
92+
93+
if stateTransitions.InitialState == nil {
94+
t.Fatalf("No initial state given: %v", stateTransitions)
95+
}
96+
9197
cfg := config.DefaultControllerConfig().Game
98+
if stateTransitions.InitialState.Division != nil {
99+
cfg.DefaultDivision = *stateTransitions.InitialState.Division
100+
}
101+
92102
e := NewEngine(cfg)
93103
initialTime := initialTime()
94104
elapsedTime := time.Duration(0)
95105
e.TimeProvider = func() time.Time {
96106
return initialTime.Add(elapsedTime)
97107
}
98108

99-
if stateTransitions.InitialState == nil {
100-
t.Fatalf("No initial state given: %v", stateTransitions)
101-
}
102-
103109
// apply the initial state to the engine
104110
if err := stateTransitions.InitialState.valid(); err != nil {
105111
t.Fatal(err)

internal/app/controller/testdata/engine_test_gameevent_placement_success.yaml renamed to internal/app/controller/testdata/engine_test_gameevent_placement_success_divA.yaml

File renamed without changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Situation:
2+
# Division: B
3+
# Who can place: both teams
4+
# Who succeeds: First team
5+
# What happened: ball left field on goal line -> direct
6+
#
7+
# Setup:
8+
# ball left field by: Yellow
9+
# team in favor: Blue
10+
#
11+
# Expectation:
12+
# Blue is awarded a direct free kick, places the ball successfully and performs the direct free kick.
13+
#
14+
initialState:
15+
stage: First Half
16+
command: forceStart
17+
division: DivB
18+
stageTimeLeft: 5m
19+
teamState:
20+
Yellow:
21+
ballPlacementFailures: 2
22+
Blue:
23+
ballPlacementFailures: 3
24+
transitions:
25+
- event:
26+
gameEvent:
27+
type: ballLeftFieldGoalLine
28+
details:
29+
ballleftfieldgoalline:
30+
byteam: 1 # Yellow
31+
bybot: 0
32+
location:
33+
x: 4.5
34+
y: 3.0
35+
expectedStateDiff:
36+
command: ballPlacement
37+
commandFor: Blue
38+
nextCommand: direct
39+
nextCommandFor: Blue
40+
placementPos:
41+
x: 4.3
42+
y: 2.8
43+
gameEvents:
44+
- type: ballLeftFieldGoalLine
45+
details:
46+
ballleftfieldgoalline:
47+
byteam: 1 # Yellow
48+
bybot: 0
49+
location:
50+
x: 4.5
51+
y: 3.0
52+
- tick: 1s # make sure that the stage time is not proceeded
53+
- event:
54+
gameEvent:
55+
type: placementSucceeded
56+
details:
57+
placementsucceeded:
58+
byteam: 2 # Blue
59+
timetaken: 1.0
60+
precision: 0.01
61+
expectedStateDiff:
62+
command: direct
63+
commandFor: Blue
64+
nextCommand: ""
65+
nextCommandFor: ""
66+
lackOfProgressDeadline: "2010-01-01T00:00:11Z"
67+
lackOfProgressTimeRemaining: 10s
68+
gameEvents: []
69+
teamState:
70+
Blue:
71+
ballPlacementFailures: 0
72+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Situation:
2+
# Division: B
3+
# Who can place: team in favor only
4+
# Who succeeds: First team
5+
# What happened: ball left field on goal line -> direct
6+
#
7+
# Setup:
8+
# ball left field by: Yellow
9+
# team in favor: Blue
10+
#
11+
# Expectation:
12+
# Blue can place the ball, so Blue should get the direct free kick and should place the ball.
13+
# It will succeed and should get the direct free kick afterwards.
14+
#
15+
initialState:
16+
stage: First Half
17+
command: forceStart
18+
division: DivB
19+
stageTimeLeft: 5m
20+
teamState:
21+
Yellow:
22+
canPlaceBall: false
23+
transitions:
24+
- event:
25+
gameEvent:
26+
type: ballLeftFieldGoalLine
27+
details:
28+
ballleftfieldgoalline:
29+
byteam: 1 # Yellow
30+
bybot: 0
31+
location:
32+
x: 4.5
33+
y: 3.0
34+
expectedStateDiff:
35+
command: ballPlacement
36+
commandFor: Blue
37+
nextCommand: direct
38+
nextCommandFor: Blue
39+
placementPos:
40+
x: 4.3
41+
y: 2.8
42+
gameEvents:
43+
- type: ballLeftFieldGoalLine
44+
details:
45+
ballleftfieldgoalline:
46+
byteam: 1 # Yellow
47+
bybot: 0
48+
location:
49+
x: 4.5
50+
y: 3.0
51+
- tick: 1s # make sure that the stage time is not proceeded
52+
- event:
53+
gameEvent:
54+
type: placementSucceeded
55+
details:
56+
placementsucceeded:
57+
byteam: 2 # Blue
58+
timetaken: 1.0
59+
precision: 0.01
60+
expectedStateDiff:
61+
command: direct
62+
commandFor: Blue
63+
nextCommand: ""
64+
nextCommandFor: ""
65+
lackOfProgressDeadline: "2010-01-01T00:00:11Z"
66+
lackOfProgressTimeRemaining: 10s
67+
gameEvents: []

internal/app/controller/testdata/engine_test_gameevent_placement_success_teamInFavorCantPlace_divA.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# team in favor: Blue
1010
#
1111
# Expectation:
12-
# Blue can't place the ball, so Blue should get an indirect free kick and should place the ball.
12+
# Blue can't place the ball, so Yellow should get an indirect free kick and should place the ball.
1313
# It will succeed and should get the indirect free kick afterwards.
1414
#
1515
initialState:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Situation:
2+
# Division: B
3+
# Who can place: team *not* in favor only
4+
# Who succeeds: First team
5+
# What happened: ball left field on goal line -> direct
6+
#
7+
# Setup:
8+
# ball left field by: Yellow
9+
# team in favor: Blue
10+
#
11+
# Expectation:
12+
# Blue can't place the ball, so Yellow should do the ball placement, but Blue should do the direct kick afterwards.
13+
#
14+
initialState:
15+
stage: First Half
16+
command: forceStart
17+
division: DivB
18+
stageTimeLeft: 5m
19+
teamState:
20+
Blue:
21+
canPlaceBall: false
22+
transitions:
23+
- event:
24+
gameEvent:
25+
type: ballLeftFieldGoalLine
26+
details:
27+
ballleftfieldgoalline:
28+
byteam: 1 # Yellow
29+
bybot: 0
30+
location:
31+
x: 4.5
32+
y: 3.0
33+
expectedStateDiff:
34+
command: ballPlacement
35+
commandFor: Yellow
36+
nextCommand: direct
37+
nextCommandFor: Blue
38+
placementPos:
39+
x: 4.3
40+
y: 2.8
41+
gameEvents:
42+
- type: ballLeftFieldGoalLine
43+
details:
44+
ballleftfieldgoalline:
45+
byteam: 1 # Yellow
46+
bybot: 0
47+
location:
48+
x: 4.5
49+
y: 3.0
50+
- tick: 1s # make sure that the stage time is not proceeded
51+
- event:
52+
gameEvent:
53+
type: placementSucceeded
54+
details:
55+
placementsucceeded:
56+
byteam: 2 # Blue
57+
timetaken: 1.0
58+
precision: 0.01
59+
expectedStateDiff:
60+
command: direct
61+
commandFor: Blue
62+
nextCommand: ""
63+
nextCommandFor: ""
64+
lackOfProgressDeadline: "2010-01-01T00:00:11Z"
65+
lackOfProgressTimeRemaining: 10s
66+
gameEvents: []

0 commit comments

Comments
 (0)