Coverage for tests\unit\maze_dataset\generation\test_custom_endpoints.py: 100%
60 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-23 12:49 -0700
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-23 12:49 -0700
1"""
2> [!NOTE]
3> these are all GPT-4o generated tests, so they might not be all that useful
4"""
6import numpy as np
7import pytest
9from maze_dataset import LatticeMaze, LatticeMazeGenerators
10from maze_dataset.maze.lattice_maze import NoValidEndpointException
13def _get_example_maze():
14 connection_list = np.zeros((2, 2, 2), dtype=bool)
15 connection_list[0, 0, 1] = True
16 connection_list[1, 0, 0] = True
17 connection_list[1, 1, 0] = True
18 maze = LatticeMaze(connection_list=connection_list)
19 print(maze.as_ascii())
20 return maze
23EXAMPLE_MAZE: LatticeMaze = _get_example_maze()
24RANDOM_MAZE: LatticeMaze = LatticeMazeGenerators.gen_dfs(grid_shape=(10, 10))
25PARAMETRIZE_KWARGS: dict = dict(
26 argnames="maze", argvalues=[EXAMPLE_MAZE, RANDOM_MAZE], ids=["example", "random"]
27)
30# parametrize with custom id
31@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
32def test_generate_random_path_no_conditions(maze):
33 path = maze.generate_random_path()
34 assert len(path) > 1
37@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
38def test_generate_random_path_allowed_start(maze):
39 allowed_start = [(0, 0)]
40 path = maze.generate_random_path(allowed_start=allowed_start)
41 assert path[0].tolist() == list(allowed_start[0])
44@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
45def test_generate_random_path_allowed_end(maze):
46 allowed_end = [(1, 1)]
47 path = maze.generate_random_path(allowed_end=allowed_end)
48 assert path[-1].tolist() == list(allowed_end[0])
51@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
52def test_generate_random_path_deadend_start(maze):
53 path = maze.generate_random_path(deadend_start=True)
54 assert len(maze.get_coord_neighbors(tuple(path[0]))) == 1
57@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
58def test_generate_random_path_deadend_end(maze):
59 path = maze.generate_random_path(deadend_end=True)
60 assert len(maze.get_coord_neighbors(tuple(path[-1]))) == 1
63@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
64def test_generate_random_path_allowed_start_and_end(maze):
65 allowed_start = [(0, 0)]
66 allowed_end = [(1, 1)]
67 path = maze.generate_random_path(
68 allowed_start=allowed_start, allowed_end=allowed_end
69 )
70 assert path[0].tolist() == list(allowed_start[0])
71 assert path[-1].tolist() == list(allowed_end[0])
74@pytest.mark.parametrize(**PARAMETRIZE_KWARGS)
75def test_generate_random_path_deadend_start_and_end(maze):
76 path = maze.generate_random_path(deadend_start=True, deadend_end=True)
77 assert len(maze.get_coord_neighbors(tuple(path[0]))) == 1
78 assert len(maze.get_coord_neighbors(tuple(path[-1]))) == 1
81@pytest.mark.parametrize("maze", [EXAMPLE_MAZE])
82def test_generate_random_path_invalid_conditions(maze):
83 with pytest.raises(NoValidEndpointException):
84 maze.generate_random_path(allowed_start=[(2, 2)])
86 with pytest.raises(NoValidEndpointException):
87 maze.generate_random_path(allowed_end=[(2, 2)])
90def test_generate_random_path_size_1():
91 connection_list = np.zeros((1, 1, 1), dtype=bool)
92 maze = LatticeMaze(connection_list=connection_list)
93 with pytest.raises(AssertionError):
94 maze.generate_random_path()