stack-test.scala

class StackTest extends WordSpec { "A stack" when { "empty" should { val stack = Stack.empty "be empty" in { assert(stack.isEmpty) } "throw NoSuchElementException when popped" in { assertThrows[NoSuchElementException](stack.pop) } "throw NoSuchElementException when topped" in { assertThrows[NoSuchElementException](stack.top) } } "with one element" should { val element = "an element" val stack = Stack(element) "not be empty" in { assert(stack.nonEmpty) } "return an element when popped and be empty" in { val (e, newStack) = stack.pop2 assert(e == element) assert(newStack.isEmpty) } "return an element when topped but remains not empty" in { val e = stack.top assert(e == element) assert(stack.nonEmpty) } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.