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 = [
|
||||
"numpy>=2.2.6",
|
||||
"pydantic>=2.12.5",
|
||||
"pytest>=9.0.2",
|
||||
]
|
||||
|
||||
|
||||
@@ -15,8 +14,12 @@ dependencies = [
|
||||
dev = [
|
||||
"mypy>=1.19.1",
|
||||
"flake8>=7.3.0",
|
||||
"pytest>=9.0.2",
|
||||
]
|
||||
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.10"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
pythonpath = ["src"]
|
||||
|
||||
+2
-17
@@ -41,25 +41,10 @@ class Cell(BaseModel):
|
||||
return self.value & 4 == 4
|
||||
|
||||
def set_west(self, is_wall: bool) -> None:
|
||||
if (not is_wall and self.value | 8 == 15) or (
|
||||
is_wall and self.value | 8 != 15
|
||||
if (not is_wall and self.value | 7 == 15) or (
|
||||
is_wall and self.value | 7 != 15
|
||||
):
|
||||
self.value = self.value ^ (8)
|
||||
|
||||
def get_west(self) -> bool:
|
||||
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):
|
||||
@abstractmethod
|
||||
@classmethod
|
||||
def generator(
|
||||
cls, height: int, width: int
|
||||
self, height: int, width: int
|
||||
) -> Generator[np.ndarray, None, np.ndarray]: ...
|
||||
|
||||
|
||||
@@ -63,9 +62,8 @@ class Kruskal(MazeGenerator):
|
||||
base_set += set
|
||||
sets.remove(set)
|
||||
|
||||
@classmethod
|
||||
def generator(
|
||||
cls, height: int, width: int
|
||||
self, height: int, width: int
|
||||
) -> Generator[np.ndarray, None, np.ndarray]:
|
||||
sets = [[i] for i in range(height * width)]
|
||||
walls = []
|
||||
@@ -77,13 +75,13 @@ class Kruskal(MazeGenerator):
|
||||
walls += [(w + (width * h), w + (width * h) + width)]
|
||||
np.random.shuffle(walls)
|
||||
|
||||
yield cls.walls_to_maze(walls, height, width)
|
||||
yield self.walls_to_maze(walls, height, width)
|
||||
for wall in walls:
|
||||
if not cls.is_in_same_set(sets, wall):
|
||||
cls.merge_sets(sets, wall)
|
||||
if not self.is_in_same_set(sets, wall):
|
||||
self.merge_sets(sets, wall)
|
||||
walls.remove(wall)
|
||||
yield cls.walls_to_maze(walls, height, width)
|
||||
return cls.walls_to_maze(walls, height, width)
|
||||
yield self.walls_to_maze(walls, height, width)
|
||||
return self.walls_to_maze(walls, height, width)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -4,5 +4,4 @@ from .Maze import Maze
|
||||
|
||||
class MazeSolver(ABC):
|
||||
@abstractmethod
|
||||
@classmethod
|
||||
def solve(cls, maze: Maze) -> str: ...
|
||||
def solve(self, 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.4.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" },
|
||||
{ name = "pydantic" },
|
||||
{ name = "pytest" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "flake8" },
|
||||
{ name = "mypy" },
|
||||
{ name = "pytest" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "numpy", specifier = ">=2.2.6" },
|
||||
{ name = "pydantic", specifier = ">=2.12.5" },
|
||||
{ name = "pytest", specifier = ">=9.0.2" },
|
||||
]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [
|
||||
{ name = "flake8", specifier = ">=7.3.0" },
|
||||
{ name = "mypy", specifier = ">=1.19.1" },
|
||||
{ name = "pytest", specifier = ">=9.0.2" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in New Issue
Block a user