mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-29 00:14:34 +02:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 22c44333c1 | |||
| b00ddc7d29 | |||
| e4e8ebfc13 | |||
| 0c20d2d063 | |||
| 96b39fbeea | |||
| 97b35fe3eb | |||
| ac13df160f | |||
| d2d477d1b5 | |||
| 721a7d00b9 | |||
| 6d849a8121 | |||
| a4d55d5692 | |||
| c6c7e6e47e | |||
| 84c4b63a6c | |||
| c14c043575 | |||
| c8a13e9d5c | |||
| 272ccefb52 | |||
| b44cffec2c | |||
| ce584d2ae3 |
@@ -11,12 +11,12 @@ clean:
|
||||
rm -rf __pycache__ .mypy_cache .venv
|
||||
|
||||
lint:
|
||||
uv run flake8 .
|
||||
uv run flake8 . --exclude=.venv
|
||||
uv run mypy . --warn-return-any --warn-unused-ignores --ignore-missing-imports --disallow-untyped-defs --check-untyped-defs
|
||||
|
||||
lint-strict:
|
||||
uv run flake8 .
|
||||
uv run mypy . --strict
|
||||
|
||||
run_test:
|
||||
PYTHONPATH=src uv run python3 test/test_parsing.py
|
||||
run_test_parsing:
|
||||
PYTHONPATH=src uv run pytest tests/test_parsing.py
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
The Randomized Kruskal's Algorithm
|
||||
|
||||
The Randomized Prim's Algorithm
|
||||
|
||||
+17
-1
@@ -1,5 +1,21 @@
|
||||
import os
|
||||
from numpy import ma
|
||||
from src.amaz_lib import MazeGenerator
|
||||
from src.amaz_lib import Maze
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("A-Maze-ing !!!")
|
||||
# try:
|
||||
maze = Maze(maze=None, start=(1, 1), end=(16, 15))
|
||||
for alg in MazeGenerator.Kruskal.kruskal(20, 20):
|
||||
maze.set_maze(alg)
|
||||
os.system("clear")
|
||||
maze.ascii_print()
|
||||
maze.export_maze("test.txt")
|
||||
|
||||
|
||||
# except Exception as err:
|
||||
# print(err)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# This script does not check for errors or malformed files.
|
||||
# It only validates that neighbooring cells sharing a wall have
|
||||
# both the correct encoding.
|
||||
# Usage: python3 output_validator.py output_maze.txt
|
||||
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: python3 {sys.argv[0]} <output_file>")
|
||||
sys.exit(1)
|
||||
|
||||
g = []
|
||||
for line in open(sys.argv[1]):
|
||||
if line.strip() == '':
|
||||
break
|
||||
g.append([int(c, 16) for c in line.strip(' \t\n\r')])
|
||||
|
||||
for r in range(len(g)):
|
||||
for c in range(len(g[0])):
|
||||
v = g[r][c]
|
||||
if not all([(r < 1 or v & 1 == (g[r-1][c] >> 2) & 1),
|
||||
(c >= len(g[0])-1 or (v >> 1) & 1 == (g[r][c+1] >> 3) & 1),
|
||||
(r >= len(g)-1 or (v >> 2) & 1 == g[r+1][c] & 1),
|
||||
(c < 1 or (v >> 3) & 1 == (g[r][c-1] >> 1) & 1)]):
|
||||
print(f'Wrong encoding for ({c},{r})')
|
||||
+4
-5
@@ -7,7 +7,6 @@ requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"numpy>=2.2.6",
|
||||
"pydantic>=2.12.5",
|
||||
"pytest>=9.0.2",
|
||||
]
|
||||
|
||||
|
||||
@@ -15,12 +14,12 @@ dependencies = [
|
||||
dev = [
|
||||
"mypy>=1.19.1",
|
||||
"flake8>=7.3.0",
|
||||
"pytest>=9.0.2",
|
||||
]
|
||||
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.10"
|
||||
exclude = [
|
||||
".venv",
|
||||
"venv",
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
pythonpath = ["src"]
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
from dataclasses import field
|
||||
from os import eventfd_read
|
||||
from typing import Generator
|
||||
import numpy
|
||||
from typing_extensions import Self
|
||||
from pydantic import AfterValidator, BaseModel, Field, model_validator
|
||||
|
||||
from amaz_lib import Maze, MazeGenerator, MazeSolver
|
||||
from amaz_lib.Cell import Cell
|
||||
|
||||
|
||||
class AMazeIng(BaseModel):
|
||||
width: int = Field(ge=3)
|
||||
height: int = Field(ge=3)
|
||||
entry: tuple[int, int]
|
||||
exit: tuple[int, int]
|
||||
output_file: str = Field(min_length=3)
|
||||
perfect: bool = Field(default=True)
|
||||
maze: Maze = Field(default=Maze(maze=numpy.array([])))
|
||||
generator: MazeGenerator
|
||||
solver: MazeSolver
|
||||
|
||||
@model_validator(mode="after")
|
||||
def check_entry_exit(self) -> Self:
|
||||
if self.entry[0] >= self.width or self.entry[1] >= self.height:
|
||||
raise ValueError("Entry coordinates exceed the maze size")
|
||||
if self.exit[0] >= self.width or self.exit[1] >= self.height:
|
||||
raise ValueError("Exit coordinates exceed the maze size")
|
||||
return self
|
||||
|
||||
def generate(self) -> Generator[Maze, None, None]:
|
||||
for array in self.generator.generator(self.height, self.width):
|
||||
self.maze.set_maze(array)
|
||||
yield self.maze
|
||||
|
||||
def solve_path(self) -> str:
|
||||
return self.solver.solve(self.maze)
|
||||
|
||||
def __str__(self) -> str:
|
||||
res = self.maze.__str__()
|
||||
res += "\n"
|
||||
res += f"{self.entry[0]},{self.entry[1]}\n"
|
||||
res += f"{self.exit[0]},{self.exit[1]}\n"
|
||||
res += self.solve_path()
|
||||
res += "\n"
|
||||
return res
|
||||
@@ -5,11 +5,17 @@ class Cell(BaseModel):
|
||||
value: int = Field(ge=0, le=15)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return hex(self.value)
|
||||
return hex(self.value).removeprefix("0x").upper()
|
||||
|
||||
def set_value(self, value: int) -> None:
|
||||
self.value = value
|
||||
|
||||
def get_value(self) -> int:
|
||||
return self.value
|
||||
|
||||
def set_north(self, is_wall: bool) -> None:
|
||||
if (is_wall and self.value | 14 == 15) or (
|
||||
not is_wall and self.value | 14 != 15
|
||||
if (not is_wall and self.value | 14 == 15) or (
|
||||
is_wall and self.value | 14 != 15
|
||||
):
|
||||
self.value = self.value ^ (1)
|
||||
|
||||
@@ -17,8 +23,8 @@ class Cell(BaseModel):
|
||||
return self.value & 1 == 1
|
||||
|
||||
def set_est(self, is_wall: bool) -> None:
|
||||
if (is_wall and self.value | 13 == 15) or (
|
||||
not is_wall and self.value | 13 != 15
|
||||
if (not is_wall and self.value | 13 == 15) or (
|
||||
is_wall and self.value | 13 != 15
|
||||
):
|
||||
self.value = self.value ^ (2)
|
||||
|
||||
@@ -26,8 +32,8 @@ class Cell(BaseModel):
|
||||
return self.value & 2 == 2
|
||||
|
||||
def set_south(self, is_wall: bool) -> None:
|
||||
if (is_wall and self.value | 11 == 15) or (
|
||||
not is_wall and self.value | 11 != 15
|
||||
if (not is_wall and self.value | 11 == 15) or (
|
||||
is_wall and self.value | 11 != 15
|
||||
):
|
||||
self.value = self.value ^ (4)
|
||||
|
||||
@@ -35,25 +41,10 @@ class Cell(BaseModel):
|
||||
return self.value & 4 == 4
|
||||
|
||||
def set_west(self, is_wall: bool) -> None:
|
||||
if (is_wall and self.value | 8 == 15) or (
|
||||
not 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()
|
||||
@@ -0,0 +1,49 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
import numpy
|
||||
from .Cell import Cell
|
||||
from .MazeGenerator import MazeGenerator
|
||||
|
||||
|
||||
@dataclass
|
||||
class Maze:
|
||||
maze: numpy.ndarray
|
||||
|
||||
def get_maze(self) -> numpy.ndarray | None:
|
||||
return self.maze
|
||||
|
||||
def set_maze(self, new_maze: numpy.ndarray) -> None:
|
||||
self.maze = new_maze
|
||||
|
||||
def __str__(self) -> str:
|
||||
if self.maze is None:
|
||||
return "None"
|
||||
res = ""
|
||||
for line in self.maze:
|
||||
for cell in line:
|
||||
res += cell.__str__()
|
||||
res += "\n"
|
||||
return res
|
||||
|
||||
def ascii_print(self) -> None:
|
||||
for line in self.maze:
|
||||
if line is self.maze[0]:
|
||||
for cell in line:
|
||||
print("_", end="")
|
||||
if cell.get_north():
|
||||
print("__", end="")
|
||||
else:
|
||||
print(" ", end="")
|
||||
print()
|
||||
for cell in line:
|
||||
if cell is line[0] and cell.get_west():
|
||||
print("|", end="")
|
||||
if cell.get_south() is True:
|
||||
print("__", end="")
|
||||
else:
|
||||
print(" ", end="")
|
||||
if cell.get_est() is True:
|
||||
print("|", end="")
|
||||
else:
|
||||
print("_", end="")
|
||||
print()
|
||||
@@ -0,0 +1,100 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Generator
|
||||
import numpy as np
|
||||
from .Cell import Cell
|
||||
import math
|
||||
|
||||
|
||||
class MazeGenerator(ABC):
|
||||
@abstractmethod
|
||||
def generator(
|
||||
self, height: int, width: int
|
||||
) -> Generator[np.ndarray, None, np.ndarray]: ...
|
||||
|
||||
|
||||
class Kruskal(MazeGenerator):
|
||||
@staticmethod
|
||||
def walls_to_maze(
|
||||
walls: list[tuple[int, int]], height: int, width: int
|
||||
) -> np.ndarray:
|
||||
maze: np.ndarray = np.array(
|
||||
[[Cell(value=0) for _ in range(width)] for _ in range(height)]
|
||||
)
|
||||
for wall in walls:
|
||||
x, y = wall
|
||||
match y - x:
|
||||
case 1:
|
||||
maze[math.trunc((x / width))][x % width].set_est(True)
|
||||
maze[math.trunc((y / width))][y % width].set_west(True)
|
||||
case width:
|
||||
maze[math.trunc((x / width))][x % width].set_south(True)
|
||||
maze[math.trunc((y / width))][y % width].set_north(True)
|
||||
for x in range(height):
|
||||
for y in range(width):
|
||||
if x == 0:
|
||||
maze[x][y].set_north(True)
|
||||
if x == height - 1:
|
||||
maze[x][y].set_south(True)
|
||||
if y == 0:
|
||||
maze[x][y].set_est(True)
|
||||
if y == width - 1:
|
||||
maze[x][y].set_west(True)
|
||||
return maze
|
||||
|
||||
@staticmethod
|
||||
def is_in_same_set(sets: list[list[int]], wall: tuple[int, int]) -> bool:
|
||||
a, b = wall
|
||||
for set in sets:
|
||||
if a in set and b in set:
|
||||
return True
|
||||
if a in set or b in set:
|
||||
return False
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def merge_sets(sets: list[list[int]], wall: tuple[int, int]) -> None:
|
||||
a, b = wall
|
||||
base_set = None
|
||||
for set in sets:
|
||||
if base_set is None and (a in set or b in set):
|
||||
base_set = set
|
||||
elif base_set and (a in set or b in set):
|
||||
base_set += set
|
||||
sets.remove(set)
|
||||
|
||||
def generator(
|
||||
self, height: int, width: int
|
||||
) -> Generator[np.ndarray, None, np.ndarray]:
|
||||
sets = [[i] for i in range(height * width)]
|
||||
walls = []
|
||||
for h in range(height):
|
||||
for w in range(width - 1):
|
||||
walls += [(w + (width * h), w + (width * h) + 1)]
|
||||
for w in range(width):
|
||||
for h in range(height - 1):
|
||||
walls += [(w + (width * h), w + (width * h) + width)]
|
||||
np.random.shuffle(walls)
|
||||
|
||||
yield self.walls_to_maze(walls, height, width)
|
||||
for wall in walls:
|
||||
if not self.is_in_same_set(sets, wall):
|
||||
self.merge_sets(sets, wall)
|
||||
walls.remove(wall)
|
||||
yield self.walls_to_maze(walls, height, width)
|
||||
return self.walls_to_maze(walls, height, width)
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
for alg in MazeGenerator.Kruskal.kruskal(10, 10):
|
||||
maze = alg
|
||||
# print(maze)
|
||||
# print()
|
||||
print(maze)
|
||||
|
||||
except GeneratorExit as maze:
|
||||
print(maze)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from .Maze import Maze
|
||||
|
||||
|
||||
class MazeSolver(ABC):
|
||||
@abstractmethod
|
||||
def solve(self, maze: Maze) -> str: ...
|
||||
@@ -0,0 +1,8 @@
|
||||
from .Cell import Cell
|
||||
from .Maze import Maze
|
||||
from .MazeGenerator import MazeGenerator
|
||||
from .MazeSolver import MazeSolver
|
||||
|
||||
__version__ = "1.0.0"
|
||||
__author__ = "us"
|
||||
__all__ = ["Cell", "Maze", "MazeGenerator", "MazeSolver"]
|
||||
+89
-10
@@ -1,18 +1,97 @@
|
||||
class DataMaze:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_data(name_file: str) -> str:
|
||||
data = ""
|
||||
def get_file_data(name_file: str) -> str:
|
||||
with open(name_file, "r") as file:
|
||||
data = file.read()
|
||||
if data == "":
|
||||
raise ValueError("The file is empty")
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def transform_data(data: str) -> dict:
|
||||
tmp = data.split("\n")
|
||||
tmp2 = [
|
||||
value.split("=", 1) for value in tmp
|
||||
]
|
||||
data_t = {
|
||||
value[0]: value[1] for value in tmp2
|
||||
}
|
||||
return data_t
|
||||
|
||||
@staticmethod
|
||||
def verif_key_data(data: dict) -> None:
|
||||
key_test = {
|
||||
"WIDTH", "HEIGHT", "ENTRY", "EXIT", "OUTPUT_FILE", "PERFECT"
|
||||
}
|
||||
set_key = {
|
||||
key for key in data.keys()
|
||||
}
|
||||
if len(set_key) != len(key_test):
|
||||
raise KeyError("Missing some data the len do not correspond")
|
||||
res_key = {key for key in set_key if key not in key_test}
|
||||
if len(res_key) != 0:
|
||||
raise KeyError("Some Key "
|
||||
f"do not correspond the keys: {res_key}")
|
||||
|
||||
@staticmethod
|
||||
def convert_values(data: dict):
|
||||
key_int = {"WIDTH", "HEIGHT"}
|
||||
key_tuple = {"ENTRY", "EXIT"}
|
||||
key_bool = {"PERFECT"}
|
||||
res: dict = {}
|
||||
for key in key_int:
|
||||
res.update({key: int(data[key])})
|
||||
for key in key_tuple:
|
||||
res.update({key: DataMaze.convert_tuple(data[key])})
|
||||
for key in key_bool:
|
||||
res.update({key: DataMaze.convert_bool(data[key])})
|
||||
res.update({"OUTPUT_FILE": data["OUTPUT_FILE"]})
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def get_data_maze(name_file: str) -> dict:
|
||||
try:
|
||||
with open(name_file, "r") as file:
|
||||
data = file.read()
|
||||
data_str = DataMaze.get_file_data(name_file)
|
||||
data_dict = DataMaze.transform_data(data_str)
|
||||
DataMaze.verif_key_data(data_dict)
|
||||
data_maze = DataMaze.convert_values(data_dict)
|
||||
return data_maze
|
||||
except FileNotFoundError:
|
||||
print("The file do not exist")
|
||||
finally:
|
||||
return data
|
||||
exit()
|
||||
except PermissionError:
|
||||
print("We dont have the Permission")
|
||||
exit()
|
||||
except ValueError as e:
|
||||
print(f"Error during the convert or the file is empty: {e}")
|
||||
exit()
|
||||
except KeyError as e:
|
||||
print(f"Error on the key in the file: {e}")
|
||||
exit()
|
||||
except IndexError as e:
|
||||
print("In the function transform Data some data cannot "
|
||||
f"be splited by '=' because '=' was not present: {e}")
|
||||
exit()
|
||||
except AttributeError as e:
|
||||
print("Error on the "
|
||||
f"funciton get_data_maze : {e}")
|
||||
exit()
|
||||
|
||||
@staticmethod
|
||||
def transform_data(data: str):
|
||||
pass
|
||||
def convert_tuple(data: str) -> tuple:
|
||||
data_t = data.split(",")
|
||||
if len(data_t) != 2:
|
||||
raise ValueError("There is too much "
|
||||
"argument in the coordinate given")
|
||||
x, y = data_t
|
||||
tup = (int(x), int(y))
|
||||
return tup
|
||||
|
||||
@staticmethod
|
||||
def convert_bool(data: str) -> bool:
|
||||
if data != "True" and data != "False":
|
||||
raise ValueError("This is not True or False")
|
||||
if data == "True":
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
7D53BFD3D57951517D1D
|
||||
3D12C3903BD03AD4178D
|
||||
2BAEBEEEAA92EED547C9
|
||||
2287ED17AAAC5393FFF0
|
||||
6C6951292A87D2AEBD30
|
||||
37D43E8686E93AABAB8C
|
||||
21516D2D47FEE8284049
|
||||
6C7857C3FB9116C696D8
|
||||
751453D6D2AAC57BE970
|
||||
3BA952D17EA83BD05470
|
||||
22AAD2907BAE86967B74
|
||||
2AA83C2EFC69696FBC35
|
||||
686EE96FD7D4783FAD21
|
||||
7ED17ED3D57D3EC52FA0
|
||||
7B943D16FB7BABD3AFC8
|
||||
7407C5297EB82EB84174
|
||||
392D53C6912EE9447E9D
|
||||
62A952BBAAC13EFD7B89
|
||||
3AAC3EC6EABAAD557824
|
||||
66C7C7D7D6C6C7D556CD
|
||||
|
||||
1,1
|
||||
16,15
|
||||
@@ -1,10 +0,0 @@
|
||||
from parsing.Parsing import DataMaze
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("Unit Testing for parsing:")
|
||||
DataMaze.get_data("config.txt")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -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
|
||||
@@ -0,0 +1,31 @@
|
||||
import numpy
|
||||
from amaz_lib.Cell import Cell
|
||||
from amaz_lib.Maze import Maze
|
||||
|
||||
|
||||
def test_maze_setter_getter() -> None:
|
||||
maze = Maze(numpy.array([]))
|
||||
|
||||
test = numpy.array(
|
||||
[
|
||||
[Cell(value=6), Cell(value=8), Cell(value=11)],
|
||||
[Cell(value=6), Cell(value=8), Cell(value=11)],
|
||||
[Cell(value=6), Cell(value=8), Cell(value=11)],
|
||||
]
|
||||
)
|
||||
|
||||
maze.set_maze(test)
|
||||
assert numpy.array_equal(maze.get_maze(), test) == True
|
||||
|
||||
|
||||
def test_maze_str() -> None:
|
||||
test = numpy.array(
|
||||
[
|
||||
[Cell(value=6), Cell(value=8), Cell(value=11)],
|
||||
[Cell(value=6), Cell(value=8), Cell(value=11)],
|
||||
[Cell(value=6), Cell(value=8), Cell(value=11)],
|
||||
]
|
||||
)
|
||||
maze = Maze(test)
|
||||
|
||||
assert maze.__str__() == "68B\n68B\n68B\n"
|
||||
@@ -0,0 +1,11 @@
|
||||
import numpy
|
||||
from amaz_lib.MazeGenerator import Kruskal
|
||||
|
||||
|
||||
def test_kruskal_output_shape() -> None:
|
||||
generator = Kruskal()
|
||||
maze = numpy.array([])
|
||||
for output in generator.generator(10, 10):
|
||||
maze = output
|
||||
|
||||
assert maze.shape == (10, 10)
|
||||
@@ -0,0 +1,78 @@
|
||||
from parsing.Parsing import DataMaze
|
||||
import pytest
|
||||
|
||||
|
||||
class TestParsing:
|
||||
|
||||
def test_get_data_valid(self):
|
||||
data = DataMaze.get_file_data("tests/test_txt/config_1.txt")
|
||||
assert isinstance(data, str) is True
|
||||
|
||||
def test_file_error(self):
|
||||
with pytest.raises(FileNotFoundError):
|
||||
DataMaze.get_file_data("tete")
|
||||
|
||||
# def test_permission_error(self):
|
||||
# with pytest.raises(PermissionError):
|
||||
# DataMaze.get_file_data("tests/test_txt/error_1.txt")
|
||||
|
||||
def test_empty_file_error(self):
|
||||
with pytest.raises(ValueError):
|
||||
DataMaze.get_file_data("tests/test_txt/error_6.txt")
|
||||
|
||||
def test_transform_data_valid(self):
|
||||
data = DataMaze.get_file_data("tests/test_txt/config_1.txt")
|
||||
data_2 = DataMaze.transform_data(data)
|
||||
assert isinstance(data_2, dict)
|
||||
|
||||
def test_transform__index_error(self):
|
||||
with pytest.raises(IndexError):
|
||||
DataMaze.transform_data("asdasdasdasdasdasda\nasdasdas=asdasd")
|
||||
|
||||
def test_key_data_error(self):
|
||||
with pytest.raises(KeyError):
|
||||
data = DataMaze.get_file_data("tests/test_txt/error_8.txt")
|
||||
data2 = DataMaze.transform_data(data)
|
||||
DataMaze.verif_key_data(data2)
|
||||
|
||||
def test_key_data_error_2(self):
|
||||
with pytest.raises(KeyError):
|
||||
data = DataMaze.get_file_data("tests/test_txt/error_9.txt")
|
||||
data2 = DataMaze.transform_data(data)
|
||||
DataMaze.verif_key_data(data2)
|
||||
|
||||
def test_convert_int(self):
|
||||
with pytest.raises(ValueError):
|
||||
data = DataMaze.get_file_data("tests/test_txt/error_2.txt")
|
||||
data2 = DataMaze.transform_data(data)
|
||||
DataMaze.convert_values(data2)
|
||||
|
||||
def test_tuple_error(self):
|
||||
with pytest.raises(ValueError):
|
||||
DataMaze.convert_tuple("0,3,5,5")
|
||||
|
||||
def test_tuple_error1(self):
|
||||
with pytest.raises(AttributeError):
|
||||
DataMaze.convert_tuple(None)
|
||||
|
||||
def test_bool_error(self):
|
||||
with pytest.raises(ValueError):
|
||||
DataMaze.convert_bool("Trueeee")
|
||||
|
||||
def test_valid_tuple(self):
|
||||
assert DataMaze.convert_tuple("7534564654, 78") == (7534564654, 78)
|
||||
|
||||
def test_valid_bool(self):
|
||||
assert DataMaze.convert_bool("False") is False
|
||||
|
||||
def test_valid_bool1(self):
|
||||
assert DataMaze.convert_bool("True") is True
|
||||
|
||||
def test_data_maze(self):
|
||||
data = DataMaze.get_data_maze("tests/test_txt/config_1.txt")
|
||||
assert data["WIDTH"] == 200
|
||||
assert data["HEIGHT"] == 100
|
||||
assert data["ENTRY"] == (0, 0)
|
||||
assert data["EXIT"] == (19, 14)
|
||||
assert data["OUTPUT_FILE"] == "maze.txt"
|
||||
assert data["PERFECT"] is True
|
||||
@@ -0,0 +1,6 @@
|
||||
WIDTH=200
|
||||
HEIGHT=100
|
||||
ENTRY=0,0
|
||||
EXIT=19,14
|
||||
OUTPUT_FILE=maze.txt
|
||||
PERFECT=True
|
||||
@@ -0,0 +1,6 @@
|
||||
WIDTH=200
|
||||
HEIGHT=100
|
||||
ENTRY=0,0
|
||||
EXIT=19,14
|
||||
OUTPUT_FILE=maze.txt
|
||||
PERFECT=True
|
||||
@@ -0,0 +1,6 @@
|
||||
WIDTH=caca
|
||||
HEIGHT=100
|
||||
ENTRY=0,0
|
||||
EXIT=19,14
|
||||
OUTPUT_FILE=maze.txt
|
||||
PERFECT=True
|
||||
@@ -0,0 +1,4 @@
|
||||
WIDTH=200
|
||||
HEIGHT=100
|
||||
ENTRY=0,0
|
||||
EXIT=19,14
|
||||
@@ -0,0 +1,7 @@
|
||||
WIDTH=200
|
||||
HEIGHT=100
|
||||
ENTRY=0,0
|
||||
EXIT=19,14
|
||||
OUTPUT_FILE=maze.txt
|
||||
PERFECT=True
|
||||
PIPI=tut
|
||||
@@ -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