From 1d247f0b07a8290ea1067fed6201b8d15a1bbdaa Mon Sep 17 00:00:00 2001 From: Hari Date: Sat, 27 Jan 2024 21:20:45 +0100 Subject: [PATCH] added additional test for theta star, weights disabled for theta star --- pathfinding3d/finder/theta_star.py | 4 +++- test/test_path.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pathfinding3d/finder/theta_star.py b/pathfinding3d/finder/theta_star.py index 1f41fee..8f2e4d6 100644 --- a/pathfinding3d/finder/theta_star.py +++ b/pathfinding3d/finder/theta_star.py @@ -20,7 +20,7 @@ def __init__( ): """ Find shortest path using Theta* algorithm - Diagonal movement is forced to always. + Diagonal movement is forced to always. Not weighted. Parameters ---------- @@ -52,6 +52,8 @@ def __init__( max_runs=max_runs, ) + self.weighted = False + def process_node( self, grid: Grid, diff --git a/test/test_path.py b/test/test_path.py index 4a6d821..d78cb2c 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -32,7 +32,6 @@ BiAStarFinder, DijkstraFinder, MinimumSpanningTree, - ThetaStarFinder, ] SIMPLE_MATRIX = np.zeros((5, 5, 5)) @@ -90,8 +89,6 @@ def test_weighted_path(): start = grid.node(0, 0, 0) end = grid.node(4, 4, 0) for find in weighted_finders: - if find == ThetaStarFinder: - continue grid.cleanup() finder = find(time_limit=TIME_LIMIT) path_, runs = finder.find_path(start, end, grid) @@ -171,3 +168,17 @@ def test_msp(): finder = MinimumSpanningTree() assert finder.tree(grid, start).sort() == [node for row in grid.nodes for col in row for node in col].sort() + + +def test_theta_star(caplog): + """ + Test that the theta star finder returns the correct path. + """ + caplog.set_level("WARNING") + grid = Grid(matrix=WEIGHTED_SIMPLE_MATRIX) + start = grid.node(0, 0, 0) + end = grid.node(4, 4, 0) + + finder = ThetaStarFinder(diagonal_movement=DiagonalMovement.never, time_limit=TIME_LIMIT) + assert finder.diagonal_movement == DiagonalMovement.always + assert "Diagonal movement is forced to always" in caplog.text