From 12461490d0b79748476ed28131d95d90479e432c Mon Sep 17 00:00:00 2001 From: Shivangi Nayak Date: Sun, 23 May 2021 23:56:53 +0530 Subject: [PATCH] modified tests --- pydatastructs/graphs/algorithms.py | 3 +-- pydatastructs/graphs/tests/test_algorithms.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pydatastructs/graphs/algorithms.py b/pydatastructs/graphs/algorithms.py index 7b36e0350..2586ff513 100644 --- a/pydatastructs/graphs/algorithms.py +++ b/pydatastructs/graphs/algorithms.py @@ -1036,7 +1036,7 @@ def lowest_common_ancestor(graph: Graph, vertex1: str, vertex2: str, algorithm: >>> graph.add_edge('v_1', 'v_3') >>> graph.add_edge('v_3', 'v_4') >>> graph.add_edge('v_3', 'v_5') - >>> lowest_common_ancestor(graph, 'v_1', 'v_5', 'binary_lifting') + >>> lowest_common_ancestor(graph, 'v_5', 'v_2', 'binary_lifting') 'v_1' >>> lowest_common_ancestor(graph, 'v_4', 'v_5', 'binary_lifting') 'v_3' @@ -1093,7 +1093,6 @@ def _collect_source_nodes(graph: Graph) -> list: pow_of_two =int(math.log2(difference)) vertex2 = ancestor[vertex2][pow_of_two] difference =- (1 << pow_of_two) - if vertex1 == vertex2: return vertex1 diff --git a/pydatastructs/graphs/tests/test_algorithms.py b/pydatastructs/graphs/tests/test_algorithms.py index 6864fee82..46543dafc 100644 --- a/pydatastructs/graphs/tests/test_algorithms.py +++ b/pydatastructs/graphs/tests/test_algorithms.py @@ -385,6 +385,7 @@ def _test_lowest_common_ancestor(ds): V5 = GraphNode(4) V6 = GraphNode(5) V7 = GraphNode(6) + V8 = GraphNode(7) G1 = Graph(V1, V2, V3, V4, V5, V6, V7) @@ -394,7 +395,8 @@ def _test_lowest_common_ancestor(ds): (V3.name, V4.name), (V3.name, V5.name), (V5.name, V6.name), - (V5.name, V7.name) + (V5.name, V7.name), + (V2.name, V8.name) ] for edge in edges: @@ -408,7 +410,7 @@ def _test_lowest_common_ancestor(ds): expected_result = V3.name assert(lca2 == expected_result) - lca3 = lowest_common_ancestor(G1, V2.name, V7.name) + lca3 = lowest_common_ancestor(G1, V7.name, V2.name) expected_result = V1.name assert(lca3 == expected_result) @@ -419,3 +421,7 @@ def _test_lowest_common_ancestor(ds): lca5 = lowest_common_ancestor(G1, V3.name, V7.name) expected_result = V3.name assert(lca5 == expected_result) + + lca6 = lowest_common_ancestor(G1, V7.name, V8.name) + expected_result = V1.name + assert(lca6 == expected_result)