mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
add Cell tester + FIX: west setter for Cell class
This commit is contained in:
+4
-1
@@ -7,7 +7,6 @@ requires-python = ">=3.10"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"numpy>=2.2.6",
|
"numpy>=2.2.6",
|
||||||
"pydantic>=2.12.5",
|
"pydantic>=2.12.5",
|
||||||
"pytest>=9.0.2",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -15,8 +14,12 @@ dependencies = [
|
|||||||
dev = [
|
dev = [
|
||||||
"mypy>=1.19.1",
|
"mypy>=1.19.1",
|
||||||
"flake8>=7.3.0",
|
"flake8>=7.3.0",
|
||||||
|
"pytest>=9.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.10"
|
python_version = "3.10"
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
pythonpath = ["src"]
|
||||||
|
|||||||
+2
-17
@@ -41,25 +41,10 @@ class Cell(BaseModel):
|
|||||||
return self.value & 4 == 4
|
return self.value & 4 == 4
|
||||||
|
|
||||||
def set_west(self, is_wall: bool) -> None:
|
def set_west(self, is_wall: bool) -> None:
|
||||||
if (not is_wall and self.value | 8 == 15) or (
|
if (not is_wall and self.value | 7 == 15) or (
|
||||||
is_wall and self.value | 8 != 15
|
is_wall and self.value | 7 != 15
|
||||||
):
|
):
|
||||||
self.value = self.value ^ (8)
|
self.value = self.value ^ (8)
|
||||||
|
|
||||||
def get_west(self) -> bool:
|
def get_west(self) -> bool:
|
||||||
return self.value & 8 == 8
|
return self.value & 8 == 8
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
c = Cell(value=1)
|
|
||||||
print(c.get_north())
|
|
||||||
c.set_north(True)
|
|
||||||
print(c.get_north())
|
|
||||||
c.set_north(True)
|
|
||||||
print(c.get_north())
|
|
||||||
c.set_north(False)
|
|
||||||
print(c.get_north())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import math
|
|||||||
|
|
||||||
class MazeGenerator(ABC):
|
class MazeGenerator(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@classmethod
|
|
||||||
def generator(
|
def generator(
|
||||||
cls, height: int, width: int
|
self, height: int, width: int
|
||||||
) -> Generator[np.ndarray, None, np.ndarray]: ...
|
) -> Generator[np.ndarray, None, np.ndarray]: ...
|
||||||
|
|
||||||
|
|
||||||
@@ -63,9 +62,8 @@ class Kruskal(MazeGenerator):
|
|||||||
base_set += set
|
base_set += set
|
||||||
sets.remove(set)
|
sets.remove(set)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def generator(
|
def generator(
|
||||||
cls, height: int, width: int
|
self, height: int, width: int
|
||||||
) -> Generator[np.ndarray, None, np.ndarray]:
|
) -> Generator[np.ndarray, None, np.ndarray]:
|
||||||
sets = [[i] for i in range(height * width)]
|
sets = [[i] for i in range(height * width)]
|
||||||
walls = []
|
walls = []
|
||||||
@@ -77,13 +75,13 @@ class Kruskal(MazeGenerator):
|
|||||||
walls += [(w + (width * h), w + (width * h) + width)]
|
walls += [(w + (width * h), w + (width * h) + width)]
|
||||||
np.random.shuffle(walls)
|
np.random.shuffle(walls)
|
||||||
|
|
||||||
yield cls.walls_to_maze(walls, height, width)
|
yield self.walls_to_maze(walls, height, width)
|
||||||
for wall in walls:
|
for wall in walls:
|
||||||
if not cls.is_in_same_set(sets, wall):
|
if not self.is_in_same_set(sets, wall):
|
||||||
cls.merge_sets(sets, wall)
|
self.merge_sets(sets, wall)
|
||||||
walls.remove(wall)
|
walls.remove(wall)
|
||||||
yield cls.walls_to_maze(walls, height, width)
|
yield self.walls_to_maze(walls, height, width)
|
||||||
return cls.walls_to_maze(walls, height, width)
|
return self.walls_to_maze(walls, height, width)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -4,5 +4,4 @@ from .Maze import Maze
|
|||||||
|
|
||||||
class MazeSolver(ABC):
|
class MazeSolver(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@classmethod
|
def solve(self, maze: Maze) -> str: ...
|
||||||
def solve(cls, maze: Maze) -> str: ...
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import pytest
|
||||||
|
from amaz_lib.Cell import Cell
|
||||||
|
|
||||||
|
|
||||||
|
def test_cell_setter_getter() -> None:
|
||||||
|
cell = Cell(value=0)
|
||||||
|
|
||||||
|
cell.set_north(True)
|
||||||
|
assert cell.get_north() is True
|
||||||
|
cell.set_north(False)
|
||||||
|
assert cell.get_north() is False
|
||||||
|
|
||||||
|
cell.set_est(True)
|
||||||
|
assert cell.get_est() is True
|
||||||
|
cell.set_est(False)
|
||||||
|
assert cell.get_est() is False
|
||||||
|
|
||||||
|
cell.set_south(True)
|
||||||
|
assert cell.get_south() is True
|
||||||
|
cell.set_south(False)
|
||||||
|
assert cell.get_south() is False
|
||||||
|
|
||||||
|
cell.set_west(True)
|
||||||
|
assert cell.get_west() is True
|
||||||
|
cell.set_west(False)
|
||||||
|
assert cell.get_west() is False
|
||||||
|
|
||||||
|
cell.set_value(8)
|
||||||
|
assert cell.get_value() == 8
|
||||||
|
cell.set_value(0)
|
||||||
|
assert cell.get_value() == 0
|
||||||
@@ -14,26 +14,26 @@ dependencies = [
|
|||||||
{ name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
|
{ name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
|
||||||
{ name = "numpy", version = "2.4.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
|
{ name = "numpy", version = "2.4.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
|
||||||
{ name = "pydantic" },
|
{ name = "pydantic" },
|
||||||
{ name = "pytest" },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dev-dependencies]
|
[package.dev-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
{ name = "flake8" },
|
{ name = "flake8" },
|
||||||
{ name = "mypy" },
|
{ name = "mypy" },
|
||||||
|
{ name = "pytest" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "numpy", specifier = ">=2.2.6" },
|
{ name = "numpy", specifier = ">=2.2.6" },
|
||||||
{ name = "pydantic", specifier = ">=2.12.5" },
|
{ name = "pydantic", specifier = ">=2.12.5" },
|
||||||
{ name = "pytest", specifier = ">=9.0.2" },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.requires-dev]
|
[package.metadata.requires-dev]
|
||||||
dev = [
|
dev = [
|
||||||
{ name = "flake8", specifier = ">=7.3.0" },
|
{ name = "flake8", specifier = ">=7.3.0" },
|
||||||
{ name = "mypy", specifier = ">=1.19.1" },
|
{ name = "mypy", specifier = ">=1.19.1" },
|
||||||
|
{ name = "pytest", specifier = ">=9.0.2" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
Reference in New Issue
Block a user