Coverage for tests/unit/processing/test_get_forking_path_points.py: 100%
20 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-24 00:33 -0600
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-24 00:33 -0600
1import numpy as np
2import pytest
4from maze_dataset import CoordArray, SolvedMaze
6_MANUAL_EXAMPLES: dict[str, dict[str, SolvedMaze | list[int] | CoordArray]] = {
7 "small_5x5": dict(
8 maze=SolvedMaze.from_ascii(
9 """
10 ###########
11 # XXX# #
12 # ###X#X# #
13 # #X#S #
14 #####X#####
15 #XXXXX#EXX#
16 #X### ###X#
17 #X# #X#
18 #X#######X#
19 #XXXXXXXXX#
20 ###########
21 """,
22 ),
23 fork_idxs=[0, 2, 4],
24 fork_coords=[
25 [1, 3],
26 [0, 2],
27 [2, 2],
28 ],
29 follow_idxs=[1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
30 follow_coords=[
31 [0, 3],
32 [1, 2],
33 [2, 1],
34 [2, 0],
35 [3, 0],
36 [4, 0],
37 [4, 1],
38 [4, 2],
39 [4, 3],
40 [4, 4],
41 [3, 4],
42 [2, 4],
43 [2, 3],
44 ],
45 ),
46 "medium_10x10": dict(
47 maze=SolvedMaze.from_ascii(
48 """
49 #####################
50 # # # #
51 # ##### # # # ### ###
52 # # # # # # #
53 # # ######### # ### #
54 # # # # # #
55 # ####### # ### ### #
56 # # # # # #
57 ### # # # ##### # ###
58 #E# # # # # # # #
59 #X# # # # # ##### # #
60 #X # # # # # #
61 #X##### ########### #
62 #XXXXXXX# XXXXX#XXX#
63 #######X###X###X#X#X#
64 #S #XXXXX# #XXX#X#
65 #X########### #####X#
66 #X#XXX#XXXXXXXXX#XXX#
67 #X#X#X#X#######X#X###
68 #XXX#XXX #XXX #
69 #####################
70 """,
71 ),
72 fork_idxs=[0, 7, 11, 14, 18, 24, 28, 32],
73 fork_coords=[[7, 0], [9, 3], [8, 6], [9, 8], [6, 9], [6, 5], [6, 3], [5, 0]],
74 follow_idxs=[
75 1,
76 2,
77 3,
78 4,
79 5,
80 6,
81 8,
82 9,
83 10,
84 12,
85 13,
86 15,
87 16,
88 17,
89 19,
90 20,
91 21,
92 22,
93 23,
94 25,
95 26,
96 27,
97 29,
98 30,
99 31,
100 33,
101 ],
102 follow_coords=[
103 [8, 0],
104 [9, 0],
105 [9, 1],
106 [8, 1],
107 [8, 2],
108 [9, 2],
109 [8, 3],
110 [8, 4],
111 [8, 5],
112 [8, 7],
113 [9, 7],
114 [8, 8],
115 [8, 9],
116 [7, 9],
117 [6, 8],
118 [7, 8],
119 [7, 7],
120 [6, 7],
121 [6, 6],
122 [7, 5],
123 [7, 4],
124 [7, 3],
125 [6, 2],
126 [6, 1],
127 [6, 0],
128 [4, 0],
129 ],
130 ),
131}
134@pytest.mark.parametrize("example_name", _MANUAL_EXAMPLES.keys())
135def test_fork_and_following_points(example_name):
136 example = _MANUAL_EXAMPLES[example_name]
137 maze = example["maze"]
139 # compute
140 fork_idxs, fork_coords = maze.get_solution_forking_points()
141 follow_idxs, follow_coords = maze.get_solution_path_following_points()
143 # check that entire solution is covered
144 fork_coords_set = set(map(tuple, fork_coords))
145 follow_coords_set = set(map(tuple, follow_coords))
146 for s_idx, s_coord_ in enumerate(maze.solution):
147 s_coord = tuple(s_coord_)
148 # exclusive or
149 assert (s_idx in fork_idxs) != (s_idx in follow_idxs)
150 assert (s_coord in fork_coords_set) != (s_coord in follow_coords_set)
152 # assert equal
153 assert np.all(fork_idxs == np.array(example["fork_idxs"]))
154 assert np.all(fork_coords == np.array(example["fork_coords"]))
155 assert np.all(follow_idxs == np.array(example["follow_idxs"]))
156 assert np.all(follow_coords == np.array(example["follow_coords"]))