check button clickability
This commit is contained in:
parent
f2dac56953
commit
216cd741d2
2 changed files with 18 additions and 2 deletions
|
@ -39,7 +39,7 @@ class Board:
|
|||
# check buttons
|
||||
length = self.height * self.width
|
||||
assert all(
|
||||
button >= 0 and button < length
|
||||
button in range(length)
|
||||
for button in self.buttons
|
||||
), "Invalid buttons!"
|
||||
|
||||
|
@ -72,5 +72,16 @@ class Board:
|
|||
for column in self.columns
|
||||
)
|
||||
|
||||
def __idx_to_xy(self, index: int) -> tuple[int, int]:
|
||||
return index % self.width, index // self.width
|
||||
|
||||
def is_clickable(self, index: int) -> bool:
|
||||
# check index
|
||||
assert index in self.buttons, f"{index} is not a button!"
|
||||
|
||||
# check is button
|
||||
x, y = self.__idx_to_xy(index)
|
||||
return self.rows[y][x] == "1"
|
||||
|
||||
def click(self, index: int) -> None:
|
||||
pass
|
||||
assert self.is_clickable(index), f"{index} is not clickable!"
|
||||
|
|
|
@ -10,3 +10,8 @@ def test_default():
|
|||
assert board.columns == ("001x", "1101", "110x"), "Wrong columns"
|
||||
assert board.binary_repr == (4, 11, 3), "Wrong binary repr"
|
||||
assert board.solution_class == (1, 3, 2), "Wrong solution class"
|
||||
|
||||
assert board.is_clickable(3) is False, "Button 3 should be inactive"
|
||||
assert board.is_clickable(4) is True, "Button 4 should be active"
|
||||
assert board.is_clickable(5) is True, "Button 5 should be active"
|
||||
assert board.is_clickable(7) is False, "Button 7 should be inactive"
|
||||
|
|
Loading…
Reference in a new issue