Skip to content

Commit deda5d4

Browse files
committed
Fixed world.cleanup() bug and extended test_connect_grids to test it.
1 parent 8cdd475 commit deda5d4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pathfinding/core/world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, grids: Dict[int, Grid]):
1212
self.dirty = False
1313

1414
def cleanup(self):
15-
for grid in self.grids:
15+
for grid in self.grids.values():
1616
grid.cleanup()
1717

1818
def neighbors(

test/test_connect_grids.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
(0, 0, 1)
2626
]
2727

28+
PATH2 = [
29+
# test same path a second time
30+
(0, 0, 1),
31+
(1, 0, 1),
32+
(2, 0, 1),
33+
(2, 1, 1),
34+
(2, 2, 1),
35+
(2, 2, 0),
36+
(1, 2, 0),
37+
(0, 2, 0),
38+
(0, 1, 0),
39+
(0, 0, 0),
40+
(1, 0, 0),
41+
(2, 0, 0)
42+
# this ensures that world cleanup is working properly
43+
]
2844

2945
def test_connect():
3046
level0 = [
@@ -52,4 +68,6 @@ def test_connect():
5268

5369
finder = AStarFinder()
5470
path, _ = finder.find_path(grid0.node(2, 0), grid1.node(0, 0), world)
71+
path2, _ = finder.find_path(grid1.node(0, 0), grid0.node(2, 0), world)
5572
assert [tuple(p) for p in path] == PATH
73+
assert [tuple(p) for p in path2] == PATH2

0 commit comments

Comments
 (0)