Skip to content

Commit 877bc98

Browse files
committed
Updated tests
1 parent e9c060f commit 877bc98

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed

src/test/groovy/algorithm/BreadthFirstSearchSpec.groovy

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@ package algorithm
22

33
import spock.lang.Specification
44
import spock.lang.Subject
5-
import spock.lang.Unroll
65

76
class BreadthFirstSearchSpec extends Specification {
87
@Subject
98
def algorithm = new BreadthFirstSearch()
109

11-
@Unroll("from #source to #target the time is #time and the path is #shortest")
1210
def 'should find a route for simple graph'() {
13-
given:
11+
given: 'A simple graph'
1412
def graph = new Graph([
1513
A: [B: 7, C: 2],
1614
B: [A: 3, C: 5],
1715
C: [A: 1, B: 3]
1816
])
1917

20-
when:
18+
when: 'we use Breadth First Search algorithm to find a path'
2119
def path = algorithm.findPath(graph, source, target)
2220

23-
then:
21+
then: 'we get the shortest path'
2422
path == shortest
2523

26-
and:
24+
and: 'the distance calculated correctly'
2725
graph.getDistance(path) == time as double
2826

2927
where:
@@ -34,9 +32,8 @@ class BreadthFirstSearchSpec extends Specification {
3432
'C' | 'B' || 3 | ['C', 'B']
3533
}
3634

37-
@Unroll("from #source to #target the time is #time and the path is #shortest")
3835
def 'should find a route for complex graph'() {
39-
given:
36+
given: 'A complex graph'
4037
def graph = new Graph([
4138
A: [B: 1],
4239
B: [A: 1, D: 1],
@@ -45,13 +42,13 @@ class BreadthFirstSearchSpec extends Specification {
4542
E: [F: 1],
4643
F: [D: 1, E: 1]])
4744

48-
when:
45+
when: 'we use Breadth First Search algorithm to find a path'
4946
def path = algorithm.findPath(graph, source, target)
5047

51-
then:
48+
then: 'we get the shortest path'
5249
path == shortest
5350

54-
and:
51+
and: 'the distance calculated correctly'
5552
graph.getDistance(path) == time as double
5653

5754
where:

src/test/groovy/algorithm/DijkstrasAlgorithmSpec.groovy

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@ package algorithm
22

33
import spock.lang.Specification
44
import spock.lang.Subject
5-
import spock.lang.Unroll
65

76
class DijkstrasAlgorithmSpec extends Specification {
87
@Subject
98
def algorithm = new DijkstrasAlgorithm<String>()
109

11-
@Unroll("from #source to #target the time is #time and the path is #fastest")
1210
def 'should find a route for a simple graph'() {
13-
given:
11+
given: 'A simple graph'
1412
def graph = new Graph([
1513
A: [B: 7, C: 2],
1614
B: [A: 3, C: 5],
1715
C: [A: 1, B: 3]
1816
])
1917

20-
when:
18+
when: "we use Dijkstra's algorithm to find a path"
2119
def path = algorithm.findPath(graph, source, target)
2220

23-
then:
21+
then: 'we get the fastest way'
2422
path == fastest
2523

26-
and:
24+
and: 'the distance calculated correctly'
2725
graph.getDistance(path) == time as double
2826

2927
where:
@@ -34,9 +32,8 @@ class DijkstrasAlgorithmSpec extends Specification {
3432
'A' | 'B' || 5 | ['A', 'C', 'B']
3533
}
3634

37-
@Unroll("from #source to #target the time is #time and the path is #fastest")
3835
def 'should find a route for a medium graph'() {
39-
given:
36+
given: 'A medium graph'
4037
def graph = new Graph([
4138
A: [B: 5],
4239
B: [A: 5, C: 10],
@@ -45,13 +42,13 @@ class DijkstrasAlgorithmSpec extends Specification {
4542
E: [B: 5]
4643
])
4744

48-
when:
45+
when: "we use Dijkstra's algorithm to find a path"
4946
def path = algorithm.findPath(graph, source, target)
5047

51-
then:
48+
then: 'we get the fastest way'
5249
path == fastest
5350

54-
and:
51+
and: 'the distance calculated correctly'
5552
graph.getDistance(path) == time as double
5653

5754
where:
@@ -64,9 +61,8 @@ class DijkstrasAlgorithmSpec extends Specification {
6461
'C' | 'A' || 20 | ['C', 'D', 'E', 'B', 'A']
6562
}
6663

67-
@Unroll("from #source to #target the time is #time and the path is #fastest")
6864
def 'should find a route for a complex graph'() {
69-
given:
65+
given: 'A complex graph'
7066
def graph = new Graph([
7167
A: [B: 5, H: 2],
7268
B: [A: 5, C: 7],
@@ -78,13 +74,13 @@ class DijkstrasAlgorithmSpec extends Specification {
7874
H: [G: 3]
7975
])
8076

81-
when:
77+
when: "we use Dijkstra's algorithm to find a path"
8278
def path = algorithm.findPath(graph, source, target)
8379

84-
then:
80+
then: 'we get the fastest way'
8581
path == fastest
8682

87-
and:
83+
and: 'the distance calculated correctly'
8884
graph.getDistance(path) == time as double
8985

9086
where:

src/test/groovy/algorithm/GraphSpec.groovy

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package algorithm
22

33
import spock.lang.Specification
4-
import spock.lang.Unroll
54

65
class GraphSpec extends Specification {
76

8-
@Unroll("distance is #distance for path #path")
97
def "should calculate distance"() {
10-
given:
8+
given: 'A simple graph'
119
def graph = new Graph([
1210
A: [B: 7, C: 2],
1311
B: [A: 3, C: 5],
1412
C: [A: 1, B: 3]
1513
])
1614

17-
expect:
15+
expect: 'the distance calculated correctly'
1816
graph.getDistance(path) == distance as double
1917

2018
where:

src/test/groovy/algorithm/SearchAlgorithmSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package algorithm
22

3-
import spock.lang.Issue
3+
44
import spock.lang.Specification
55
import spock.lang.Subject
66
import spock.lang.Title

0 commit comments

Comments
 (0)