-
Notifications
You must be signed in to change notification settings - Fork 3
/
_03_01_MultiStackTest.groovy
41 lines (34 loc) · 1.49 KB
/
_03_01_MultiStackTest.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
package Ch03_StacksAndQueues
import spock.lang.Specification
import spock.lang.Unroll
@Unroll class _03_01_MultiStackTest extends Specification {
/*@formatter:off*/
def 'multiStack?'() {
when: def multiStack = new MultiStack(stackContents.size(), stackSizes)
then: stackContents.indices.every { stackId -> multiStack.isEmpty(stackId) }
when: stackContents.eachWithIndex { List values, int stackId ->
values.reverseEach { value ->
multiStack.push(stackId, value)
assert !multiStack.isEmpty(stackId)
}
}
then: stackContents.eachWithIndex { List values, int stackId ->
assert values.every { it == multiStack.pop(stackId) }
assert multiStack.isEmpty(stackId)
}
where: stackContents | stackSizes
[[]] | 1
[[1],[2]] | 1
[[1,2],[3,4],[5,6]] | 2
[[1,2,3,4],[5,6],[7],[8]] | 10
}
def "multiStack pushes don't override next stack elements?"() {
when: def multiStack = new MultiStack(stackContents.size(), stackSizes)
stackContents[0].each { value -> multiStack.push(0, value) }
then: thrown(AssertionError)
multiStack.isEmpty(1)
where: stackContents | stackSizes
[[1,2,3],[]] | 2
}
/*@formatter:on*/
}