summaryrefslogtreecommitdiff
path: root/src/02/05/stack_test.c
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-08-05 21:42:35 -0600
committermo khan <mo.khan@gmail.com>2020-08-05 21:42:35 -0600
commit2fc19c9e521bb2d09cfdfd990fbe440a1524bd4a (patch)
tree5623f804102610ab7ab49928bc1571a58e8e1bdc /src/02/05/stack_test.c
parent8ebf2af9526cbc66dfdb1a305cb5d594c19d45b7 (diff)
Implement stack_pop
Diffstat (limited to 'src/02/05/stack_test.c')
-rw-r--r--src/02/05/stack_test.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/02/05/stack_test.c b/src/02/05/stack_test.c
index c2ec4c2..5c74290 100644
--- a/src/02/05/stack_test.c
+++ b/src/02/05/stack_test.c
@@ -7,14 +7,43 @@ BeforeEach(Stack) {}
AfterEach(Stack) {}
Ensure(Stack, when_pushing_an_item_on_to_a_stack) {
- Stack *stack = stack_init(10);
+ Stack *stack = stack_init();
+
+ stack_push(stack, 10);
assert_that(stack_size(stack), is_equal_to(1));
assert_that(stack_peek(stack), is_equal_to(10));
}
+Ensure(Stack, when_pushing_multiple_items_on_to_a_stack) {
+ Stack *stack = stack_init();
+
+ stack_push(stack, 20);
+ stack_push(stack, 10);
+ stack_push(stack, 50);
+
+ assert_that(stack_size(stack), is_equal_to(3));
+ assert_that(stack_peek(stack), is_equal_to(50));
+}
+
+Ensure(Stack, when_popping_an_item_off_of_a_stack) {
+ Stack *stack = stack_init();
+
+ stack_push(stack, 20);
+ stack_push(stack, 10);
+ stack_push(stack, 50);
+
+ int result = stack_pop(stack);
+
+ assert_that(stack_size(stack), is_equal_to(2));
+ assert_that(stack_peek(stack), is_equal_to(10));
+ assert_that(result, is_equal_to(50));
+}
+
TestSuite *stack_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, Stack, when_pushing_an_item_on_to_a_stack);
+ add_test_with_context(suite, Stack, when_pushing_multiple_items_on_to_a_stack);
+ add_test_with_context(suite, Stack, when_popping_an_item_off_of_a_stack);
return suite;
}