Coverage for tests/unit/generation/test_custom_endpoints.py: 100%

60 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-24 00:33 -0600

1"""testing endpoints 

2 

3> [!NOTE] 

4> these are all GPT-4o generated tests, so they might not be all that useful 

5""" 

6 

7import numpy as np 

8import pytest 

9 

10from maze_dataset import LatticeMaze, LatticeMazeGenerators 

11from maze_dataset.maze.lattice_maze import NoValidEndpointException 

12 

13 

14def _get_example_maze(): 

15 connection_list = np.zeros((2, 2, 2), dtype=bool) 

16 connection_list[0, 0, 1] = True 

17 connection_list[1, 0, 0] = True 

18 connection_list[1, 1, 0] = True 

19 maze = LatticeMaze(connection_list=connection_list) 

20 print(maze.as_ascii()) 

21 return maze 

22 

23 

24EXAMPLE_MAZE: LatticeMaze = _get_example_maze() 

25RANDOM_MAZE: LatticeMaze = LatticeMazeGenerators.gen_dfs(grid_shape=(10, 10)) 

26PARAMETRIZE_KWARGS: dict = dict( 

27 argnames="maze", 

28 argvalues=[EXAMPLE_MAZE, RANDOM_MAZE], 

29 ids=["example", "random"], 

30) 

31 

32 

33# parametrize with custom id 

34@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

35def test_generate_random_path_no_conditions(maze): 

36 path = maze.generate_random_path() 

37 assert len(path) > 1 

38 

39 

40@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

41def test_generate_random_path_allowed_start(maze): 

42 allowed_start = [(0, 0)] 

43 path = maze.generate_random_path(allowed_start=allowed_start) 

44 assert path[0].tolist() == list(allowed_start[0]) 

45 

46 

47@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

48def test_generate_random_path_allowed_end(maze): 

49 allowed_end = [(1, 1)] 

50 path = maze.generate_random_path(allowed_end=allowed_end) 

51 assert path[-1].tolist() == list(allowed_end[0]) 

52 

53 

54@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

55def test_generate_random_path_deadend_start(maze): 

56 path = maze.generate_random_path(deadend_start=True) 

57 assert len(maze.get_coord_neighbors(tuple(path[0]))) == 1 

58 

59 

60@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

61def test_generate_random_path_deadend_end(maze): 

62 path = maze.generate_random_path(deadend_end=True) 

63 assert len(maze.get_coord_neighbors(tuple(path[-1]))) == 1 

64 

65 

66@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

67def test_generate_random_path_allowed_start_and_end(maze): 

68 allowed_start = [(0, 0)] 

69 allowed_end = [(1, 1)] 

70 path = maze.generate_random_path( 

71 allowed_start=allowed_start, 

72 allowed_end=allowed_end, 

73 ) 

74 assert path[0].tolist() == list(allowed_start[0]) 

75 assert path[-1].tolist() == list(allowed_end[0]) 

76 

77 

78@pytest.mark.parametrize(**PARAMETRIZE_KWARGS) 

79def test_generate_random_path_deadend_start_and_end(maze): 

80 path = maze.generate_random_path(deadend_start=True, deadend_end=True) 

81 assert len(maze.get_coord_neighbors(tuple(path[0]))) == 1 

82 assert len(maze.get_coord_neighbors(tuple(path[-1]))) == 1 

83 

84 

85@pytest.mark.parametrize("maze", [EXAMPLE_MAZE]) 

86def test_generate_random_path_invalid_conditions(maze): 

87 with pytest.raises(NoValidEndpointException): 

88 maze.generate_random_path(allowed_start=[(2, 2)]) 

89 

90 with pytest.raises(NoValidEndpointException): 

91 maze.generate_random_path(allowed_end=[(2, 2)]) 

92 

93 

94def test_generate_random_path_size_1(): 

95 connection_list = np.zeros((1, 1, 1), dtype=bool) 

96 maze = LatticeMaze(connection_list=connection_list) 

97 with pytest.raises(AssertionError): 

98 maze.generate_random_path()