Created
August 11, 2020 03:28
-
-
Save ashkrit/24a6d9397f27e48e5260ac33930b125f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
specification("A Stack", scenario -> { | |
scenario.should("Empty stack should have size 0", then -> { | |
Stack<String> stack = new Stack<>(); | |
then.value(stack.size()).shouldBe(0); | |
}); | |
scenario.should("pop values in last-in-first-out order", then -> { | |
Stack<String> stack = new Stack<>(); | |
stack.push("1"); | |
stack.push("2"); | |
then.value(stack.pop()).shouldBe("2"); | |
then.value(stack.pop()).shouldBe("1"); | |
}); | |
scenario.should("throw NoSuchElementException if an empty stack is popped", then -> { | |
Stack<String> stack = new Stack<>(); | |
then.shouldThrow(EmptyStackException.class, () -> stack.pop()); | |
}); | |
scenario.should("Size is equal to values pushed", then -> { | |
Stack<String> stack = new Stack<>(); | |
stack.push("1"); | |
stack.push("2"); | |
then.value(stack.size()).shouldBe(3); | |
}); | |
scenario.should("Simulate unhandled case", then -> { | |
Stack<String> stack = null; | |
then.value(stack.size()).shouldBe(3); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment