@@ -46,18 +46,23 @@ def find_shortest_path(self, start, end, path=None):
46
46
return shortest
47
47
48
48
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']}
51
53
52
- # initialization of new graph search object
53
- graph1 = GraphSearch (graph )
54
+ # initialization of new graph search object
55
+ >>> graph1 = GraphSearch(graph)
54
56
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
+ """
55
64
56
- print (graph1 .find_path ('A' , 'D' ))
57
- print (graph1 .find_all_path ('A' , 'D' ))
58
- print (graph1 .find_shortest_path ('A' , 'D' ))
59
65
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