diff options
| author | mo khan <mo.khan@gmail.com> | 2020-07-04 13:04:54 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-07-04 13:04:54 -0600 |
| commit | 24700ade3ae9ff643b0c092ff617fb065d9f19f1 (patch) | |
| tree | 186b70d02e3c9ab11c54ea9d3ff81f167ec6148f /src/01/06/min_stack_test.c | |
| parent | e93f71c94f7f70b759cd442fa7d66c2a25ee3800 (diff) | |
Switch 06 and 01b
Diffstat (limited to 'src/01/06/min_stack_test.c')
| -rw-r--r-- | src/01/06/min_stack_test.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/01/06/min_stack_test.c b/src/01/06/min_stack_test.c new file mode 100644 index 0000000..a02c163 --- /dev/null +++ b/src/01/06/min_stack_test.c @@ -0,0 +1,87 @@ +#include <cgreen/cgreen.h> +#include "min_stack.h" + +Describe(MinStack); +BeforeEach(MinStack){ } +AfterEach(MinStack){ } + +Ensure(MinStack, when_empty) { + Stack *stack = initialize(); + + assert_that(size(stack), is_equal_to(0)); + assert_that(min(stack), is_equal_to(NULL)); + assert_that(pop(stack), is_equal_to(NULL)); + + free(stack); +} + +Ensure(MinStack, when_pushing_a_single_integer) { + Stack *stack = initialize(); + + push(stack, 1); + + assert_that(size(stack), is_equal_to(1)); + assert_that(min(stack), is_equal_to(1)); + assert_that(pop(stack), is_equal_to(1)); + assert_that(size(stack), is_equal_to(0)); + + free(stack); +} + +Ensure(MinStack, when_pushing_multiple_integers_out_of_order) { + Stack *stack = initialize(); + + push(stack, 2); + push(stack, 3); + push(stack, 1); + + assert_that(size(stack), is_equal_to(3)); + assert_that(min(stack), is_equal_to(1)); + + assert_that(pop(stack), is_equal_to(1)); + assert_that(size(stack), is_equal_to(2)); + + assert_that(pop(stack), is_equal_to(2)); + assert_that(size(stack), is_equal_to(1)); + + assert_that(pop(stack), is_equal_to(3)); + assert_that(size(stack), is_equal_to(0)); + + assert_that(pop(stack), is_equal_to(NULL)); + assert_that(size(stack), is_equal_to(0)); + + free(stack); +} + +Ensure(MinStack, when_pushing_duplicate_values_on_to_the_stack) { + Stack *stack = initialize(); + + push(stack, 2); + push(stack, 1); + push(stack, 2); + + assert_that(size(stack), is_equal_to(3)); + assert_that(min(stack), is_equal_to(1)); + + assert_that(pop(stack), is_equal_to(1)); + assert_that(pop(stack), is_equal_to(2)); + assert_that(pop(stack), is_equal_to(2)); + assert_that(pop(stack), is_equal_to(NULL)); + + free(stack); +} + +TestSuite *min_stack_tests() { + TestSuite *suite = create_test_suite(); + + add_test_with_context(suite, MinStack, when_empty); + add_test_with_context(suite, MinStack, when_pushing_a_single_integer); + add_test_with_context(suite, MinStack, when_pushing_multiple_integers_out_of_order); + return suite; +} + +int main(int argc, char **argv) { + TestSuite *suite = create_test_suite(); + add_suite(suite, min_stack_tests()); + return run_test_suite(suite, create_text_reporter()); +} |
