Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created August 11, 2020 03:28
Show Gist options
  • Save ashkrit/24a6d9397f27e48e5260ac33930b125f to your computer and use it in GitHub Desktop.
Save ashkrit/24a6d9397f27e48e5260ac33930b125f to your computer and use it in GitHub Desktop.
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