mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Refactor playoff bracket logic to more easily support alternative formats.
This commit is contained in:
36
bracket/test_helpers.go
Normal file
36
bracket/test_helpers.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2022 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Helper methods for use in tests in this package and others.
|
||||
|
||||
package bracket
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func setupTestDb(t *testing.T) *model.Database {
|
||||
return model.SetupTestDb(t, "bracket")
|
||||
}
|
||||
|
||||
func assertMatch(t *testing.T, match model.Match, displayName string, redAlliance int, blueAlliance int) {
|
||||
assert.Equal(t, displayName, match.DisplayName)
|
||||
assert.Equal(t, redAlliance, match.ElimRedAlliance)
|
||||
assert.Equal(t, blueAlliance, match.ElimBlueAlliance)
|
||||
assert.Equal(t, 100*redAlliance+2, match.Red1)
|
||||
assert.Equal(t, 100*redAlliance+1, match.Red2)
|
||||
assert.Equal(t, 100*redAlliance+3, match.Red3)
|
||||
assert.Equal(t, 100*blueAlliance+2, match.Blue1)
|
||||
assert.Equal(t, 100*blueAlliance+1, match.Blue2)
|
||||
assert.Equal(t, 100*blueAlliance+3, match.Blue3)
|
||||
}
|
||||
|
||||
func scoreMatch(database *model.Database, displayName string, winner model.MatchStatus) {
|
||||
match, _ := database.GetMatchByName("elimination", displayName)
|
||||
match.Status = winner
|
||||
database.UpdateMatch(match)
|
||||
database.UpdateAllianceFromMatch(match.ElimRedAlliance, [3]int{match.Red1, match.Red2, match.Red3})
|
||||
database.UpdateAllianceFromMatch(match.ElimBlueAlliance, [3]int{match.Blue1, match.Blue2, match.Blue3})
|
||||
}
|
||||
Reference in New Issue
Block a user