mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Refactor to merge Match.Status and Match.Winner fields into one.
This commit is contained in:
@@ -33,12 +33,20 @@ type Match struct {
|
||||
Blue2IsSurrogate bool
|
||||
Blue3 int
|
||||
Blue3IsSurrogate bool
|
||||
Status string
|
||||
StartedAt time.Time
|
||||
ScoreCommittedAt time.Time
|
||||
Winner string
|
||||
Status 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 {
|
||||
@@ -96,6 +104,10 @@ func (database *Database) GetMatchesByType(matchType string) ([]Match, error) {
|
||||
return matches, err
|
||||
}
|
||||
|
||||
func (match *Match) IsComplete() bool {
|
||||
return match.Status != MatchNotPlayed
|
||||
}
|
||||
|
||||
func (match *Match) CapitalizedType() string {
|
||||
if match.Type == "" {
|
||||
return ""
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestMatchCrud(t *testing.T) {
|
||||
db := setupTestDb(t)
|
||||
|
||||
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(), ""}
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
db.CreateMatch(&match)
|
||||
match2, err := db.GetMatchById(1)
|
||||
assert.Nil(t, err)
|
||||
@@ -30,7 +30,7 @@ func TestMatchCrud(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, match, *match3)
|
||||
|
||||
match.Status = "started"
|
||||
match.Status = RedWonMatch
|
||||
db.SaveMatch(&match)
|
||||
match2, err = db.GetMatchById(1)
|
||||
assert.Nil(t, err)
|
||||
@@ -46,7 +46,7 @@ func TestTruncateMatches(t *testing.T) {
|
||||
db := setupTestDb(t)
|
||||
|
||||
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(), ""}
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
db.CreateMatch(&match)
|
||||
db.TruncateMatches()
|
||||
match2, err := db.GetMatchById(1)
|
||||
@@ -87,13 +87,13 @@ func TestGetMatchesByType(t *testing.T) {
|
||||
db := setupTestDb(t)
|
||||
|
||||
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(), ""}
|
||||
5, false, 6, false, time.Now().UTC(), time.Now().UTC(), 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(), ""}
|
||||
false, 6, false, time.Now().UTC(), time.Now().UTC(), 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(), ""}
|
||||
false, 6, false, time.Now().UTC(), time.Now().UTC(), MatchNotPlayed}
|
||||
db.CreateMatch(&match3)
|
||||
|
||||
matches, err := db.GetMatchesByType("test")
|
||||
|
||||
Reference in New Issue
Block a user