| Executed features | Passed | Failures | Errors | Skipped | Success rate | Time |
|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 0 | 100.0% | 0.005 seconds |
Comparison of two algorithms
|
should find a route for a complex graph
Return
(0)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Given:
|
a complex graph with eight nodes
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def graph = Graph.of([
A: [B: 5, H: 2],
B: [A: 5, C: 7],
C: [B: 7, D: 3, G: 4],
D: [C: 20, E: 4],
E: [F: 5],
F: [G: 6],
G: [C: 4],
H: [G: 3]
])
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
When:
|
we use Breadth First Search algorithm for the first route
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def routeOne = bfsAlgorithm.findPath(graph, source, target) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
And:
|
we use Dijkstra's algorithm for the second route
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def routeTwo = dijkstras.findPath(graph, source, target) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Then:
|
the first route is the shortest
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
routeOne == shortest |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
And:
|
the second route is the fastest
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
routeTwo == fastest |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
And:
|
the distance calculated correctly
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
graph.getDistance(routeOne) == t1 as double graph.getDistance(routeTwo) == t2 as double |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Examples:
|
|
12/12 passed
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||