Skip to content

Commit 247c4fa

Browse files
committed
[bugfix] Fix unit test
1 parent 8600f3b commit 247c4fa

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

internal/app/controller/engine.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewGameControllerState() (s *GameControllerState) {
3737
s.GameEventBehavior[event] = GameEventBehaviorOn
3838
}
3939

40-
s.GameEventProposals = []*GameEventProposal{}
40+
s.GameEventProposals = nil
4141

4242
s.AutoRefsConnected = []string{}
4343
s.TeamConnected = map[Team]bool{}
@@ -53,8 +53,12 @@ func NewGameControllerState() (s *GameControllerState) {
5353

5454
func (s GameControllerState) DeepCopy() (c GameControllerState) {
5555
c = s
56-
c.GameEventProposals = make([]*GameEventProposal, len(s.GameEventProposals))
57-
copy(c.GameEventProposals, s.GameEventProposals)
56+
if len(s.GameEventProposals) > 0 {
57+
c.GameEventProposals = make([]*GameEventProposal, len(s.GameEventProposals))
58+
copy(c.GameEventProposals, s.GameEventProposals)
59+
} else {
60+
c.GameEventProposals = nil
61+
}
5862
c.GameEventBehavior = make(map[GameEventType]GameEventBehavior)
5963
for k, v := range s.GameEventBehavior {
6064
c.GameEventBehavior[k] = v
@@ -238,7 +242,7 @@ func (e *Engine) SendCommand(command RefCommand, forTeam Team) {
238242
}
239243
// reset game event proposals
240244
if len(e.GcState.GameEventProposals) > 0 {
241-
e.GcState.GameEventProposals = []*GameEventProposal{}
245+
e.GcState.GameEventProposals = nil
242246
}
243247
// reset ball placement pos and follow ups
244248
e.State.PlacementPos = nil

internal/app/controller/engine_test.go

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,21 @@ import (
1414
)
1515

1616
type TestState struct {
17-
Stage *Stage `yaml:"stage"`
18-
Command *RefCommand `yaml:"command"`
19-
CommandFor *Team `yaml:"commandFor"`
20-
GameEvents []*GameEvent `yaml:"gameEvents"`
21-
StageTimeElapsed *time.Duration `yaml:"stageTimeElapsed"`
22-
StageTimeLeft *time.Duration `yaml:"stageTimeLeft"`
23-
MatchTimeStart *time.Time `yaml:"matchTimeStart"`
24-
MatchDuration *time.Duration `yaml:"matchDuration"`
25-
TeamState map[Team]*TestTeamInfo `yaml:"teamState"`
26-
Division *config.Division `yaml:"division"`
27-
PlacementPos *Location `yaml:"placementPos"`
28-
AutoContinue *bool `yaml:"autoContinue"`
29-
NextCommand *RefCommand `yaml:"nextCommand"`
30-
NextCommandFor *Team `yaml:"nextCommandFor"`
31-
GameEventBehavior *map[GameEventType]GameEventBehavior `yaml:"gameEventBehavior"`
32-
GameEventProposals []*GameEventProposal `yaml:"gameEventProposals"`
33-
CurrentActionDeadline *time.Time `yaml:"currentActionDeadline"`
34-
CurrentActionTimeRemaining *time.Duration `yaml:"currentActionTimeRemaining"`
17+
Stage *Stage `yaml:"stage"`
18+
Command *RefCommand `yaml:"command"`
19+
CommandFor *Team `yaml:"commandFor"`
20+
GameEvents []*GameEvent `yaml:"gameEvents"`
21+
StageTimeElapsed *time.Duration `yaml:"stageTimeElapsed"`
22+
StageTimeLeft *time.Duration `yaml:"stageTimeLeft"`
23+
MatchTimeStart *time.Time `yaml:"matchTimeStart"`
24+
MatchDuration *time.Duration `yaml:"matchDuration"`
25+
TeamState map[Team]*TestTeamInfo `yaml:"teamState"`
26+
Division *config.Division `yaml:"division"`
27+
PlacementPos *Location `yaml:"placementPos"`
28+
NextCommand *RefCommand `yaml:"nextCommand"`
29+
NextCommandFor *Team `yaml:"nextCommandFor"`
30+
CurrentActionDeadline *time.Time `yaml:"currentActionDeadline"`
31+
CurrentActionTimeRemaining *time.Duration `yaml:"currentActionTimeRemaining"`
3532
}
3633

3734
type TestTeamInfo struct {
@@ -208,21 +205,6 @@ func (t *TestState) valid() error {
208205
if t.NextCommandFor != nil && !t.NextCommandFor.Valid() {
209206
return errors.Errorf("TestState.NextCommandFor has an invalid value: %v", t.NextCommandFor)
210207
}
211-
if t.GameEventBehavior != nil {
212-
for gameEventType, gameEventBehavior := range *t.GameEventBehavior {
213-
if !gameEventType.Valid() {
214-
return errors.Errorf("TestState.GameEventBehavior has an invalid key: %v", gameEventType)
215-
}
216-
if !gameEventBehavior.Valid() {
217-
return errors.Errorf("TestState.GameEventBehavior[%v] has an invalid value: %v", gameEventType, gameEventBehavior)
218-
}
219-
}
220-
}
221-
for _, proposal := range t.GameEventProposals {
222-
if !proposal.GameEvent.Type.Valid() {
223-
return errors.Errorf("TestState.GameEventProposals.GameEvent.Type has an invalid value: %v", proposal.GameEvent.Type)
224-
}
225-
}
226208
return nil
227209
}
228210

0 commit comments

Comments
 (0)