diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-16 17:26:38 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-16 17:26:38 -0600 |
| commit | b8e927bd7ba60ca732e9b805d51a9583fd4f6419 (patch) | |
| tree | 3724c20df8ba95eaf92ede1eea2041099edc7b94 /src/02/03/stack_test.c | |
| parent | 18a7345a0b2514e26bef935da366b3cc631115be (diff) | |
Calculate the size of a binary tree
Diffstat (limited to 'src/02/03/stack_test.c')
| -rw-r--r-- | src/02/03/stack_test.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/02/03/stack_test.c b/src/02/03/stack_test.c new file mode 100644 index 0000000..2f3eae0 --- /dev/null +++ b/src/02/03/stack_test.c @@ -0,0 +1,65 @@ +#include "stack.h" +#include <cgreen/cgreen.h> +#include <string.h> + +Describe(Stack); +BeforeEach(Stack) {} +AfterEach(Stack) {} + +Ensure(Stack, when_pushing_an_item_on_to_a_stack) { + Stack *stack = stack_init(); + + stack_push(stack, (void *)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, (void *)20); + stack_push(stack, (void *)10); + stack_push(stack, (void *)50); + + assert_that(stack_size(stack), is_equal_to(3)); + assert_that(stack_peek(stack), is_equal_to(50)); +} + +Ensure(Stack, when_pushing_a_custom_type_on_to_a_stack) { + typedef struct { + } Item; + + Stack *stack = stack_init(); + Item *item = malloc(sizeof(Item)); + + stack_push(stack, item); + + assert_that(stack_size(stack), is_equal_to(1)); + assert_that(stack_peek(stack), is_equal_to(item)); + assert_that(stack_pop(stack), is_equal_to(item)); +} + +Ensure(Stack, when_popping_an_item_off_of_a_stack) { + Stack *stack = stack_init(); + + stack_push(stack, (void *)20); + stack_push(stack, (void *)10); + stack_push(stack, (void *)50); + + void *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_pushing_a_custom_type_on_to_a_stack); + add_test_with_context(suite, Stack, when_popping_an_item_off_of_a_stack); + return suite; +} |
