don't spam the output on live input runs
This commit is contained in:
parent
af48c1a8fb
commit
8278b91e19
@ -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()
|
||||||
|
if not silent:
|
||||||
printSolution(self.day, 1, check, solution, case)
|
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()
|
||||||
|
if not silent:
|
||||||
printSolution(self.day, 2, check, solution, case)
|
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
|
||||||
|
|||||||
4
main.py
4
main.py
@ -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)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user