Skip to content

Commit

Permalink
WIP ensuring early validation for the static knockout scheduler
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
PeterJCLaw committed Oct 1, 2024
1 parent a4e7799 commit 02aef40
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sr/comp/knockout_scheduler/static_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)

# Collect a list of the teams eligible for the knockouts, in seeded order.
# TODO: deduplicate this vs similar logic in the automated scheduler.
last_league_match_num = self.schedule.n_matches()
self._knockout_seeds = self._get_non_dropped_out_teams(
teams = self._get_non_dropped_out_teams(
MatchNumber(last_league_match_num),
)

def get_team(self, team_ref: StaticMatchTeamReference | None) -> TLA | None:
if not self._played_all_league_matches():
return UNKNOWABLE_TEAM
teams = [UNKNOWABLE_TEAM] * len(teams)
self._knockout_seeds = teams

def get_team(self, team_ref: StaticMatchTeamReference | None) -> TLA | None:
if team_ref is None:
return None

Expand Down
39 changes: 39 additions & 0 deletions tests/test_static_knockout_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from sr.comp.match_period import Match, MatchType
from sr.comp.teams import Team

from .factories import build_match

TLAs = ['AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'HHH', 'III', 'JJJ']


Expand Down Expand Up @@ -205,6 +207,19 @@ def assertMatches(self, expected_matches, **kwargs):

self.assertEqual(e, a, f"Match {i} in the knockouts")

def assertInvalidReference(self, value, matches=()):
config = get_four_team_config()

config['matches'][1][0]['teams'][0] = value

with self.assertRaises(ValueError):
scheduler = get_scheduler(
matches_config=config,
matches=matches,
)

scheduler.add_knockouts()

def test_four_teams_before(self):
# Add an un-scored league match so that we don't appear to have played them all
league_matches = [{'A': Match(
Expand Down Expand Up @@ -448,3 +463,27 @@ def test_two_teams_partial_2(self):
]),
},
)

def test_invalid_position_reference(self):
self.assertInvalidReference('005')

def test_invalid_match_reference(self):
self.assertInvalidReference('050')

def test_invalid_round_reference(self):
self.assertInvalidReference('500')

def test_invalid_position_reference_incomplete_league(self):
# Add an un-scored league match so that we don't appear to have played them all
league_matches = [{'A': build_match(arena='A')}]
self.assertInvalidReference('005', matches=league_matches)

def test_invalid_match_reference_incomplete_league(self):
# Add an un-scored league match so that we don't appear to have played them all
league_matches = [{'A': build_match(arena='A')}]
self.assertInvalidReference('050', matches=league_matches)

def test_invalid_round_reference_incomplete_league(self):
# Add an un-scored league match so that we don't appear to have played them all
league_matches = [{'A': build_match(arena='A')}]
self.assertInvalidReference('500', matches=league_matches)

0 comments on commit 02aef40

Please sign in to comment.