| Executed features | Passed | Failures | Errors | Skipped | Success rate | Time |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 0 | 0.0% | 0.037 seconds |
Dijkstra's Algorithm
Dijkstra's algorithm is an algorithm for finding the fastest paths between nodes in a graph
|
should find a route for a simple graph
Return
(0.016 seconds)
|
|||||||||||||||||||||
|
Given:
|
def graph = Graph.of([
A: [B: 7, C: 2],
B: [A: 3, C: 5],
C: [A: 1, B: 3]
])
|
||||||||||||||||||||
|
When:
|
def path = algorithm.findPath(graph, source, target) def time = graph.getDistance(path) |
||||||||||||||||||||
|
Then:
|
path == fastestPath // line 29 time == fastestTime |
||||||||||||||||||||
|
Examples:
|
|
2/3 passed
|
|||||||||||||||||||
|
The following problems occurred:
|
|||||||||||||||||||||
|
should find a route for a medium graph
Return
|
|||||||||||||||||||||
|
Given:
|
def graph = Graph.of([
A: [B: 5],
B: [A: 5, C: 10],
C: [B: 20, D: 5],
D: [E: 5],
E: [B: 5]
])
|
||||||||||||||||||||
|
When:
|
def path = algorithm.findPath(graph, source, target) |
||||||||||||||||||||
|
Then:
|
path == fastest |
||||||||||||||||||||
|
And:
|
graph.getDistance(path) == time as double |
||||||||||||||||||||
|
should find a route for a complex graph
Return
|
|||||||||||||||||||||
|
Given:
|
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:
|
def path = algorithm.findPath(graph, source, target) |
||||||||||||||||||||
|
Then:
|
path == fastest |
||||||||||||||||||||
|
And:
|
graph.getDistance(path) == time as double |
||||||||||||||||||||
|
should thrown NPE for an empty graph
Return
|
|||||||||||||||||||||
|
Given:
|
def graph = Graph.of([:]) |
||||||||||||||||||||
|
When:
|
algorithm.findPath(graph, 'A', 'B') |
||||||||||||||||||||
|
Then:
|
thrown NullPointerException |
||||||||||||||||||||
|
should return an empty path if can't find a route
Return
|
|||||||||||||||||||||
|
Given:
|
a simple graph with no edge between nodes
|
||||||||||||||||||||
def graph = Graph.of([A: [:], B: [:]]) |
|||||||||||||||||||||
|
When:
|
def path = algorithm.findPath(graph, 'A', 'B') |
||||||||||||||||||||
|
Then:
|
path == [] |
||||||||||||||||||||