54 lines
2.0 KiB
Python
Executable File
54 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import aoclib
|
|
import importlib
|
|
import os
|
|
|
|
argument_parser = argparse.ArgumentParser()
|
|
argument_parser.add_argument("-d", "--day", help="specify day to process; leave empty for ALL days", type=int)
|
|
argument_parser.add_argument("-t", "--test", help="run test cases", action="store_true", default=False)
|
|
argument_parser.add_argument("-p", "--part", help="run only part x", choices=[1, 2], type=int)
|
|
flags = argument_parser.parse_args()
|
|
|
|
import_day = ""
|
|
if flags.day:
|
|
import_day = "%02d" % flags.day
|
|
|
|
imported = []
|
|
for _, _, files in os.walk(aoclib.BASE_PATH):
|
|
for f in files:
|
|
if f.startswith('day' + import_day) and f.endswith('.py'):
|
|
lib_name = f[:-3]
|
|
globals()[lib_name] = importlib.import_module(lib_name)
|
|
imported.append(lib_name)
|
|
|
|
break
|
|
|
|
for lib in sorted(imported):
|
|
day = int(lib[-2:])
|
|
if not flags.test:
|
|
if not flags.part or flags.part == 1:
|
|
test_part_1 = getattr(globals()[lib], "part1")(test_mode=True)
|
|
test_solution_1 = getattr(globals()[lib], "TEST_SOLUTION_PART1")
|
|
if test_part_1 != test_solution_1:
|
|
print(
|
|
"TEST FAILED for Day %s Part 1: Expected %s; Got %s"
|
|
% (day, test_solution_1, test_part_1)
|
|
)
|
|
|
|
if not flags.part or flags.part == 2:
|
|
test_part_2 = getattr(globals()[lib], "part2")(test_mode=True)
|
|
test_solution_2 = getattr(globals()[lib], "TEST_SOLUTION_PART2")
|
|
if test_part_2 != test_solution_2:
|
|
print(
|
|
"TEST FAILED for Day %s Part 2: Expected %s; Got %s"
|
|
% (day, test_solution_2, test_part_2)
|
|
)
|
|
|
|
if not flags.part or flags.part == 1:
|
|
aoclib.printSolution(day, 1, globals()[lib].part1(test_mode=flags.test), test=flags.test)
|
|
|
|
if not flags.part or flags.part == 2:
|
|
aoclib.printSolution(day, 2, globals()[lib].part2(test_mode=flags.test), test=flags.test)
|