...
| Code Block |
|---|
// require(url:'http://code.google.com/p/instinct', jar:'instinct-0.1.5.jar') // require(url:'http://geekscape.org/static/boost.html', jar:'boost-982.jar') // require(groupId:'org.jmock', artifactId:'jmock', version:'2.2.0') import com.googlecode.instinct.marker.annotate.* import com.googlecode.instinct.runner.TextContextRunnerTextRunner @Context class AlmostEmptyFixedStackContext { private stack @BeforeSpecification void initially() { stack = new FixedStack() stack.push 'anything' assert !stack.isEmpty() } @Specification void shouldRemainNotEmptyAfterPeek() { stack.peek() assert !stack.isEmpty() } @Specification void shouldBecomeEmptyAfterPop() { stack.pop() assert stack.isEmpty() } } class AlmostFullFixedStackContext { private stack @BeforeSpecification void initially() { stack = new FixedStack() (1..<FixedStack.MAXSIZE).each{ x -> stack.push x } assert !stack.isFull() } @Specification void shouldBecomeFullAfterPush() { stack.push 'anything' assert stack.isFull() } } class EmptyFixedStackContext extends GroovyTestCase { private stack = new FixedStack() @BeforeSpecification void preConditions() { assert stack.isEmpty() } @Specification void shouldNoLongerBeEmptyAfterPush() { stack.push 'anything' assert !stack.isEmpty() } @Specification void shouldComplainWhenSentPeek() { shouldFail(StackUnderflowException) { stack.peek() } } @Specification void shouldComplainWhenSentPop() { shouldFail(StackUnderflowException) { stack.pop() } } } class FullFixedStackContext extends GroovyTestCase { private stack @BeforeSpecification void initially() { stack = new FixedStack() (1..FixedStack.MAXSIZE).each{ x -> stack.push x } assert stack.isFull() } @Specification void shouldRemainFullAfterPeek() { stack.peek() assert stack.isFull() } @Specification void shouldNoLongerBeFullAfterPop() { stack.pop() assert !stack.isFull() } @Specification void shouldComplainOnPush() { shouldFail(StackOverflowException) { stack.push 'anything' } } } class NonEmptyFixedStackContext { private stack @BeforeSpecification void setUp() { stack = new FixedStack() ('a'..'c').each{ x -> stack.push x } assert !stack.isEmpty() } @Specification void shouldAddToTheTopWhenSentPush() { stack.push 'd' assert stack.peek() == 'd' } @Specification void shouldBeUnchangedWhenSentPushThenPop() { stack.push 'anything' stack.pop() assert stack.peek() == 'c' } @Specification void shouldReturnTheTopItemWhenSentPeek() { assert stack.peek() == 'c' } @Specification void shouldNotRemoveTheTopItemWhenSentPeek() { assert stack.peek() == 'c' assert stack.peek() == 'c' } @Specification void shouldReturnTheTopItemWhenSentPop() { assert stack.pop() == 'c' } @Specification void shouldRemoveTheTopItemWhenSentPop() { assert stack.pop() == 'c' assert stack.pop() == 'b' } } TextContextRunnerTextRunner.runContexts( AlmostEmptyFixedStackContext, AlmostFullFixedStackContext, EmptyFixedStackContext, FullFixedStackContext, NonEmptyFixedStackContext ) |
...