mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 05:36:45 -04:00
Add consideration of playoff tiebreakers.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
package bracket
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/tournament"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -96,8 +96,8 @@ func TestBracketUpdateTiming(t *testing.T) {
|
||||
assert.Equal(t, int64(2200), matches[2].Time.Unix())
|
||||
assert.Equal(t, int64(2800), matches[3].Time.Unix())
|
||||
}
|
||||
scoreMatch(database, "SF1-1", model.RedWonMatch)
|
||||
scoreMatch(database, "SF1-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-1", game.RedWonMatch)
|
||||
scoreMatch(database, "SF1-2", game.BlueWonMatch)
|
||||
startTime = time.Unix(5000, 0)
|
||||
assert.Nil(t, bracket.Update(database, &startTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
@@ -133,8 +133,8 @@ func TestBracketUpdateTeamPositions(t *testing.T) {
|
||||
match2.Blue1, match2.Blue3 = 305, match2.Blue1
|
||||
database.UpdateMatch(&match1)
|
||||
database.UpdateMatch(&match2)
|
||||
scoreMatch(database, "SF1-1", model.RedWonMatch)
|
||||
scoreMatch(database, "SF2-1", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-1", game.RedWonMatch)
|
||||
scoreMatch(database, "SF2-1", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
if assert.Equal(t, 4, len(matches)) {
|
||||
@@ -154,8 +154,8 @@ func TestBracketUpdateTeamPositions(t *testing.T) {
|
||||
}
|
||||
|
||||
// Advance them to the finals and verify that the team position updates have been propagated.
|
||||
scoreMatch(database, "SF1-2", model.RedWonMatch)
|
||||
scoreMatch(database, "SF2-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-2", game.RedWonMatch)
|
||||
scoreMatch(database, "SF2-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
if assert.Equal(t, 6, len(matches)) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package bracket
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/tournament"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -50,13 +50,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(matches))
|
||||
|
||||
scoreMatch(database, "1", model.BlueWonMatch)
|
||||
scoreMatch(database, "1", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(matches))
|
||||
|
||||
scoreMatch(database, "2", model.RedWonMatch)
|
||||
scoreMatch(database, "2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -65,13 +65,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assertMatch(t, matches[5], "7", 8, 4)
|
||||
}
|
||||
|
||||
scoreMatch(database, "3", model.RedWonMatch)
|
||||
scoreMatch(database, "3", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 6, len(matches))
|
||||
|
||||
scoreMatch(database, "4", model.BlueWonMatch)
|
||||
scoreMatch(database, "4", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -82,19 +82,19 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assertMatch(t, matches[7], "8", 3, 7)
|
||||
}
|
||||
|
||||
scoreMatch(database, "5", model.BlueWonMatch)
|
||||
scoreMatch(database, "5", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 8, len(matches))
|
||||
|
||||
scoreMatch(database, "6", model.BlueWonMatch)
|
||||
scoreMatch(database, "6", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 8, len(matches))
|
||||
|
||||
scoreMatch(database, "7", model.BlueWonMatch)
|
||||
scoreMatch(database, "7", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -102,7 +102,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assertMatch(t, matches[8], "9", 8, 2)
|
||||
}
|
||||
|
||||
scoreMatch(database, "8", model.RedWonMatch)
|
||||
scoreMatch(database, "8", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -111,13 +111,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assertMatch(t, matches[10], "12", 4, 3)
|
||||
}
|
||||
|
||||
scoreMatch(database, "9", model.RedWonMatch)
|
||||
scoreMatch(database, "9", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 11, len(matches))
|
||||
|
||||
scoreMatch(database, "10", model.RedWonMatch)
|
||||
scoreMatch(database, "10", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -126,13 +126,13 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assertMatch(t, matches[11], "12", 4, 3)
|
||||
}
|
||||
|
||||
scoreMatch(database, "11", model.BlueWonMatch)
|
||||
scoreMatch(database, "11", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 12, len(matches))
|
||||
|
||||
scoreMatch(database, "12", model.RedWonMatch)
|
||||
scoreMatch(database, "12", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -140,7 +140,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assertMatch(t, matches[12], "13", 3, 7)
|
||||
}
|
||||
|
||||
scoreMatch(database, "13", model.BlueWonMatch)
|
||||
scoreMatch(database, "13", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -152,7 +152,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assert.Equal(t, 0, bracket.Winner())
|
||||
assert.Equal(t, 0, bracket.Finalist())
|
||||
|
||||
scoreMatch(database, "F-1", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-1", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -161,7 +161,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assert.Equal(t, 0, bracket.Winner())
|
||||
assert.Equal(t, 0, bracket.Finalist())
|
||||
|
||||
scoreMatch(database, "F-2", model.RedWonMatch)
|
||||
scoreMatch(database, "F-2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -172,7 +172,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assert.Equal(t, 0, bracket.Winner())
|
||||
assert.Equal(t, 0, bracket.Finalist())
|
||||
|
||||
scoreMatch(database, "F-3", model.TieMatch)
|
||||
scoreMatch(database, "F-3", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -183,7 +183,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assert.Equal(t, 0, bracket.Winner())
|
||||
assert.Equal(t, 0, bracket.Finalist())
|
||||
|
||||
scoreMatch(database, "F-4", model.TieMatch)
|
||||
scoreMatch(database, "F-4", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -194,7 +194,7 @@ func TestDoubleEliminationProgression(t *testing.T) {
|
||||
assert.Equal(t, 0, bracket.Winner())
|
||||
assert.Equal(t, 0, bracket.Finalist())
|
||||
|
||||
scoreMatch(database, "F-5", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-5", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -215,7 +215,7 @@ func TestDoubleEliminationTie(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(matches))
|
||||
|
||||
scoreMatch(database, "1", model.TieMatch)
|
||||
scoreMatch(database, "1", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -223,7 +223,7 @@ func TestDoubleEliminationTie(t *testing.T) {
|
||||
assertMatch(t, matches[4], "1-2", 1, 8)
|
||||
}
|
||||
|
||||
scoreMatch(database, "1-2", model.TieMatch)
|
||||
scoreMatch(database, "1-2", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -231,7 +231,7 @@ func TestDoubleEliminationTie(t *testing.T) {
|
||||
assertMatch(t, matches[5], "1-3", 1, 8)
|
||||
}
|
||||
|
||||
scoreMatch(database, "1-3", model.RedWonMatch)
|
||||
scoreMatch(database, "1-3", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -249,13 +249,13 @@ func TestDoubleEliminationChangeResult(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(matches))
|
||||
|
||||
scoreMatch(database, "1", model.BlueWonMatch)
|
||||
scoreMatch(database, "1", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(matches))
|
||||
|
||||
scoreMatch(database, "2", model.RedWonMatch)
|
||||
scoreMatch(database, "2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -264,12 +264,12 @@ func TestDoubleEliminationChangeResult(t *testing.T) {
|
||||
assertMatch(t, matches[5], "7", 8, 4)
|
||||
}
|
||||
|
||||
scoreMatch(database, "2", model.MatchNotPlayed)
|
||||
scoreMatch(database, "2", game.MatchNotPlayed)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 4, len(matches))
|
||||
|
||||
scoreMatch(database, "2", model.BlueWonMatch)
|
||||
scoreMatch(database, "2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -8,6 +8,7 @@ package bracket
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"strconv"
|
||||
)
|
||||
@@ -266,9 +267,9 @@ func (matchup *Matchup) update(database *model.Database) error {
|
||||
}
|
||||
|
||||
// Check who won.
|
||||
if match.Status == model.RedWonMatch {
|
||||
if match.Status == game.RedWonMatch {
|
||||
matchup.RedAllianceWins++
|
||||
} else if match.Status == model.BlueWonMatch {
|
||||
} else if match.Status == game.BlueWonMatch {
|
||||
matchup.BlueAllianceWins++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package bracket
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/tournament"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -316,8 +316,8 @@ func TestSingleEliminationPopulatePartialMatch(t *testing.T) {
|
||||
bracket, err := NewSingleEliminationBracket(3)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF2-1", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-1", game.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err := database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -334,14 +334,14 @@ func TestSingleEliminationPopulatePartialMatch(t *testing.T) {
|
||||
bracket, err = NewSingleEliminationBracket(4)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF2-1", model.RedWonMatch)
|
||||
scoreMatch(database, "SF2-2", model.RedWonMatch)
|
||||
scoreMatch(database, "SF2-1", game.RedWonMatch)
|
||||
scoreMatch(database, "SF2-2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(matches))
|
||||
scoreMatch(database, "SF1-1", model.RedWonMatch)
|
||||
scoreMatch(database, "SF1-2", model.RedWonMatch)
|
||||
scoreMatch(database, "SF1-1", game.RedWonMatch)
|
||||
scoreMatch(database, "SF1-2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -361,19 +361,19 @@ func TestSingleEliminationCreateNextRound(t *testing.T) {
|
||||
bracket, err := NewSingleEliminationBracket(4)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF1-1", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-1", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ := database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 4, len(matches))
|
||||
scoreMatch(database, "SF2-1", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-1", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 4, len(matches))
|
||||
scoreMatch(database, "SF1-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 4, len(matches))
|
||||
scoreMatch(database, "SF2-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
if assert.Equal(t, 6, len(matches)) {
|
||||
@@ -390,19 +390,19 @@ func TestSingleEliminationDetermineWinner(t *testing.T) {
|
||||
bracket, err := NewSingleEliminationBracket(2)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "F-1", model.TieMatch)
|
||||
scoreMatch(database, "F-1", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
assert.Equal(t, 0, bracket.Winner())
|
||||
assert.Equal(t, 0, bracket.Finalist())
|
||||
matches, _ := database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 3, len(matches))
|
||||
scoreMatch(database, "F-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 3, len(matches))
|
||||
scoreMatch(database, "F-3", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-3", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.True(t, bracket.IsComplete())
|
||||
assert.Equal(t, 2, bracket.Winner())
|
||||
@@ -418,26 +418,26 @@ func TestSingleEliminationDetermineWinner(t *testing.T) {
|
||||
bracket, err = NewSingleEliminationBracket(2)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "F-1", model.RedWonMatch)
|
||||
scoreMatch(database, "F-1", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 2, len(matches))
|
||||
scoreMatch(database, "F-2", model.TieMatch)
|
||||
scoreMatch(database, "F-2", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 3, len(matches))
|
||||
scoreMatch(database, "F-3", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-3", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 4, len(matches))
|
||||
assert.Equal(t, "F-4", matches[3].DisplayName)
|
||||
scoreMatch(database, "F-4", model.TieMatch)
|
||||
scoreMatch(database, "F-4", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
scoreMatch(database, "F-5", model.RedWonMatch)
|
||||
scoreMatch(database, "F-5", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.True(t, bracket.IsComplete())
|
||||
assert.Equal(t, 1, bracket.Winner())
|
||||
@@ -451,24 +451,24 @@ func TestSingleEliminationDetermineWinner(t *testing.T) {
|
||||
bracket, err = NewSingleEliminationBracket(2)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "F-1", model.TieMatch)
|
||||
scoreMatch(database, "F-1", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 3, len(matches))
|
||||
scoreMatch(database, "F-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 3, len(matches))
|
||||
scoreMatch(database, "F-3", model.TieMatch)
|
||||
scoreMatch(database, "F-3", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
if assert.Equal(t, 4, len(matches)) {
|
||||
assert.Equal(t, "F-4", matches[3].DisplayName)
|
||||
}
|
||||
scoreMatch(database, "F-4", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-4", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.True(t, bracket.IsComplete())
|
||||
database.TruncateAlliances()
|
||||
@@ -484,23 +484,23 @@ func TestSingleEliminationDetermineWinner(t *testing.T) {
|
||||
assert.Equal(t, expectedNumMatches, len(matches))
|
||||
}
|
||||
updateAndAssertSchedule(2, false)
|
||||
scoreMatch(database, "F-1", model.TieMatch)
|
||||
scoreMatch(database, "F-1", game.TieMatch)
|
||||
updateAndAssertSchedule(3, false)
|
||||
scoreMatch(database, "F-2", model.TieMatch)
|
||||
scoreMatch(database, "F-2", game.TieMatch)
|
||||
updateAndAssertSchedule(4, false)
|
||||
scoreMatch(database, "F-3", model.TieMatch)
|
||||
scoreMatch(database, "F-3", game.TieMatch)
|
||||
updateAndAssertSchedule(5, false)
|
||||
scoreMatch(database, "F-4", model.TieMatch)
|
||||
scoreMatch(database, "F-4", game.TieMatch)
|
||||
updateAndAssertSchedule(6, false)
|
||||
scoreMatch(database, "F-5", model.TieMatch)
|
||||
scoreMatch(database, "F-5", game.TieMatch)
|
||||
updateAndAssertSchedule(7, false)
|
||||
scoreMatch(database, "F-6", model.TieMatch)
|
||||
scoreMatch(database, "F-6", game.TieMatch)
|
||||
updateAndAssertSchedule(8, false)
|
||||
scoreMatch(database, "F-7", model.RedWonMatch)
|
||||
scoreMatch(database, "F-7", game.RedWonMatch)
|
||||
updateAndAssertSchedule(8, false)
|
||||
scoreMatch(database, "F-8", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-8", game.BlueWonMatch)
|
||||
updateAndAssertSchedule(9, false)
|
||||
scoreMatch(database, "F-9", model.RedWonMatch)
|
||||
scoreMatch(database, "F-9", game.RedWonMatch)
|
||||
updateAndAssertSchedule(9, true)
|
||||
}
|
||||
|
||||
@@ -511,19 +511,19 @@ func TestSingleEliminationRemoveUnneededMatches(t *testing.T) {
|
||||
bracket, err := NewSingleEliminationBracket(2)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "F-1", model.RedWonMatch)
|
||||
scoreMatch(database, "F-2", model.TieMatch)
|
||||
scoreMatch(database, "F-1", game.RedWonMatch)
|
||||
scoreMatch(database, "F-2", game.TieMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, _ := database.GetMatchesByType("elimination")
|
||||
assert.Equal(t, 3, len(matches))
|
||||
|
||||
// Check that the third match is deleted if the score is changed.
|
||||
scoreMatch(database, "F-2", model.RedWonMatch)
|
||||
scoreMatch(database, "F-2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.True(t, bracket.IsComplete())
|
||||
|
||||
// Check that the deleted match is recreated if the score is changed.
|
||||
scoreMatch(database, "F-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "F-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
assert.False(t, bracket.IsComplete())
|
||||
matches, _ = database.GetMatchesByType("elimination")
|
||||
@@ -539,23 +539,23 @@ func TestSingleEliminationChangePreviousRoundResult(t *testing.T) {
|
||||
bracket, err := NewSingleEliminationBracket(4)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF2-1", model.RedWonMatch)
|
||||
scoreMatch(database, "SF2-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-1", game.RedWonMatch)
|
||||
scoreMatch(database, "SF2-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF2-3", model.RedWonMatch)
|
||||
scoreMatch(database, "SF2-3", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF2-3", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF2-3", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err := database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 5, len(matches))
|
||||
|
||||
scoreMatch(database, "SF1-1", model.RedWonMatch)
|
||||
scoreMatch(database, "SF1-2", model.RedWonMatch)
|
||||
scoreMatch(database, "SF1-1", game.RedWonMatch)
|
||||
scoreMatch(database, "SF1-2", game.RedWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF1-2", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-2", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
scoreMatch(database, "SF1-3", model.BlueWonMatch)
|
||||
scoreMatch(database, "SF1-3", game.BlueWonMatch)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
@@ -564,7 +564,7 @@ func TestSingleEliminationChangePreviousRoundResult(t *testing.T) {
|
||||
assertMatch(t, matches[7], "F-2", 4, 3)
|
||||
}
|
||||
|
||||
scoreMatch(database, "SF2-3", model.MatchNotPlayed)
|
||||
scoreMatch(database, "SF2-3", game.MatchNotPlayed)
|
||||
assert.Nil(t, bracket.Update(database, &dummyStartTime))
|
||||
matches, err = database.GetMatchesByType("elimination")
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package bracket
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -27,7 +28,7 @@ func assertMatch(t *testing.T, match model.Match, displayName string, redAllianc
|
||||
assert.Equal(t, 100*blueAlliance+3, match.Blue3)
|
||||
}
|
||||
|
||||
func scoreMatch(database *model.Database, displayName string, winner model.MatchStatus) {
|
||||
func scoreMatch(database *model.Database, displayName string, winner game.MatchStatus) {
|
||||
match, _ := database.GetMatchByName("elimination", displayName)
|
||||
match.Status = winner
|
||||
database.UpdateMatch(match)
|
||||
|
||||
@@ -378,12 +378,12 @@ func TestLoadNextMatch(t *testing.T) {
|
||||
|
||||
arena.Database.CreateTeam(&model.Team{Id: 1114})
|
||||
practiceMatch1 := model.Match{Type: "practice", DisplayName: "1"}
|
||||
practiceMatch2 := model.Match{Type: "practice", DisplayName: "2", Status: model.RedWonMatch}
|
||||
practiceMatch2 := model.Match{Type: "practice", DisplayName: "2", Status: game.RedWonMatch}
|
||||
practiceMatch3 := model.Match{Type: "practice", DisplayName: "3"}
|
||||
arena.Database.CreateMatch(&practiceMatch1)
|
||||
arena.Database.CreateMatch(&practiceMatch2)
|
||||
arena.Database.CreateMatch(&practiceMatch3)
|
||||
qualificationMatch1 := model.Match{Type: "qualification", DisplayName: "1", Status: model.BlueWonMatch}
|
||||
qualificationMatch1 := model.Match{Type: "qualification", DisplayName: "1", Status: game.BlueWonMatch}
|
||||
qualificationMatch2 := model.Match{Type: "qualification", DisplayName: "2"}
|
||||
arena.Database.CreateMatch(&qualificationMatch1)
|
||||
arena.Database.CreateMatch(&qualificationMatch2)
|
||||
@@ -392,7 +392,7 @@ func TestLoadNextMatch(t *testing.T) {
|
||||
assert.Equal(t, 0, arena.CurrentMatch.Id)
|
||||
err := arena.SubstituteTeam(1114, "R1")
|
||||
assert.Nil(t, err)
|
||||
arena.CurrentMatch.Status = model.TieMatch
|
||||
arena.CurrentMatch.Status = game.TieMatch
|
||||
err = arena.LoadNextMatch()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, arena.CurrentMatch.Id)
|
||||
@@ -405,12 +405,12 @@ func TestLoadNextMatch(t *testing.T) {
|
||||
err = arena.LoadNextMatch()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, practiceMatch1.Id, arena.CurrentMatch.Id)
|
||||
practiceMatch1.Status = model.RedWonMatch
|
||||
practiceMatch1.Status = game.RedWonMatch
|
||||
arena.Database.UpdateMatch(&practiceMatch1)
|
||||
err = arena.LoadNextMatch()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, practiceMatch3.Id, arena.CurrentMatch.Id)
|
||||
practiceMatch3.Status = model.BlueWonMatch
|
||||
practiceMatch3.Status = game.BlueWonMatch
|
||||
arena.Database.UpdateMatch(&practiceMatch3)
|
||||
err = arena.LoadNextMatch()
|
||||
assert.Nil(t, err)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package field
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -118,9 +119,9 @@ func setMatch(database *model.Database, match *model.Match, matchTime time.Time,
|
||||
match.Time = matchTime
|
||||
match.StartedAt = startedAt
|
||||
if isComplete {
|
||||
match.Status = model.TieMatch
|
||||
match.Status = game.TieMatch
|
||||
} else {
|
||||
match.Status = model.MatchNotPlayed
|
||||
match.Status = game.MatchNotPlayed
|
||||
}
|
||||
_ = database.UpdateMatch(match)
|
||||
}
|
||||
|
||||
@@ -11,13 +11,6 @@ type Score struct {
|
||||
EndgamePoints int
|
||||
}
|
||||
|
||||
type ScoreSummary struct {
|
||||
AutoPoints int
|
||||
TeleopPoints int
|
||||
EndgamePoints int
|
||||
Score int
|
||||
}
|
||||
|
||||
// Calculates and returns the summary fields used for ranking and display.
|
||||
func (score *Score) Summarize() *ScoreSummary {
|
||||
summary := new(ScoreSummary)
|
||||
|
||||
38
game/score_summary.go
Normal file
38
game/score_summary.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2022 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Model representing the calculated totals of a match score.
|
||||
|
||||
package game
|
||||
|
||||
type ScoreSummary struct {
|
||||
AutoPoints int
|
||||
TeleopPoints int
|
||||
EndgamePoints int
|
||||
Score int
|
||||
}
|
||||
|
||||
type MatchStatus string
|
||||
|
||||
const (
|
||||
RedWonMatch MatchStatus = "R"
|
||||
BlueWonMatch MatchStatus = "B"
|
||||
TieMatch MatchStatus = "T"
|
||||
MatchNotPlayed MatchStatus = ""
|
||||
)
|
||||
|
||||
// Determines the winner of the match given the score summaries for both alliances.
|
||||
func DetermineMatchStatus(redScoreSummary, blueScoreSummary *ScoreSummary) MatchStatus {
|
||||
return comparePoints(redScoreSummary.Score, blueScoreSummary.Score)
|
||||
}
|
||||
|
||||
// Helper method to compare the red and blue alliance point totals and return the appropriate MatchStatus.
|
||||
func comparePoints(redPoints, bluePoints int) MatchStatus {
|
||||
if redPoints > bluePoints {
|
||||
return RedWonMatch
|
||||
}
|
||||
if redPoints < bluePoints {
|
||||
return BlueWonMatch
|
||||
}
|
||||
return TieMatch
|
||||
}
|
||||
21
game/score_summary_test.go
Normal file
21
game/score_summary_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2022 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
|
||||
package game
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScoreSummaryDetermineMatchStatus(t *testing.T) {
|
||||
redScoreSummary := &ScoreSummary{Score: 10}
|
||||
blueScoreSummary := &ScoreSummary{Score: 10}
|
||||
assert.Equal(t, TieMatch, DetermineMatchStatus(redScoreSummary, blueScoreSummary))
|
||||
|
||||
redScoreSummary.Score = 11
|
||||
assert.Equal(t, RedWonMatch, DetermineMatchStatus(redScoreSummary, blueScoreSummary))
|
||||
|
||||
blueScoreSummary.Score = 12
|
||||
assert.Equal(t, BlueWonMatch, DetermineMatchStatus(redScoreSummary, blueScoreSummary))
|
||||
}
|
||||
@@ -7,6 +7,7 @@ package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -36,18 +37,9 @@ type Match struct {
|
||||
Blue3IsSurrogate bool
|
||||
StartedAt time.Time
|
||||
ScoreCommittedAt time.Time
|
||||
Status MatchStatus
|
||||
Status game.MatchStatus
|
||||
}
|
||||
|
||||
type MatchStatus string
|
||||
|
||||
const (
|
||||
RedWonMatch MatchStatus = "R"
|
||||
BlueWonMatch MatchStatus = "B"
|
||||
TieMatch MatchStatus = "T"
|
||||
MatchNotPlayed MatchStatus = ""
|
||||
)
|
||||
|
||||
var elimRoundNames = map[int]string{1: "F", 2: "SF", 4: "QF", 8: "EF"}
|
||||
|
||||
func (database *Database) CreateMatch(match *Match) error {
|
||||
@@ -128,7 +120,7 @@ func (database *Database) GetMatchesByType(matchType string) ([]Match, error) {
|
||||
}
|
||||
|
||||
func (match *Match) IsComplete() bool {
|
||||
return match.Status != MatchNotPlayed
|
||||
return match.Status != game.MatchNotPlayed
|
||||
}
|
||||
|
||||
func (match *Match) CapitalizedType() string {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -23,7 +24,7 @@ func TestMatchCrud(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
match := Match{0, "qualification", "254", time.Now().UTC(), 0, 0, 0, 0, 0, 1, false, 2, false, 3, false, 4, false,
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), game.MatchNotPlayed}
|
||||
db.CreateMatch(&match)
|
||||
match2, err := db.GetMatchById(1)
|
||||
assert.Nil(t, err)
|
||||
@@ -32,7 +33,7 @@ func TestMatchCrud(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, match, *match3)
|
||||
|
||||
match.Status = RedWonMatch
|
||||
match.Status = game.RedWonMatch
|
||||
db.UpdateMatch(&match)
|
||||
match2, err = db.GetMatchById(1)
|
||||
assert.Nil(t, err)
|
||||
@@ -49,7 +50,7 @@ func TestTruncateMatches(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
match := Match{0, "qualification", "254", time.Now().UTC(), 0, 0, 0, 0, 0, 1, false, 2, false, 3, false, 4, false,
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), game.MatchNotPlayed}
|
||||
db.CreateMatch(&match)
|
||||
db.TruncateMatches()
|
||||
match2, err := db.GetMatchById(1)
|
||||
@@ -92,13 +93,13 @@ func TestGetMatchesByType(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
match := Match{0, "qualification", "1", time.Now().UTC(), 0, 0, 0, 0, 0, 1, false, 2, false, 3, false, 4, false,
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), game.MatchNotPlayed}
|
||||
db.CreateMatch(&match)
|
||||
match2 := Match{0, "practice", "1", time.Now().UTC(), 0, 0, 0, 0, 0, 1, false, 2, false, 3, false, 4, false, 5,
|
||||
false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
false, 6, false, time.Now().UTC(), time.Now().UTC(), game.MatchNotPlayed}
|
||||
db.CreateMatch(&match2)
|
||||
match3 := Match{0, "practice", "2", time.Now().UTC(), 0, 0, 0, 0, 0, 1, false, 2, false, 3, false, 4, false, 5,
|
||||
false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
false, 6, false, time.Now().UTC(), time.Now().UTC(), game.MatchNotPlayed}
|
||||
db.CreateMatch(&match3)
|
||||
|
||||
matches, err := db.GetMatchesByType("test")
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestPublishMatches(t *testing.T) {
|
||||
database := setupTestDb(t)
|
||||
|
||||
match1 := model.Match{Type: "qualification", DisplayName: "2", Time: time.Unix(600, 0), Red1: 7, Red2: 8, Red3: 9,
|
||||
Blue1: 10, Blue2: 11, Blue3: 12, Status: model.RedWonMatch}
|
||||
Blue1: 10, Blue2: 11, Blue3: 12, Status: game.RedWonMatch}
|
||||
match2 := model.Match{Type: "elimination", DisplayName: "SF2-2", ElimRound: 2, ElimGroup: 2, ElimInstance: 2}
|
||||
database.CreateMatch(&match1)
|
||||
database.CreateMatch(&match2)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package tournament
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
@@ -85,13 +86,13 @@ func TestCalculateRankings(t *testing.T) {
|
||||
// Sets up a schedule and results that touches on all possible variables.
|
||||
func setupMatchResultsForRankings(database *model.Database) {
|
||||
match1 := model.Match{Type: "qualification", DisplayName: "1", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5,
|
||||
Blue3: 6, Status: model.RedWonMatch, Red2IsSurrogate: true}
|
||||
Blue3: 6, Status: game.RedWonMatch, Red2IsSurrogate: true}
|
||||
database.CreateMatch(&match1)
|
||||
matchResult1 := model.BuildTestMatchResult(match1.Id, 1)
|
||||
database.CreateMatchResult(matchResult1)
|
||||
|
||||
match2 := model.Match{Type: "qualification", DisplayName: "2", Red1: 1, Red2: 3, Red3: 5, Blue1: 2, Blue2: 4,
|
||||
Blue3: 6, Status: model.BlueWonMatch, Red2IsSurrogate: true, Blue3IsSurrogate: true}
|
||||
Blue3: 6, Status: game.BlueWonMatch, Red2IsSurrogate: true, Blue3IsSurrogate: true}
|
||||
database.CreateMatch(&match2)
|
||||
matchResult2 := model.BuildTestMatchResult(match2.Id, 1)
|
||||
matchResult2.BlueScore, matchResult2.RedScore = matchResult2.RedScore, matchResult2.BlueScore
|
||||
@@ -100,7 +101,7 @@ func setupMatchResultsForRankings(database *model.Database) {
|
||||
database.CreateMatchResult(matchResult2)
|
||||
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "3", Red1: 6, Red2: 5, Red3: 4, Blue1: 3, Blue2: 2,
|
||||
Blue3: 1, Status: model.TieMatch, Red3IsSurrogate: true}
|
||||
Blue3: 1, Status: game.TieMatch, Red3IsSurrogate: true}
|
||||
database.CreateMatch(&match3)
|
||||
matchResult3 := model.BuildTestMatchResult(match3.Id, 1)
|
||||
database.CreateMatchResult(matchResult3)
|
||||
@@ -110,19 +111,19 @@ func setupMatchResultsForRankings(database *model.Database) {
|
||||
database.CreateMatchResult(matchResult3)
|
||||
|
||||
match4 := model.Match{Type: "practice", DisplayName: "1", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5,
|
||||
Blue3: 6, Status: model.RedWonMatch}
|
||||
Blue3: 6, Status: game.RedWonMatch}
|
||||
database.CreateMatch(&match4)
|
||||
matchResult4 := model.BuildTestMatchResult(match4.Id, 1)
|
||||
database.CreateMatchResult(matchResult4)
|
||||
|
||||
match5 := model.Match{Type: "elimination", DisplayName: "F-1", Red1: 1, Red2: 2, Red3: 3, Blue1: 4, Blue2: 5,
|
||||
Blue3: 6, Status: model.BlueWonMatch}
|
||||
Blue3: 6, Status: game.BlueWonMatch}
|
||||
database.CreateMatch(&match5)
|
||||
matchResult5 := model.BuildTestMatchResult(match5.Id, 1)
|
||||
database.CreateMatchResult(matchResult5)
|
||||
|
||||
match6 := model.Match{Type: "qualification", DisplayName: "4", Red1: 7, Red2: 8, Red3: 9, Blue1: 10, Blue2: 11,
|
||||
Blue3: 12, Status: model.MatchNotPlayed}
|
||||
Blue3: 12, Status: game.MatchNotPlayed}
|
||||
database.CreateMatch(&match6)
|
||||
matchResult6 := model.BuildTestMatchResult(match6.Id, 1)
|
||||
database.CreateMatchResult(matchResult6)
|
||||
|
||||
@@ -7,6 +7,7 @@ package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -313,7 +314,7 @@ func (web *Web) canResetAllianceSelection() bool {
|
||||
return false
|
||||
}
|
||||
for _, match := range matches {
|
||||
if match.Status != model.MatchNotPlayed {
|
||||
if match.Status != game.MatchNotPlayed {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func TestAllianceSelectionReset(t *testing.T) {
|
||||
assert.NotEmpty(t, matches)
|
||||
|
||||
// Mark a match as played and verify that the alliance selection can no longer be reset.
|
||||
matches[0].Status = model.RedWonMatch
|
||||
matches[0].Status = game.RedWonMatch
|
||||
assert.Nil(t, web.arena.Database.UpdateMatch(&matches[0]))
|
||||
recorder = web.postHttpResponse("/alliance_selection/reset", "")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestRankingsApi(t *testing.T) {
|
||||
ranking2 := RankingWithNickname{*game.TestRanking1(), "ChezyPof"}
|
||||
web.arena.Database.CreateRanking(&ranking1.Ranking)
|
||||
web.arena.Database.CreateRanking(&ranking2.Ranking)
|
||||
web.arena.Database.CreateMatch(&model.Match{Type: "qualification", DisplayName: "29", Status: model.RedWonMatch})
|
||||
web.arena.Database.CreateMatch(&model.Match{Type: "qualification", DisplayName: "29", Status: game.RedWonMatch})
|
||||
web.arena.Database.CreateMatch(&model.Match{Type: "qualification", DisplayName: "30"})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 254, Nickname: "ChezyPof"})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 1114, Nickname: "Simbots"})
|
||||
|
||||
@@ -27,7 +27,7 @@ type MatchPlayListItem struct {
|
||||
Id int
|
||||
DisplayName string
|
||||
Time string
|
||||
Status model.MatchStatus
|
||||
Status game.MatchStatus
|
||||
ColorClass string
|
||||
}
|
||||
|
||||
@@ -413,15 +413,9 @@ func (web *Web) commitMatchScore(match *model.Match, matchResult *model.MatchRes
|
||||
|
||||
// Update and save the match record to the database.
|
||||
match.ScoreCommittedAt = time.Now()
|
||||
redScore := matchResult.RedScoreSummary()
|
||||
blueScore := matchResult.BlueScoreSummary()
|
||||
if redScore.Score > blueScore.Score {
|
||||
match.Status = model.RedWonMatch
|
||||
} else if redScore.Score < blueScore.Score {
|
||||
match.Status = model.BlueWonMatch
|
||||
} else {
|
||||
match.Status = model.TieMatch
|
||||
}
|
||||
redScoreSummary := matchResult.RedScoreSummary()
|
||||
blueScoreSummary := matchResult.BlueScoreSummary()
|
||||
match.Status = game.DetermineMatchStatus(redScoreSummary, blueScoreSummary)
|
||||
err := web.arena.Database.UpdateMatch(match)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -516,7 +510,7 @@ func (list MatchPlayList) Len() int {
|
||||
|
||||
// Helper function to implement the required interface for Sort.
|
||||
func (list MatchPlayList) Less(i, j int) bool {
|
||||
return list[i].Status == model.MatchNotPlayed && list[j].Status != model.MatchNotPlayed
|
||||
return list[i].Status == game.MatchNotPlayed && list[j].Status != game.MatchNotPlayed
|
||||
}
|
||||
|
||||
// Helper function to implement the required interface for Sort.
|
||||
@@ -538,11 +532,11 @@ func (web *Web) buildMatchPlayList(matchType string) (MatchPlayList, error) {
|
||||
matchPlayList[i].Time = match.Time.Local().Format("3:04 PM")
|
||||
matchPlayList[i].Status = match.Status
|
||||
switch match.Status {
|
||||
case model.RedWonMatch:
|
||||
case game.RedWonMatch:
|
||||
matchPlayList[i].ColorClass = "danger"
|
||||
case model.BlueWonMatch:
|
||||
case game.BlueWonMatch:
|
||||
matchPlayList[i].ColorClass = "info"
|
||||
case model.TieMatch:
|
||||
case game.TieMatch:
|
||||
matchPlayList[i].ColorClass = "warning"
|
||||
default:
|
||||
matchPlayList[i].ColorClass = ""
|
||||
|
||||
@@ -22,10 +22,10 @@ import (
|
||||
func TestMatchPlay(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: model.RedWonMatch}
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: game.RedWonMatch}
|
||||
match2 := model.Match{Type: "practice", DisplayName: "2"}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: model.BlueWonMatch}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: model.TieMatch}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: game.BlueWonMatch}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: game.TieMatch}
|
||||
match5 := model.Match{Type: "elimination", DisplayName: "SF1-2"}
|
||||
web.arena.Database.CreateMatch(&match1)
|
||||
web.arena.Database.CreateMatch(&match2)
|
||||
@@ -54,7 +54,7 @@ func TestMatchPlayLoad(t *testing.T) {
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 104})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 105})
|
||||
web.arena.Database.CreateTeam(&model.Team{Id: 106})
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: model.RedWonMatch, Red1: 101,
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: game.RedWonMatch, Red1: 101,
|
||||
Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
recorder := web.getHttpResponse("/match_play")
|
||||
@@ -97,7 +97,7 @@ func TestMatchPlayShowResult(t *testing.T) {
|
||||
recorder := web.getHttpResponse("/match_play/1/show_result")
|
||||
assert.Equal(t, 500, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "Invalid match")
|
||||
match := model.Match{Type: "qualification", DisplayName: "1", Status: model.TieMatch}
|
||||
match := model.Match{Type: "qualification", DisplayName: "1", Status: game.TieMatch}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
recorder = web.getHttpResponse(fmt.Sprintf("/match_play/%d/show_result", match.Id))
|
||||
assert.Equal(t, 500, recorder.Code)
|
||||
@@ -139,7 +139,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, matchResult.PlayNumber)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, model.BlueWonMatch, match.Status)
|
||||
assert.Equal(t, game.BlueWonMatch, match.Status)
|
||||
|
||||
matchResult = model.NewMatchResult()
|
||||
matchResult.MatchId = match.Id
|
||||
@@ -148,7 +148,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, matchResult.PlayNumber)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, model.RedWonMatch, match.Status)
|
||||
assert.Equal(t, game.RedWonMatch, match.Status)
|
||||
|
||||
matchResult = model.NewMatchResult()
|
||||
matchResult.MatchId = match.Id
|
||||
@@ -156,7 +156,7 @@ func TestCommitMatch(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, matchResult.PlayNumber)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, model.TieMatch, match.Status)
|
||||
assert.Equal(t, game.TieMatch, match.Status)
|
||||
|
||||
// Verify TBA publishing by checking the log for the expected failure messages.
|
||||
web.arena.TbaClient.BaseUrl = "fakeUrl"
|
||||
@@ -183,7 +183,7 @@ func TestCommitEliminationTie(t *testing.T) {
|
||||
err := web.commitMatchScore(match, matchResult, true)
|
||||
assert.Nil(t, err)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, model.TieMatch, match.Status)
|
||||
assert.Equal(t, game.TieMatch, match.Status)
|
||||
|
||||
tournament.CreateTestAlliances(web.arena.Database, 2)
|
||||
web.arena.CreatePlayoffBracket()
|
||||
@@ -193,7 +193,7 @@ func TestCommitEliminationTie(t *testing.T) {
|
||||
web.arena.Database.UpdateMatch(match)
|
||||
web.commitMatchScore(match, matchResult, true)
|
||||
match, _ = web.arena.Database.GetMatchById(1)
|
||||
assert.Equal(t, model.TieMatch, match.Status) // No elimination tiebreakers.
|
||||
assert.Equal(t, game.TieMatch, match.Status)
|
||||
}
|
||||
|
||||
func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
|
||||
@@ -8,6 +8,7 @@ package web
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
@@ -193,11 +194,11 @@ func (web *Web) buildMatchReviewList(matchType string) ([]MatchReviewListItem, e
|
||||
matchReviewList[i].BlueScore = matchResult.BlueScoreSummary().Score
|
||||
}
|
||||
switch match.Status {
|
||||
case model.RedWonMatch:
|
||||
case game.RedWonMatch:
|
||||
matchReviewList[i].ColorClass = "danger"
|
||||
case model.BlueWonMatch:
|
||||
case game.BlueWonMatch:
|
||||
matchReviewList[i].ColorClass = "info"
|
||||
case model.TieMatch:
|
||||
case game.TieMatch:
|
||||
matchReviewList[i].ColorClass = "warning"
|
||||
default:
|
||||
matchReviewList[i].ColorClass = ""
|
||||
|
||||
@@ -5,6 +5,7 @@ package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena-lite/game"
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/Team254/cheesy-arena-lite/tournament"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -14,10 +15,10 @@ import (
|
||||
func TestMatchReview(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: model.RedWonMatch}
|
||||
match1 := model.Match{Type: "practice", DisplayName: "1", Status: game.RedWonMatch}
|
||||
match2 := model.Match{Type: "practice", DisplayName: "2"}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: model.BlueWonMatch}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: model.TieMatch}
|
||||
match3 := model.Match{Type: "qualification", DisplayName: "1", Status: game.BlueWonMatch}
|
||||
match4 := model.Match{Type: "elimination", DisplayName: "SF1-1", Status: game.TieMatch}
|
||||
match5 := model.Match{Type: "elimination", DisplayName: "SF1-2"}
|
||||
web.arena.Database.CreateMatch(&match1)
|
||||
web.arena.Database.CreateMatch(&match2)
|
||||
@@ -38,7 +39,7 @@ func TestMatchReview(t *testing.T) {
|
||||
func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: model.RedWonMatch, Red1: 1001,
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: game.RedWonMatch, Red1: 1001,
|
||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006, ElimRedAlliance: 1, ElimBlueAlliance: 2}
|
||||
assert.Nil(t, web.arena.Database.CreateMatch(&match))
|
||||
matchResult := model.BuildTestMatchResult(match.Id, 1)
|
||||
@@ -83,7 +84,7 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
||||
func TestMatchReviewCreateNewResult(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: model.RedWonMatch, Red1: 1001,
|
||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: game.RedWonMatch, Red1: 1001,
|
||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006, ElimRedAlliance: 1, ElimBlueAlliance: 2}
|
||||
web.arena.Database.CreateMatch(&match)
|
||||
tournament.CreateTestAlliances(web.arena.Database, 2)
|
||||
@@ -149,7 +150,7 @@ func TestMatchReviewEditCurrentMatch(t *testing.T) {
|
||||
|
||||
// Check that the persisted match is still unedited and that the realtime scores have been updated instead.
|
||||
match2, _ := web.arena.Database.GetMatchById(match.Id)
|
||||
assert.Equal(t, model.MatchNotPlayed, match2.Status)
|
||||
assert.Equal(t, game.MatchNotPlayed, match2.Status)
|
||||
assert.Equal(t, 10, web.arena.RedScore.AutoPoints)
|
||||
assert.Equal(t, 20, web.arena.RedScore.TeleopPoints)
|
||||
assert.Equal(t, 30, web.arena.RedScore.EndgamePoints)
|
||||
|
||||
Reference in New Issue
Block a user