mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Fixed bug with elimination teams not percolating correctly when the outcome of a round is edited.
This commit is contained in:
@@ -113,11 +113,13 @@ func (database *Database) buildEliminationMatchSet(round int, group int, numAlli
|
||||
}
|
||||
var unplayedMatches []*Match
|
||||
for _, match := range matches {
|
||||
// Update the teams in the match if they are not yet set.
|
||||
if match.Red1 == 0 && len(redAlliance) != 0 {
|
||||
// Update the teams in the match if they are not yet set or are incorrect.
|
||||
if len(redAlliance) != 0 && !(teamInAlliance(match.Red1, redAlliance) &&
|
||||
teamInAlliance(match.Red2, redAlliance) && teamInAlliance(match.Red3, redAlliance)) {
|
||||
shuffleRedTeams(&match, redAlliance)
|
||||
database.SaveMatch(&match)
|
||||
} else if match.Blue1 == 0 && len(blueAlliance) != 0 {
|
||||
} else if len(blueAlliance) != 0 && !(teamInAlliance(match.Blue1, blueAlliance) &&
|
||||
teamInAlliance(match.Blue2, blueAlliance) && teamInAlliance(match.Blue3, blueAlliance)) {
|
||||
shuffleBlueTeams(&match, blueAlliance)
|
||||
database.SaveMatch(&match)
|
||||
}
|
||||
@@ -229,3 +231,12 @@ func shuffleBlueTeams(match *Match, alliance []AllianceTeam) {
|
||||
match.Blue2 = alliance[shuffle[1]].TeamId
|
||||
match.Blue3 = alliance[shuffle[2]].TeamId
|
||||
}
|
||||
|
||||
func teamInAlliance(teamId int, alliance []AllianceTeam) bool {
|
||||
for _, allianceTeam := range alliance {
|
||||
if teamId == allianceTeam.TeamId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -649,9 +649,6 @@ func TestEliminationScheduleDetermineWinner(t *testing.T) {
|
||||
assert.Equal(t, 1, winner[0].TeamId)
|
||||
}
|
||||
}
|
||||
db.TruncateAllianceTeams()
|
||||
db.TruncateMatches()
|
||||
db.TruncateMatchResults()
|
||||
}
|
||||
|
||||
func TestEliminationScheduleRemoveUnneededMatches(t *testing.T) {
|
||||
@@ -680,6 +677,51 @@ func TestEliminationScheduleRemoveUnneededMatches(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEliminationScheduleChangePreviousRoundResult(t *testing.T) {
|
||||
clearDb()
|
||||
defer clearDb()
|
||||
db, err := OpenDatabase(testDbPath)
|
||||
assert.Nil(t, err)
|
||||
defer db.Close()
|
||||
|
||||
createTestAlliances(db, 4)
|
||||
_, err = db.UpdateEliminationSchedule(time.Unix(0, 0))
|
||||
assert.Nil(t, err)
|
||||
scoreMatch(db, "SF2-1", "R")
|
||||
scoreMatch(db, "SF2-2", "B")
|
||||
scoreMatch(db, "SF2-3", "R")
|
||||
_, err = db.UpdateEliminationSchedule(time.Unix(0, 0))
|
||||
assert.Nil(t, err)
|
||||
scoreMatch(db, "SF2-3", "B")
|
||||
_, err = db.UpdateEliminationSchedule(time.Unix(0, 0))
|
||||
assert.Nil(t, err)
|
||||
matches, err := db.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
if assert.Equal(t, 9, len(matches)) {
|
||||
assertMatch(t, matches[6], "F-1", 0, 3)
|
||||
assertMatch(t, matches[7], "F-2", 0, 3)
|
||||
assertMatch(t, matches[8], "F-3", 0, 3)
|
||||
}
|
||||
|
||||
scoreMatch(db, "SF1-1", "R")
|
||||
scoreMatch(db, "SF1-2", "R")
|
||||
_, err = db.UpdateEliminationSchedule(time.Unix(0, 0))
|
||||
assert.Nil(t, err)
|
||||
scoreMatch(db, "SF1-2", "B")
|
||||
_, err = db.UpdateEliminationSchedule(time.Unix(0, 0))
|
||||
assert.Nil(t, err)
|
||||
scoreMatch(db, "SF1-3", "B")
|
||||
_, err = db.UpdateEliminationSchedule(time.Unix(0, 0))
|
||||
assert.Nil(t, err)
|
||||
matches, err = db.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
if assert.Equal(t, 9, len(matches)) {
|
||||
assertMatch(t, matches[6], "F-1", 4, 3)
|
||||
assertMatch(t, matches[7], "F-2", 4, 3)
|
||||
assertMatch(t, matches[8], "F-3", 4, 3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEliminationScheduleUnscoredMatch(t *testing.T) {
|
||||
clearDb()
|
||||
defer clearDb()
|
||||
|
||||
Reference in New Issue
Block a user