Skip to content

Commit

Permalink
Use class dispatcher (not ifs) to select validator
Browse files Browse the repository at this point in the history
  • Loading branch information
thorehusfeldt committed Jan 15, 2024
1 parent d2d9beb commit f5a71e9
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,39 +426,20 @@ def has_constraints_checking(f):

paths = constraint_validators

match validator_type:
case 'input_format':
validators = [
validate.InputValidator(
validator_dispatcher = {
'input_format': validate.InputValidator,
'output_format': validate.AnswerValidator,
'output': validate.OutputValidator
}
validators = [
validator_dispatcher[validator_type](
problem,
path,
skip_double_build_warning=check_constraints,
check_constraints=check_constraints,
)
for path in paths
]
case 'output_format':
validators = [
validate.AnswerValidator(
problem,
path,
skip_double_build_warning=check_constraints,
check_constraints=check_constraints,
)
for path in paths
]
case 'output':
validators = [
validate.OutputValidator(
problem,
path,
skip_double_build_warning=check_constraints,
check_constraints=check_constraints,
)
for path in paths
]
case _:
assert False

bar = ProgressBar(f'Build {validator_type} validators', items=validators)
ok = True
Expand Down

0 comments on commit f5a71e9

Please sign in to comment.