-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStackSpec.scala
More file actions
45 lines (38 loc) · 1.19 KB
/
Copy pathStackSpec.scala
File metadata and controls
45 lines (38 loc) · 1.19 KB
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
// Copyright © 2010-2016, Esko Luontola <www.orfjackal.net>
// This software is released under the Apache License 2.0.
// The license text is at http://www.apache.org/licenses/LICENSE-2.0
package org.specsy.examples.scala
import org.specsy.scala.ScalaSpecsy
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers._
import org.junit.Assert._
class StackSpec extends ScalaSpecsy {
val stack = new scala.collection.mutable.Stack[String]
"An empty stack" >> {
"is empty" >> {
assertTrue(stack.isEmpty)
}
"After a push, the stack is no longer empty" >> {
stack.push("a push")
assertFalse(stack.isEmpty)
}
}
"When objects have been pushed onto a stack" >> {
stack.push("pushed first")
stack.push("pushed last")
"the object pushed last is popped first" >> {
val poppedFirst = stack.pop()
assertThat(poppedFirst, is("pushed last"))
}
"the object pushed first is popped last" >> {
stack.pop()
val poppedLast = stack.pop()
assertThat(poppedLast, is("pushed first"))
}
"After popping all objects, the stack is empty" >> {
stack.pop()
stack.pop()
assertTrue(stack.isEmpty)
}
}
}