forked from asparagus/search
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
40 lines (31 loc) · 844 Bytes
/
test.py
File metadata and controls
40 lines (31 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Testing BFS, DFS, A*, IDFS on a ShortestPathProblem.
>>> import problem
>>> import search
>>> adjacency_matrix = [
... [0, 1, 0, 0, 1],
... [1, 0, 0, 0, 1],
... [1, 0, 0, 0, 0],
... [0, 0, 1, 0, 0],
... [0, 1, 0, 1, 0]]
>>> start = 4
>>> end = 0
>>> spp = problem.ShortestPathProblem(adjacency_matrix, start, end)
>>> bfs = search.BreadthFirstSearch()
>>> dfs = search.DepthFirstSearch()
>>> a = search.BestFirstSearch()
>>> idfs = search.IterativeDepthFirstSearch()
>>> bfs.solve(spp)
{index: 0, value: 2, path: [4, 1, 0]}
>>> dfs.solve(spp)
{index: 0, value: 3, path: [4, 3, 2, 0]}
>>> a.solve(spp)
{index: 0, value: 2, path: [4, 1, 0]}
>>> idfs.solve(spp)
{index: 0, value: 2, path: [4, 1, 0]}
"""
if __name__ == '__main__':
import doctest
doctest.testmod()