From 80432cc6e24803c21128b992613c292666c09534 Mon Sep 17 00:00:00 2001 From: alexo Date: Thu, 28 Dec 2023 00:31:28 +1100 Subject: [PATCH] day17: coverage --- day17/lib/classes.py | 13 ++++++++----- day17/lib/direction.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/day17/lib/classes.py b/day17/lib/classes.py index 2a75138..1c2fa3b 100644 --- a/day17/lib/classes.py +++ b/day17/lib/classes.py @@ -46,16 +46,19 @@ def __init__(self, num_rows: int, num_cols: int, cache_min: int, cache_max: int) ] def add_solution(self, step: Step) -> bool: - """adds solution to cache""" + """adds solution to cache returns whether an improvement was made""" tile_cache = self.cache[step.row][step.col] existing_item = tile_cache[step.direction, step.consecutive_steps] if existing_item is None: tile_cache[step.direction, step.consecutive_steps] = step return True + # due to the way that we run in BFS, we shouldn't be getting + # into this branch if step.total_cost < existing_item.total_cost: - tile_cache[step.direction, step.consecutive_steps] = step - return True + raise AssertionError("this shouldn't be possible") + # tile_cache[step.direction, step.consecutive_steps] = step + # return True return False @@ -114,7 +117,7 @@ def solve(self) -> Step: if (new_step := self.create_step(step, direction)) is not None: steps_to_explore.put(new_step) - raise ValueError("No solution found!") + raise AssertionError("No solution found!") def is_oob(self, row: int, col: int) -> bool: """true if laser is out of bounds""" @@ -169,4 +172,4 @@ def solve(self) -> Step: for direction in ALL_DIRECTIONS: if (new_step := self.create_step(step, direction)) is not None: steps_to_explore.put(new_step) - raise ValueError("No solution found!") + raise AssertionError("No solution found!") diff --git a/day17/lib/direction.py b/day17/lib/direction.py index 5ad449c..68f4a10 100644 --- a/day17/lib/direction.py +++ b/day17/lib/direction.py @@ -21,7 +21,7 @@ def __str__(self) -> str: return "v" elif self == Direction.WEST: return "<" - raise ValueError("invalid value") + raise AssertionError("invalid value") def opposite(self) -> "Direction": int_value = int(self) @@ -36,7 +36,7 @@ def offset(self, row: int, col: int) -> tuple[int, int]: return (row + 1, col) if self == Direction.WEST: return (row, col - 1) - raise ValueError("direction not suppported", self) + raise AssertionError("direction not suppported", self) def offset_list(self, row: int, col: int, size: int = 4) -> list[tuple[int, int]]: offsets = range(1, size + 1) @@ -48,7 +48,7 @@ def offset_list(self, row: int, col: int, size: int = 4) -> list[tuple[int, int] return [(row + i, col) for i in offsets] if self == Direction.WEST: return [(row, col - i) for i in offsets] - raise ValueError("direction not suppported", self) + raise AssertionError("direction not suppported", self) ALL_DIRECTIONS = list(Direction)