Skip to content

Commit

Permalink
Explain each of the implemented checks
Browse files Browse the repository at this point in the history
This makes it easier to understand the intent of these code blocks
as well as enabling non-Python-fluent readers to consider which
checks have been implemented.
  • Loading branch information
PeterJCLaw committed Nov 17, 2024
1 parent a9ff512 commit ae26673
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scoring/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def calculate_scores(self):
return scores

def validate(self, other_data):
# Check that the right districts are specified.
if self._districts.keys() != DISTRICT_SCORE_MAP.keys():
missing = DISTRICT_SCORE_MAP.keys() - self._districts.keys()
extra = self._districts.keys() - DISTRICT_SCORE_MAP.keys()
Expand All @@ -97,6 +98,7 @@ def validate(self, other_data):
code='invalid_districts',
)

# Check that the "highest" pallet is a single, valid colour entry.
bad_highest = {}
for name, district in self._districts.items():
highest = district['highest']
Expand All @@ -111,6 +113,7 @@ def validate(self, other_data):
code='invalid_highest_pallet',
)

# Check that the pallets are valid colours.
bad_pallets = {}
for name, district in self._districts.items():
extra = district['pallet_counts'].keys() - ZONE_COLOURS
Expand All @@ -124,6 +127,8 @@ def validate(self, other_data):
code='invalid_pallets',
)

# Check that the "highest" pallet is accompanied by at least one pallet
# of that colour in the district.
bad_highest2 = {}
for name, district in self._districts.items():
highest = district['highest']
Expand Down Expand Up @@ -151,6 +156,8 @@ def validate(self, other_data):
code='impossible_highest_pallet',
)

# Check that the "highest" pallet is assigned in the case where a
# district has pallets from only one team.
missing_highest = {}
for name, district in self._districts.items():
highest = district['highest']
Expand All @@ -166,6 +173,8 @@ def validate(self, other_data):
code='missing_highest_pallet',
)

# Check that the total number of pallets of each colour across the whole
# arena are less than the expected number.
totals = collections.Counter()
for district in self._districts.values():
totals += district['pallet_counts']
Expand Down

0 comments on commit ae26673

Please sign in to comment.