Make executing incomplete tests simpler

This commit is contained in:
2024-12-02 00:43:22 -08:00
parent ae922c5c33
commit 7e548d13c1

View File

@@ -1,6 +1,6 @@
import sys import sys
from time import time
from importlib import import_module from importlib import import_module
from time import time
from advent.errors import InvalidSessionIDError, PuzzleNotFoundError from advent.errors import InvalidSessionIDError, PuzzleNotFoundError
from advent.functions import get_puzzle_input from advent.functions import get_puzzle_input
@@ -29,6 +29,25 @@ def main():
print(f"Solver for day {day} not found") print(f"Solver for day {day} not found")
sys.exit(1) sys.exit(1)
try:
print("Testing part 1 solution...")
start = time()
assert mod.solve_p1(mod.test_input) == mod.test_solution_p1
print(f"Test passed in {time() - start:.3f} seconds")
print("Testing part 2 solution...")
start = time()
assert mod.solve_p2(mod.test_input) == mod.test_solution_p2
print(f"Test passed in {time() - start:.3f} seconds")
except AssertionError:
print("Test failed")
sys.exit(1)
except Exception as exc:
print("Error:", exc)
sys.exit(1)
try: try:
print("Fetching puzzle input...") print("Fetching puzzle input...")
puzzle_input = get_puzzle_input(2024, int(day)) puzzle_input = get_puzzle_input(2024, int(day))
@@ -37,21 +56,11 @@ def main():
sys.exit(1) sys.exit(1)
try: try:
print("Testing part 1 solution...")
start = time()
assert mod.solve_p1(mod.test_input) == mod.test_solution_p1
print(f"Test passed in {time() - start:.3f} seconds")
print("Solving part 1...") print("Solving part 1...")
start = time() start = time()
solution_p1 = mod.solve_p1(puzzle_input) solution_p1 = mod.solve_p1(puzzle_input)
print(f"Part 1 solution: {solution_p1} ({time() - start:.3f} seconds)") print(f"Part 1 solution: {solution_p1} ({time() - start:.3f} seconds)")
print("Testing part 2 solution...")
start = time()
assert mod.solve_p2(mod.test_input) == mod.test_solution_p2
print(f"Test passed in {time() - start:.3f} seconds")
print("Solving part 2...") print("Solving part 2...")
solution_p2 = mod.solve_p2(puzzle_input) solution_p2 = mod.solve_p2(puzzle_input)
print(f"Part 2 solution: {solution_p2} ({time() - start:.3f} seconds)") print(f"Part 2 solution: {solution_p2} ({time() - start:.3f} seconds)")
@@ -60,7 +69,7 @@ def main():
print("Puzzle solver is incomplete. Exiting") print("Puzzle solver is incomplete. Exiting")
sys.exit(1) sys.exit(1)
except exc: except Exception as exc:
print("Error:", exc) print("Error:", exc)
sys.exit(1) sys.exit(1)