Added unit tests for cards.

This commit is contained in:
Patrick Fairbank
2014-08-27 13:42:10 -07:00
parent 1da27cab4a
commit 977244f8ba
3 changed files with 71 additions and 1 deletions

View File

@@ -383,6 +383,25 @@ func TestRefereeDisplayWebsocket(t *testing.T) {
readWebsocketType(t, ws, "reload")
assert.Equal(t, 1, len(mainArena.redRealtimeScore.Fouls))
// Test card setting.
cardData := struct {
Alliance string
TeamId int
Card string
}{"red", 256, "yellow"}
ws.Write("card", cardData)
cardData.Alliance = "blue"
cardData.TeamId = 1680
cardData.Card = "red"
ws.Write("card", cardData)
time.Sleep(time.Millisecond * 10) // Allow some time for the command to be processed.
if assert.Equal(t, 1, len(mainArena.redRealtimeScore.Cards)) {
assert.Equal(t, "yellow", mainArena.redRealtimeScore.Cards["256"])
}
if assert.Equal(t, 1, len(mainArena.blueRealtimeScore.Cards)) {
assert.Equal(t, "red", mainArena.blueRealtimeScore.Cards["1680"])
}
// Test match committing.
mainArena.MatchState = POST_MATCH
ws.Write("commitMatch", foulData)

View File

@@ -189,7 +189,7 @@ func TestCommitEliminationTie(t *testing.T) {
match := &Match{Id: 0, Type: "qualification", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5, Blue3: 6}
db.CreateMatch(match)
matchResult := &MatchResult{MatchId: match.Id, RedScore: Score{AutoHighHot: 1}, RedFouls: []Foul{Foul{}}}
CommitMatchScore(match, matchResult)
err = CommitMatchScore(match, matchResult)
assert.Nil(t, err)
match, _ = db.GetMatchById(1)
assert.Equal(t, "T", match.Winner)
@@ -200,6 +200,53 @@ func TestCommitEliminationTie(t *testing.T) {
assert.Equal(t, "B", match.Winner)
}
func TestCommitCards(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
mainArena.Setup()
// Check that a yellow card sticks with a team.
team := &Team{Id: 5}
db.CreateTeam(team)
match := &Match{Id: 0, Type: "qualification", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5, Blue3: 6}
db.CreateMatch(match)
matchResult := &MatchResult{MatchId: match.Id, BlueCards: map[string]string{"5": "yellow"}}
err = CommitMatchScore(match, matchResult)
assert.Nil(t, err)
team, _ = db.GetTeamById(5)
assert.True(t, team.YellowCard)
// Check that editing a match result removes a yellow card from a team.
matchResult = &MatchResult{MatchId: match.Id}
err = CommitMatchScore(match, matchResult)
assert.Nil(t, err)
team, _ = db.GetTeamById(5)
assert.False(t, team.YellowCard)
// Check that a red card causes a yellow card to stick with a team.
matchResult = &MatchResult{MatchId: match.Id, BlueCards: map[string]string{"5": "red"}}
err = CommitMatchScore(match, matchResult)
assert.Nil(t, err)
team, _ = db.GetTeamById(5)
assert.True(t, team.YellowCard)
// Check that a red card in eliminations zeroes out the score.
createTestAlliances(db, 2)
match.Type = "elimination"
db.SaveMatch(match)
*matchResult = buildTestMatchResult(match.Id, 10)
matchResult.RedCards = map[string]string{"1": "red"}
err = CommitMatchScore(match, matchResult)
assert.Nil(t, err)
assert.Equal(t, 0, matchResult.RedScoreSummary().Score)
assert.Equal(t, 593, matchResult.BlueScoreSummary().Score)
}
func TestMatchPlayWebsocketCommands(t *testing.T) {
clearDb()
defer clearDb()

View File

@@ -20,6 +20,7 @@ func TestSetupAllianceSelection(t *testing.T) {
eventSettings, _ = db.GetEventSettings()
eventSettings.NumElimAlliances = 15
eventSettings.SelectionRound3Order = "L"
mainArena.Setup()
for i := 1; i <= 10; i++ {
db.CreateRanking(&Ranking{TeamId: 100 + i, Rank: i})
}
@@ -79,6 +80,7 @@ func TestSetupAllianceSelection(t *testing.T) {
assert.Contains(t, recorder.Body.String(), ">110<")
// Finalize alliance selection.
db.CreateTeam(&Team{Id: 254, YellowCard: true})
recorder = postHttpResponse("/setup/alliance_selection/finalize", "startTime=2014-01-01 01:00:00 PM")
assert.Equal(t, 302, recorder.Code)
alliances, err := db.GetAllAlliances()
@@ -91,6 +93,8 @@ func TestSetupAllianceSelection(t *testing.T) {
matches, err := db.GetMatchesByType("elimination")
assert.Nil(t, err)
assert.Equal(t, 6, len(matches))
team, _ := db.GetTeamById(254)
assert.False(t, team.YellowCard)
}
func TestSetupAllianceSelectionErrors(t *testing.T) {