diff --git a/pigeon_magnet_solver/board.py b/pigeon_magnet_solver/board.py index e43a69f..8d7add8 100644 --- a/pigeon_magnet_solver/board.py +++ b/pigeon_magnet_solver/board.py @@ -89,10 +89,13 @@ class Board: old_row = self.rows[row] self.rows[row] = old_row[:col] + value + old_row[col+1:] - def click(self, index: int) -> Self: + def click(self, index: int) -> Self | None: # check is clickable row, col = index // self.width, index % self.width - assert self.rows[row][col] == "1", f"{index} is not clickable!" + + if self.rows[row][col] != "1": + # button is not clickable + return None # get neighbor positions nb_rc = [ diff --git a/tests/test_board.py b/tests/test_board.py index ba596f3..e3d135e 100644 --- a/tests/test_board.py +++ b/tests/test_board.py @@ -1,5 +1,3 @@ -import pytest - from pigeon_magnet_solver.board import Board @@ -13,9 +11,11 @@ def test_default(): assert board.binary_repr == (4, 11, 3), "Wrong binary repr" assert board.solution_class == (1, 3, 2), "Wrong solution class" - assert board.click(4).binary_repr == (4, 14, 3) - assert board.click(5).binary_repr == (4, 11, 6) + assert (board2 := board.click(4)) is not None + assert board2.binary_repr == (4, 14, 3) + + assert (board2 := board.click(5)) is not None + assert board2.binary_repr == (4, 11, 6) for idx in (3, 7): - with pytest.raises(AssertionError): - board.click(idx) + assert board.click(idx) is None