basic Board class
This commit is contained in:
parent
1e44b979e6
commit
cfe02d65f7
4 changed files with 127 additions and 2 deletions
47
pigeon_magnet_solver/board.py
Normal file
47
pigeon_magnet_solver/board.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(kw_only=True, slots=True)
|
||||
class Board:
|
||||
rows: list[str]
|
||||
buttons: tuple[int, ...]
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
def default_puzzle(cls) -> "Board":
|
||||
return cls(
|
||||
rows=["011", "011", "100", "x1x"],
|
||||
buttons=(3, 4, 5, 7),
|
||||
)
|
||||
|
||||
@property
|
||||
def height(self) -> int:
|
||||
return len(self.rows)
|
||||
|
||||
@property
|
||||
def width(self) -> int:
|
||||
if not self.rows:
|
||||
return 0
|
||||
else:
|
||||
return len(self.rows[0])
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
# check char set
|
||||
chars = {c for c in "".join(self.rows)}
|
||||
assert chars.issubset({"0", "1", "x"}), "Invalid char set!"
|
||||
|
||||
# check defined width
|
||||
assert all(
|
||||
len(row) == self.width
|
||||
for row in self.rows
|
||||
), "Inconsistent width!"
|
||||
|
||||
# check buttons
|
||||
length = self.height * self.width
|
||||
assert all(
|
||||
button >= 0 and button < length
|
||||
for button in self.buttons
|
||||
), "Invalid buttons!"
|
||||
|
||||
def click(self, index: int) -> None:
|
||||
pass
|
71
poetry.lock
generated
71
poetry.lock
generated
|
@ -1,7 +1,74 @@
|
|||
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
|
||||
package = []
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
files = [
|
||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iniconfig"
|
||||
version = "2.0.0"
|
||||
description = "brain-dead simple config-ini parsing"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"},
|
||||
{file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "23.1"
|
||||
description = "Core utilities for Python packages"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"},
|
||||
{file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pluggy"
|
||||
version = "1.2.0"
|
||||
description = "plugin and hook calling mechanisms for python"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"},
|
||||
{file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
dev = ["pre-commit", "tox"]
|
||||
testing = ["pytest", "pytest-benchmark"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest"
|
||||
version = "7.4.0"
|
||||
description = "pytest: simple powerful testing with Python"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "pytest-7.4.0-py3-none-any.whl", hash = "sha256:78bf16451a2eb8c7a2ea98e32dc119fd2aa758f1d5d66dbf0a59d69a3969df32"},
|
||||
{file = "pytest-7.4.0.tar.gz", hash = "sha256:b4bf8c45bd59934ed84001ad51e11b4ee40d40a1229d2c79f9c592b0a3f6bd8a"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
colorama = {version = "*", markers = "sys_platform == \"win32\""}
|
||||
iniconfig = "*"
|
||||
packaging = "*"
|
||||
pluggy = ">=0.12,<2.0"
|
||||
|
||||
[package.extras]
|
||||
testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.11"
|
||||
content-hash = "81b2fa642d7f2d1219cf80112ace12d689d053d81be7f7addb98144d56fc0fb2"
|
||||
content-hash = "1e9ef2f430b03c3b1e90971fa9e6f71d9d89e38a7153abdb2d9a8fb78d8295ad"
|
||||
|
|
|
@ -10,6 +10,9 @@ packages = [{include = "pigeon_magnet_solver"}]
|
|||
python = "^3.11"
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pytest = "^7.4.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
|
8
tests/test_board.py
Normal file
8
tests/test_board.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from pigeon_magnet_solver.board import Board
|
||||
|
||||
|
||||
def test_default():
|
||||
board = Board.default_puzzle
|
||||
|
||||
assert board.width == 3, "Wrong width"
|
||||
assert board.height == 4, "Wrong height"
|
Loading…
Reference in a new issue