diff --git a/pyproject.toml b/pyproject.toml index 738ccdf..11a0fd9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/src/amaz_lib/Cell.py b/src/amaz_lib/Cell.py index d6675bc..56f0c61 100644 --- a/src/amaz_lib/Cell.py +++ b/src/amaz_lib/Cell.py @@ -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() diff --git a/src/amaz_lib/MazeGenerator.py b/src/amaz_lib/MazeGenerator.py index f83c8f3..5f2f7a2 100644 --- a/src/amaz_lib/MazeGenerator.py +++ b/src/amaz_lib/MazeGenerator.py @@ -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(): diff --git a/src/amaz_lib/MazeSolver.py b/src/amaz_lib/MazeSolver.py index dae0fd0..2efe587 100644 --- a/src/amaz_lib/MazeSolver.py +++ b/src/amaz_lib/MazeSolver.py @@ -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: ... diff --git a/tests/test_Cell.py b/tests/test_Cell.py new file mode 100644 index 0000000..9f37042 --- /dev/null +++ b/tests/test_Cell.py @@ -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 diff --git a/uv.lock b/uv.lock index b4d2e9a..92fbe72 100644 --- a/uv.lock +++ b/uv.lock @@ -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]]