aboutsummaryrefslogtreecommitdiff
path: root/examples/scalatest-example/src/test/scala/Test.scala
blob: 48b0a36042ad3eea0b16ca6842b97117ede214f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import collection.mutable.Stack
import org.scalatest._

class Test extends FlatSpec with Matchers {
  "square" should "return double" in {
    Main.square(2) should be (4)
  }

  "A Stack" should "pop values in last-in-first-out order" in {
    val stack = new Stack[Int]
    stack.push(1)
    stack.push(2)
    stack.pop() should be (2)
    stack.pop() should be (1)
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {
    val emptyStack = new Stack[Int]
    a [NoSuchElementException] should be thrownBy {
      emptyStack.pop()
    }
  }
}