...
| Code Block |
|---|
import com.craig.gspec.GSpecBuilderRunner
def the = new GSpecBuilderRunner()
the.context('A non-empty stack') {
initially {
the.stack = new FixedStack()
('a'..'c').each { x -> the.stack.push x }
the.stack.should_not_be_empty
}
specify('should return the top item when sent #peek') {
the.stack.peek().should_equal 'c'
}
specify('should NOT remove the top item when sent #peek') {
the.stack.peek().should_equal 'c'
the.stack.peek().should_equal 'c'
}
specify('should be unchanged when sent #push then #pop') {
the.stack.push 'Anything'
the.stack.pop()
the.stack.peek().should_equal 'c'
}
specify('should return the top item when sent #pop') {
the.stack.pop().should_equal 'c'
the.stack.push 'c' // put it back the way it was
}
specify('should remove the top item when sent #pop') {
the.stack.pop().should_equal 'c'
the.stack.pop().should_equal 'b'
}
specify('should add to the top when sent #push') {
the.stack.push 'd'
the.stack.peek().should_equal 'd'
}
}
the.context('An empty stack') {
initially {
the.stack = new FixedStack()
the.stack.should_be_empty
}
specify('should no longer be empty after #push') {
the.stack.push 'anything'
the.stack.should_not_be_empty
}
specify('should complain when sent #peek') {
// the.stack.peek().should_fail_with( StackUnderflowException)
}
specify('should complain when sent #pop') {
// the.stack.pop().should_fail_with( StackUnderflowException)
}
}
the.context('A stack with one item') {
initially {
the.stack = new FixedStack()
the.stack.push 'anything'
the.stack.should_not_be_empty
}
specify('should remain not empty after #peek') {
the.stack.peek()
the.stack.should_not_be_empty
}
specify('should become empty after #pop') {
the.stack.pop()
the.stack.should_be_empty
}
}
the.context('A stack with one item less than capacity') {
initially {
the.stack = new FixedStack()
(1..<FixedStack.MAXSIZE).each { x -> the.stack.push x }
the.stack.should_not_be_full
}
specify('should become full after #push') {
the.stack.push 'Anything'
the.stack.should_be_full
}
}
the.context('A full stack') {
initially {
the.stack = new FixedStack()
(1..FixedStack.MAXSIZE).each { x -> the.stack.push x }
the.stack.should_be_full
}
specify('should remain full after #peek') {
the.stack.peek()
the.stack.should_be_full
}
specify('should no longer be full after #pop') {
the.stack.pop()
the.stack.should_not_be_full
}
specify('should complain on #push') {
// the.stack.push('Anything').should_fail_with( StackOverflowException)
}
}
|
The Item Storer Example
...