don't spam the output on live input runs

This commit is contained in:
Stefan Harmuth 2021-11-21 13:13:16 +01:00
parent af48c1a8fb
commit 8278b91e19
2 changed files with 14 additions and 6 deletions

View File

@ -24,29 +24,37 @@ class AOCDay:
def part2(self) -> Any: def part2(self) -> Any:
pass pass
def test_part1(self) -> bool: def test_part1(self, silent: bool = False) -> bool:
live_input = self.input.copy() live_input = self.input.copy()
for case, solution in enumerate(self.test_solutions_p1): for case, solution in enumerate(self.test_solutions_p1):
with open(os.path.join(INPUTS_PATH, "test_input%02d_1_%d" % (self.day, case))) as f: with open(os.path.join(INPUTS_PATH, "test_input%02d_1_%d" % (self.day, case))) as f:
self.input = f.read().splitlines() self.input = f.read().splitlines()
check = self.part1() check = self.part1()
printSolution(self.day, 1, check, solution, case) if not silent:
printSolution(self.day, 1, check, solution, case)
if check != solution: if check != solution:
if silent:
printSolution(self.day, 1, check, solution, case)
return False return False
self.input = live_input self.input = live_input
return True return True
def test_part2(self) -> bool: def test_part2(self, silent: bool = False) -> bool:
live_input = self.input.copy() live_input = self.input.copy()
for case, solution in enumerate(self.test_solutions_p2): for case, solution in enumerate(self.test_solutions_p2):
with open(os.path.join(INPUTS_PATH, "test_input%02d_2_%d" % (self.day, case))) as f: with open(os.path.join(INPUTS_PATH, "test_input%02d_2_%d" % (self.day, case))) as f:
self.input = f.read().splitlines() self.input = f.read().splitlines()
check = self.part2() check = self.part2()
printSolution(self.day, 2, check, solution, case) if not silent:
printSolution(self.day, 2, check, solution, case)
if check != solution: if check != solution:
if silent:
printSolution(self.day, 2, check, solution, case)
return False return False
self.input = live_input self.input = live_input

View File

@ -41,12 +41,12 @@ for lib in sorted(imported):
day_class = getattr(globals()[lib], "Day")(day) day_class = getattr(globals()[lib], "Day")(day)
if not flags.test: if not flags.test:
if not flags.part or flags.part == 1: if not flags.part or flags.part == 1:
if not day_class.test_part1(): if not day_class.test_part1(silent=True):
print("TEST FAILED! Aborting.") print("TEST FAILED! Aborting.")
sys.exit(1) sys.exit(1)
if not flags.part or flags.part == 2: if not flags.part or flags.part == 2:
if not day_class.test_part2(): if not day_class.test_part2(silent=True):
print("TEST FAILED! Aborting.") print("TEST FAILED! Aborting.")
sys.exit(1) sys.exit(1)