Skip to content

Commit 21e26a2

Browse files
committed
Add graph schemas
1 parent 0cab4bf commit 21e26a2

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

docs/Graphs.pptx

38.8 KB
Binary file not shown.

docs/complex.gif

13 KB
Loading

docs/medium.gif

9.68 KB
Loading

src/test/groovy/algorithm/DijkstrasSpec.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@ class DijkstrasSpec extends Specification {
3434
'A' | 'B' || 5 | ['A', 'C', 'B']
3535
}
3636

37+
@Unroll("from #source to #target the time is #time and the path is #fastest")
38+
def 'should find a route for a medium graph'() {
39+
given:
40+
def graph = new Graph([
41+
A: [B: 5],
42+
B: [A: 5, C: 10],
43+
C: [B: 20, D: 5],
44+
D: [E: 5],
45+
E: [B: 5]
46+
])
47+
48+
when:
49+
def path = algorithm.findPath(graph, source, target)
50+
51+
then:
52+
path == fastest
53+
54+
and:
55+
graph.getDistance(path) == time as double
56+
57+
where:
58+
source | target || time | fastest
59+
'A' | 'A' || 0 | ['A']
60+
'B' | 'B' || 0 | ['B']
61+
'A' | 'B' || 5 | ['A', 'B']
62+
'B' | 'A' || 5 | ['B', 'A']
63+
'A' | 'C' || 15 | ['A', 'B', 'C']
64+
'C' | 'A' || 20 | ['C', 'D', 'E', 'B', 'A']
65+
}
66+
3767
@Unroll("from #source to #target the time is #time and the path is #fastest")
3868
def 'should find a route for a complex graph'() {
3969
given:

0 commit comments

Comments
 (0)