Skip to content

Commit

Permalink
Don't create a break before finals if there are only two alliances.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed May 23, 2024
1 parent d7d8a26 commit 08f9ee6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
10 changes: 6 additions & 4 deletions playoff/single_elimination.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ func newSingleEliminationBracket(numAlliances int) (*Matchup, []breakSpec, error
}

// Define scheduled breaks.
breakSpecs := []breakSpec{
{43, 480, "Field Break"},
{44, 480, "Field Break"},
{45, 480, "Field Break"},
var breakSpecs []breakSpec
if numAlliances > 2 {
// Only create a break before the first finals match if there were preceding matches.
breakSpecs = append(breakSpecs, breakSpec{43, 480, "Field Break"})
}
breakSpecs = append(breakSpecs, breakSpec{44, 480, "Field Break"})
breakSpecs = append(breakSpecs, breakSpec{45, 480, "Field Break"})

return &final, breakSpecs, nil
}
Expand Down
35 changes: 28 additions & 7 deletions playoff/single_elimination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import (
"github.com/Team254/cheesy-arena/model"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

var dummyStartTime = time.Unix(0, 0)

func TestSingleEliminationInitialWith2Alliances(t *testing.T) {
finalMatchup, _, err := newSingleEliminationBracket(2)
finalMatchup, breakSpecs, err := newSingleEliminationBracket(2)
assert.Nil(t, err)
matchSpecs, err := collectMatchSpecs(finalMatchup)
assert.Nil(t, err)
Expand All @@ -29,9 +26,15 @@ func TestSingleEliminationInitialWith2Alliances(t *testing.T) {
matchGroups, err := collectMatchGroups(finalMatchup)
assert.Nil(t, err)
assertMatchGroups(t, matchGroups, "F")

if assert.Equal(t, 2, len(breakSpecs)) {
assert.Equal(t, breakSpec{44, 480, "Field Break"}, breakSpecs[0])
assert.Equal(t, breakSpec{45, 480, "Field Break"}, breakSpecs[1])
}
}

func TestSingleEliminationInitialWith3Alliances(t *testing.T) {
finalMatchup, _, err := newSingleEliminationBracket(3)
finalMatchup, breakSpecs, err := newSingleEliminationBracket(3)
assert.Nil(t, err)
matchSpecs, err := collectMatchSpecs(finalMatchup)
assert.Nil(t, err)
Expand Down Expand Up @@ -66,6 +69,12 @@ func TestSingleEliminationInitialWith3Alliances(t *testing.T) {
matchGroups, err := collectMatchGroups(finalMatchup)
assert.Nil(t, err)
assertMatchGroups(t, matchGroups, "SF2", "F")

if assert.Equal(t, 3, len(breakSpecs)) {
assert.Equal(t, breakSpec{43, 480, "Field Break"}, breakSpecs[0])
assert.Equal(t, breakSpec{44, 480, "Field Break"}, breakSpecs[1])
assert.Equal(t, breakSpec{45, 480, "Field Break"}, breakSpecs[2])
}
}

func TestSingleEliminationInitialWith4Alliances(t *testing.T) {
Expand Down Expand Up @@ -249,7 +258,7 @@ func TestSingleEliminationInitialWith7Alliances(t *testing.T) {
}

func TestSingleEliminationInitialWith8Alliances(t *testing.T) {
finalMatchup, _, err := newSingleEliminationBracket(8)
finalMatchup, breakSpecs, err := newSingleEliminationBracket(8)
assert.Nil(t, err)
matchSpecs, err := collectMatchSpecs(finalMatchup)
assert.Nil(t, err)
Expand Down Expand Up @@ -282,6 +291,12 @@ func TestSingleEliminationInitialWith8Alliances(t *testing.T) {
matchGroups, err := collectMatchGroups(finalMatchup)
assert.Nil(t, err)
assertMatchGroups(t, matchGroups, "QF1", "QF2", "QF3", "QF4", "SF1", "SF2", "F")

if assert.Equal(t, 3, len(breakSpecs)) {
assert.Equal(t, breakSpec{43, 480, "Field Break"}, breakSpecs[0])
assert.Equal(t, breakSpec{44, 480, "Field Break"}, breakSpecs[1])
assert.Equal(t, breakSpec{45, 480, "Field Break"}, breakSpecs[2])
}
}

func TestSingleEliminationInitialWith9Alliances(t *testing.T) {
Expand Down Expand Up @@ -765,7 +780,7 @@ func TestSingleEliminationInitialWith15Alliances(t *testing.T) {
}

func TestSingleEliminationInitialWith16Alliances(t *testing.T) {
finalMatchup, _, err := newSingleEliminationBracket(16)
finalMatchup, breakSpecs, err := newSingleEliminationBracket(16)
assert.Nil(t, err)
matchSpecs, err := collectMatchSpecs(finalMatchup)
assert.Nil(t, err)
Expand Down Expand Up @@ -846,6 +861,12 @@ func TestSingleEliminationInitialWith16Alliances(t *testing.T) {
matchGroups,
"EF1", "EF2", "EF3", "EF4", "EF5", "EF6", "EF7", "EF8", "QF1", "QF2", "QF3", "QF4", "SF1", "SF2", "F",
)

if assert.Equal(t, 3, len(breakSpecs)) {
assert.Equal(t, breakSpec{43, 480, "Field Break"}, breakSpecs[0])
assert.Equal(t, breakSpec{44, 480, "Field Break"}, breakSpecs[1])
assert.Equal(t, breakSpec{45, 480, "Field Break"}, breakSpecs[2])
}
}

func TestSingleEliminationErrors(t *testing.T) {
Expand Down

0 comments on commit 08f9ee6

Please sign in to comment.