Skip to content

Commit 93df74d

Browse files
committed
Add doctest for graph_search
1 parent bfe7af3 commit 93df74d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

patterns/other/graph_search.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,23 @@ def find_shortest_path(self, start, end, path=None):
4646
return shortest
4747

4848

49-
# example of graph usage
50-
graph = {'A': ['B', 'C'], 'B': ['C', 'D'], 'C': ['D'], 'D': ['C'], 'E': ['F'], 'F': ['C']}
49+
def main():
50+
"""
51+
# example of graph usage
52+
>>> graph = {'A': ['B', 'C'], 'B': ['C', 'D'], 'C': ['D'], 'D': ['C'], 'E': ['F'], 'F': ['C']}
5153
52-
# initialization of new graph search object
53-
graph1 = GraphSearch(graph)
54+
# initialization of new graph search object
55+
>>> graph1 = GraphSearch(graph)
5456
57+
>>> print(graph1.find_path('A', 'D'))
58+
['A', 'B', 'C', 'D']
59+
>>> print(graph1.find_all_path('A', 'D'))
60+
[['A', 'B', 'C', 'D'], ['A', 'B', 'D'], ['A', 'C', 'D']]
61+
>>> print(graph1.find_shortest_path('A', 'D'))
62+
['A', 'B', 'D']
63+
"""
5564

56-
print(graph1.find_path('A', 'D'))
57-
print(graph1.find_all_path('A', 'D'))
58-
print(graph1.find_shortest_path('A', 'D'))
5965

60-
### OUTPUT ###
61-
# ['A', 'B', 'C', 'D']
62-
# [['A', 'B', 'C', 'D'], ['A', 'B', 'D'], ['A', 'C', 'D']]
63-
# ['A', 'B', 'D']
66+
if __name__ == "__main__":
67+
import doctest
68+
doctest.testmod()

0 commit comments

Comments
 (0)