From 2fc19c9e521bb2d09cfdfd990fbe440a1524bd4a Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 5 Aug 2020 21:42:35 -0600 Subject: Implement stack_pop --- src/02/05/stack_test.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/02/05/stack_test.c') 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; } -- cgit v1.2.3