/
FizzBuzzSpec.groovy
111 lines (87 loc) · 2.25 KB
/
FizzBuzzSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
@Grab(group='org.spockframework', module='spock-core', version='0.7-groovy-2.0')
import spock.lang.*
class FizzBuzzSpec extends Specification {
void 'return fizz with 3'() {
given:
FizzBuzz fb = new FizzBuzz()
String res = fb.check(3)
expect:
res == 'fizz'
}
void 'return buzz with 5'() {
given:
FizzBuzz fb = new FizzBuzz()
String res = fb.check(5)
expect:
res == 'buzz'
}
void 'return fizzbuzz with 15'() {
given:
FizzBuzz fb = new FizzBuzz()
String res = fb.check(15)
expect:
res == 'fizzbuzz'
}
void 'return number with 23'() {
given:
FizzBuzz fb = new FizzBuzz()
Integer res = fb.check(23)
expect:
res == 23
}
@Unroll
void 'return fizz with multiple of 3'() {
given:
FizzBuzz fb = new FizzBuzz()
when:
String res = fb.check(num)
then:
res == 'fizz'
where:
num | _
3 | _
6 | _
9 | _
12 | _
//Data tables must have at least two columns.
//A single-column table can be written as above.
}
@Unroll
void 'return proper [expResult=#expResult] for [num=#num]'() {
given: "A FizzBuzz game"
FizzBuzz fb = new FizzBuzz()
when:
def res = fb.check(num)
then: "that everything works"
res == expResult
where: "I have the following data"
num | expResult
1 | 1
2 | 2
3 | 'fizz'
4 | 4
5 | 'buzz'
6 | 'fizz'
7 | 7
8 | 8
9 | 'fizz'
10 | 'buzz'
11 | 11
12 | 'fizz'
13 | 13
14 | 14
15 | 'fizzbuzz'
}
@Unroll
void 'return proper [expResult=#expResult] for [num=#num] from 1 to 15'() {
given: "A FizzBuzz game"
FizzBuzz fb = new FizzBuzz()
when:
def res = fb.check(num)
then: "that everything works"
res == expResult
where: "I have the following data"
num << (1..15)
expResult << [1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', 'buzz', 11, 'fizz', 13, 14, 'fizzbuzz']
}
}