Skip to content

Commit

Permalink
Update match play tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed May 17, 2024
1 parent 9a40ca7 commit 452408c
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions web/match_play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,74 +126,64 @@ func TestCommitTiebreak(t *testing.T) {
MatchId: match.Id,
// These should all be fields that aren't part of the tiebreaker.
RedScore: &game.Score{
// TODO(pat): Update for 2024.
//Grid: game.Grid{Nodes: [3][9]game.NodeState{{game.Cube}, {game.Cone}}},
Fouls: []game.Foul{{RuleId: 1}, {RuleId: 2}},
AmpSpeaker: game.AmpSpeaker{TeleopUnamplifiedSpeakerNotes: 1},
Fouls: []game.Foul{{RuleId: 1}, {RuleId: 2}},
},
BlueScore: &game.Score{
Fouls: []game.Foul{{RuleId: 1}},
},
}

// Sanity check that the test scores are equal; they will need to be updated accordingly for each new game.
// TODO(pat): Update for 2024.
//assert.Equal(
// t,
// matchResult.RedScore.Summarize(matchResult.BlueScore).Score,
// matchResult.BlueScore.Summarize(matchResult.RedScore).Score,
//)
assert.Equal(
t,
matchResult.RedScore.Summarize(matchResult.BlueScore).Score,
matchResult.BlueScore.Summarize(matchResult.RedScore).Score,
)

err := web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
match, _ = web.arena.Database.GetMatchById(1)
// TODO(pat): Update for 2024.
//assert.Equal(t, game.TieMatch, match.Status)
assert.Equal(t, game.TieMatch, match.Status)

// The match should still be tied since the tiebreaker criteria for a perfect tie are fulfilled.
match.UseTiebreakCriteria = true
web.arena.Database.UpdateMatch(match)
err = web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
match, _ = web.arena.Database.GetMatchById(1)
// TODO(pat): Update for 2024.
//assert.Equal(t, game.TieMatch, match.Status)
assert.Equal(t, game.TieMatch, match.Status)

// Change the score to still be equal nominally but trigger the tiebreaker criteria.
// TODO(pat): Update for 2024.
//matchResult.BlueScore.AutoDockStatuses = [3]bool{true, false, false}
//matchResult.BlueScore.AutoChargeStationLevel = true
matchResult.BlueScore.TrapStatuses = [3]bool{true, false, false}
matchResult.BlueScore.Fouls = []game.Foul{{IsTechnical: false}, {IsTechnical: true}}

// Sanity check that the test scores are equal; they will need to be updated accordingly for each new game.
// TODO(pat): Update for 2024.
//assert.Equal(
// t,
// matchResult.RedScore.Summarize(matchResult.BlueScore).Score,
// matchResult.BlueScore.Summarize(matchResult.RedScore).Score,
//)
assert.Equal(
t,
matchResult.RedScore.Summarize(matchResult.BlueScore).Score,
matchResult.BlueScore.Summarize(matchResult.RedScore).Score,
)

err = web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
match, _ = web.arena.Database.GetMatchById(1)
// TODO(pat): Update for 2024.
//assert.Equal(t, game.RedWonMatch, match.Status)
assert.Equal(t, game.RedWonMatch, match.Status)

// Swap red and blue and verify that the tie is broken in the other direction.
matchResult.RedScore, matchResult.BlueScore = matchResult.BlueScore, matchResult.RedScore

// Sanity check that the test scores are equal; they will need to be updated accordingly for each new game.
// TODO(pat): Update for 2024.
//assert.Equal(
// t,
// matchResult.RedScore.Summarize(matchResult.BlueScore).Score,
// matchResult.BlueScore.Summarize(matchResult.RedScore).Score,
//)
assert.Equal(
t,
matchResult.RedScore.Summarize(matchResult.BlueScore).Score,
matchResult.BlueScore.Summarize(matchResult.RedScore).Score,
)

err = web.commitMatchScore(match, matchResult, true)
assert.Nil(t, err)
match, _ = web.arena.Database.GetMatchById(1)
// TODO(pat): Update for 2024.
//assert.Equal(t, game.BlueWonMatch, match.Status)
assert.Equal(t, game.BlueWonMatch, match.Status)
}

func TestCommitCards(t *testing.T) {
Expand Down Expand Up @@ -316,12 +306,11 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
readWebsocketType(t, ws, "audienceDisplayMode")
readWebsocketType(t, ws, "allianceStationDisplayMode")
assert.Equal(t, field.PostMatch, web.arena.MatchState)
// TODO(pat): Update for 2024.
//web.arena.RedRealtimeScore.CurrentScore.AutoDockStatuses = [3]bool{false, true, true}
web.arena.RedRealtimeScore.CurrentScore.AmpSpeaker.TeleopAmplifiedSpeakerNotes = 6
web.arena.BlueRealtimeScore.CurrentScore.LeaveStatuses = [3]bool{true, false, true}
ws.Write("commitResults", nil)
readWebsocketMultiple(t, ws, 5) // scorePosted, matchLoad, realtimeScore, allianceStationDisplayMode, scoringStatus
//assert.Equal(t, [3]bool{false, true, true}, web.arena.SavedMatchResult.RedScore.AutoDockStatuses)
assert.Equal(t, 6, web.arena.SavedMatchResult.RedScore.AmpSpeaker.TeleopAmplifiedSpeakerNotes)
assert.Equal(t, [3]bool{true, false, true}, web.arena.SavedMatchResult.BlueScore.LeaveStatuses)
assert.Equal(t, field.PreMatch, web.arena.MatchState)
ws.Write("discardResults", nil)
Expand Down

0 comments on commit 452408c

Please sign in to comment.