From fd7f79966d25c50cdb9582a3f1cf71bfe5019b78 Mon Sep 17 00:00:00 2001 From: alexo Date: Thu, 28 Dec 2023 00:48:00 +1100 Subject: [PATCH] day18: coverage --- day18/day18a.py | 6 +++--- day18/day18b.py | 2 +- day18/tests/test_day18a.py | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/day18/day18a.py b/day18/day18a.py index 8a06d46..895b6a8 100644 --- a/day18/day18a.py +++ b/day18/day18a.py @@ -22,7 +22,7 @@ class Direction(StrEnum): Left = "L" Right = "R" - def __repr__(self) -> str: + def __repr__(self) -> str: # pragma: no cover return str(self) def __str__(self) -> str: @@ -47,7 +47,7 @@ def generate_offsets( return [Position(position.row + i, position.col) for i in range(1, steps + 1)] if direction == Direction.Up: return [Position(position.row - i, position.col) for i in range(1, steps + 1)] - raise ValueError(f"Direction not supported{direction}") + raise AssertionError(f"Direction not supported{direction}") class Matrix: @@ -92,7 +92,7 @@ def dig_out(self) -> None: while not to_process.empty(): position: Position = to_process.get() if self.is_oob(position): - continue + raise AssertionError("pre-allocated matrix shouldn't cause OOB") if visited[position.row][position.col]: continue if self.contents[position.row][position.col].contents != ".": diff --git a/day18/day18b.py b/day18/day18b.py index 45b0a40..0c0a629 100644 --- a/day18/day18b.py +++ b/day18/day18b.py @@ -47,7 +47,7 @@ def process_command(command: Command, position: Position) -> Position: return Position(position.row, position.col - command.steps) if command.direction == Direction.Up: return Position(position.row - command.steps, position.col) - raise ValueError(f"unsupported directoin {command.direction}") + raise AssertionError(f"unsupported directoin {command.direction}") def calculate_area(positions: list[Position], perimeter: int) -> int: diff --git a/day18/tests/test_day18a.py b/day18/tests/test_day18a.py index 7857940..f264471 100644 --- a/day18/tests/test_day18a.py +++ b/day18/tests/test_day18a.py @@ -7,3 +7,5 @@ def test_day18a() -> None: assert commands[0].steps == 6 and commands[0].direction == Direction.Right assert get_solution(commands) == 62 + + assert str(Direction.Right) == "Right"