Skip to content

Commit

Permalink
modified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sHiVaNgI821 committed May 23, 2021
1 parent 9554c66 commit 1246149
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions pydatastructs/graphs/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions pydatastructs/graphs/tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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)

Expand All @@ -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)

0 comments on commit 1246149

Please sign in to comment.