| 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testUndirectedPathSearch() { |
| 76 | IVert v1 = undirectedGraph.getVertex(2); |
| 77 | IVert v4 = undirectedGraph.getVertex(4); |
| 78 | // Use DFS to find the path between v1 and v4 |
| 79 | Search<Integer> search = new DepthFirstSearch<>(); |
| 80 | SearchResult<Integer> result = search.find(v1, v4); |
| 81 | assertNotNull(result); |
| 82 | // Path must follow one of the given paths |
| 83 | String[] paths = new String[]{"2 1 3 4", "2 5 3 4"}; |
| 84 | String path = result.getPath().stream() |
| 85 | .map(String::valueOf) |
| 86 | .collect(Collectors.joining(" ")).toString(); |
| 87 | assertTrue(Arrays.binarySearch(paths, path) >= 0); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void testDirectedPathSearch() { |