summaryrefslogtreecommitdiff
path: root/networkx
diff options
context:
space:
mode:
authorNavya Agarwal <82928853+navyagarwal@users.noreply.github.com>2023-03-14 18:29:06 +0530
committerGitHub <noreply@github.com>2023-03-14 08:59:06 -0400
commit2257ef4e820c009ae3d06d45072868feb6390204 (patch)
tree2b96a5e834c1e901275e0939523eefb61b0f00c8 /networkx
parent8fd5c481338dcfaeeb6ac7afc239a2eebc0500e1 (diff)
downloadnetworkx-2257ef4e820c009ae3d06d45072868feb6390204.tar.gz
Improve test coverage for astar.py (#6504)
Improve test coverage for Astar
Diffstat (limited to 'networkx')
-rw-r--r--networkx/algorithms/shortest_paths/tests/test_astar.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/networkx/algorithms/shortest_paths/tests/test_astar.py b/networkx/algorithms/shortest_paths/tests/test_astar.py
index 3cc4050b..680f76ef 100644
--- a/networkx/algorithms/shortest_paths/tests/test_astar.py
+++ b/networkx/algorithms/shortest_paths/tests/test_astar.py
@@ -194,3 +194,17 @@ class TestAStar:
G.add_edges_from(pairwise(nodes, cyclic=True))
path = nx.astar_path(G, nodes[0], nodes[2])
assert len(path) == 3
+
+ def test_astar_NetworkXNoPath(self):
+ """Tests that exception is raised when there exists no
+ path between source and target"""
+ G = nx.gnp_random_graph(10, 0.2, seed=10)
+ with pytest.raises(nx.NetworkXNoPath):
+ nx.astar_path(G, 4, 9)
+
+ def test_astar_NodeNotFound(self):
+ """Tests that exception is raised when either
+ source or target is not in graph"""
+ G = nx.gnp_random_graph(10, 0.2, seed=10)
+ with pytest.raises(nx.NodeNotFound):
+ nx.astar_path_length(G, 11, 9)