updated AOCDay Interface; output exec_time seperately

This commit is contained in:
Stefan Harmuth 2021-12-27 17:33:53 +01:00
parent 117eeec768
commit 5a60b71139

View File

@ -8,13 +8,15 @@ INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')
class AOCDay:
year: int
day: int
input: List[str] # our input is always a list of str/lines
inputs: List[List[Tuple[Any, str]]]
part_func: List[Callable]
def __init__(self, day: int):
def __init__(self, year: int, day: int):
self.day = day
self.year = year
self.part_func = [self.part1, self.part2]
def part1(self) -> Any:
@ -30,7 +32,7 @@ class AOCDay:
answer = None
self._loadInput(input_file)
if not measure_runtime or case_count < len(self.input[part]) - 1:
if not measure_runtime or case_count < len(self.inputs[part]) - 1:
answer = self.part_func[part]()
else:
stopwatch = StopWatch()
@ -63,10 +65,10 @@ class AOCDay:
with open(os.path.join(INPUTS_PATH, filename)) as f:
self.input = f.read().splitlines()
def _downloadInput(self, filename):
def _downloadInput(self, filename: str):
pass
def _submit(self, answer):
def _submit(self, part: int, answer: Any):
pass
def test_part1(self, silent: bool = False) -> bool:
@ -159,27 +161,24 @@ class AOCDay:
def printSolution(day: int, part: int, solution: Any, test: Any = None, test_case: int = 0, exec_time: str = None):
if exec_time is None:
time_output = ""
else:
time_output = " (Average run time: %s)" % exec_time
if test is not None:
print(
"%s (TEST day%d/part%d/case%d): got '%s'; expected '%s'%s"
% ("OK" if test == solution else "FAIL", day, part, test_case, solution, test, time_output)
"%s (TEST day%d/part%d/case%d): got '%s'; expected '%s'"
% ("OK" if test == solution else "FAIL", day, part, test_case, solution, test)
)
else:
print(
"Solution to day %s, part %s: %s%s"
"Solution to day %s, part %s: %s"
% (
day,
part,
solution,
time_output
)
)
if exec_time:
print("Day %s, Part %s - Average run time: %s" % (day, part, exec_time))
def splitLine(line, split_char: str = ',', return_type: Union[Type, List[Type]] = None):
if split_char: