Skip to content

Commit

Permalink
chore: apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDiallo23 committed Jan 22, 2025
1 parent 5157d22 commit f59f495
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def define_constraints(constraint_factory: ConstraintFactory):
unavailability_penalty(constraint_factory),
fair_assignment_count_per_team(constraint_factory),
evenly_confrontation_count(constraint_factory)

]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TeamAssignment(JsonDomainBase):
DayDeserializer,
Field(default=None)]
index_in_day: int
pinned: Annotated[bool, PlanningPin]
pinned: Annotated[bool, PlanningPin, Field(default=False)]
team: Annotated[Team | None,
PlanningVariable,
IdSerializer,
Expand Down
36 changes: 18 additions & 18 deletions python/tournament-scheduling/tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tournament_scheduling.constraints import *

constraint_verifier = ConstraintVerifier.build(define_constraints, TournamentSchedule, TeamAssignment)
# Sample teams and days (equivalent to static variables in Java)

DAY0 = Day(date_index=0)
DAY1 = Day(date_index=1)
DAY2 = Day(date_index=2)
Expand All @@ -12,22 +12,22 @@
TEAM2 = Team(id=2, name="C")

def test_one_assignment_per_day_per_team():
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, pinned=False, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY0, index_in_day=1, pinned=False, team=TEAM0)
assignment3 = TeamAssignment(id=2, day=DAY0, index_in_day=2, pinned=False, team=TEAM0)
assignment4 = TeamAssignment(id=3, day=DAY1, index_in_day=0, pinned=False, team=TEAM1)
assignment5 = TeamAssignment(id=4, day=DAY2, index_in_day=1, pinned=False, team=TEAM1)
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY0, index_in_day=1, team=TEAM0)
assignment3 = TeamAssignment(id=2, day=DAY0, index_in_day=2, team=TEAM0)
assignment4 = TeamAssignment(id=3, day=DAY1, index_in_day=0, team=TEAM1)
assignment5 = TeamAssignment(id=4, day=DAY2, index_in_day=1, team=TEAM1)

(constraint_verifier.verify_that(one_assignment_per_date_per_team)
.given(assignment1, assignment2, assignment3, assignment4, assignment5, TEAM0, TEAM1, TEAM2)
.penalizes_by(3)) # TEAM0 by 2, TEAM1 by 1


def test_unavailability_penalty():
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, pinned=False, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY1, index_in_day=0, pinned=False, team=TEAM1)
assignment3 = TeamAssignment(id=2, day=DAY1, index_in_day=1, pinned=False, team=TEAM1)
assignment4 = TeamAssignment(id=3, day=DAY2, index_in_day=0, pinned=False, team=TEAM1)
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY1, index_in_day=0, team=TEAM1)
assignment3 = TeamAssignment(id=2, day=DAY1, index_in_day=1, team=TEAM1)
assignment4 = TeamAssignment(id=3, day=DAY2, index_in_day=0, team=TEAM1)

unavailability_penalty1 = UnavailabilityPenalty(team=TEAM0, day=DAY0)
unavailability_penalty2 = UnavailabilityPenalty(team=TEAM1, day=DAY1)
Expand All @@ -38,10 +38,10 @@ def test_unavailability_penalty():


def test_fair_assignment_count_per_team():
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, pinned=False, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY1, index_in_day=0, pinned=False, team=TEAM1)
assignment3 = TeamAssignment(id=2, day=DAY2, index_in_day=0, pinned=False, team=TEAM2)
assignment4 = TeamAssignment(id=3, day=DAY0, index_in_day=0, pinned=False, team=TEAM2)
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY1, index_in_day=0, team=TEAM1)
assignment3 = TeamAssignment(id=2, day=DAY2, index_in_day=0, team=TEAM2)
assignment4 = TeamAssignment(id=3, day=DAY0, index_in_day=0, team=TEAM2)
(constraint_verifier.verify_that(fair_assignment_count_per_team)
.given(assignment1, assignment2, assignment3)
.penalizes_by(0))
Expand All @@ -53,10 +53,10 @@ def test_fair_assignment_count_per_team():


def test_evenly_confrontation_count():
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, pinned=False, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY0, index_in_day=0, pinned=False, team=TEAM1)
assignment3 = TeamAssignment(id=2, day=DAY0, index_in_day=0, pinned=False, team=TEAM2)
assignment4 = TeamAssignment(id=3, day=DAY0, index_in_day=0, pinned=False, team=TEAM2)
assignment1 = TeamAssignment(id=0, day=DAY0, index_in_day=0, team=TEAM0)
assignment2 = TeamAssignment(id=1, day=DAY0, index_in_day=0, team=TEAM1)
assignment3 = TeamAssignment(id=2, day=DAY0, index_in_day=0, team=TEAM2)
assignment4 = TeamAssignment(id=3, day=DAY0, index_in_day=0, team=TEAM2)

(constraint_verifier.verify_that(evenly_confrontation_count)
.given(assignment1, assignment2, assignment3)
Expand Down

0 comments on commit f59f495

Please sign in to comment.