summaryrefslogtreecommitdiff
path: root/src/01/01b/stack_test.c
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-07-04 16:31:05 -0600
committermo khan <mo.khan@gmail.com>2020-07-04 16:31:05 -0600
commitc52aa3f75385c5618ab6bd5ab279775c4da2d1ae (patch)
tree18c3236e5b3f005f0033149995ac362771ca7818 /src/01/01b/stack_test.c
parent2c86d809386422e34899503567cd88a57d170e1b (diff)
Add specs for boundary cases
Diffstat (limited to 'src/01/01b/stack_test.c')
-rw-r--r--src/01/01b/stack_test.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/01/01b/stack_test.c b/src/01/01b/stack_test.c
index 457f656..b05f278 100644
--- a/src/01/01b/stack_test.c
+++ b/src/01/01b/stack_test.c
@@ -1,5 +1,6 @@
-#include <cgreen/cgreen.h>
#include "stack.h"
+#include <cgreen/cgreen.h>
+#include <math.h>
Describe(Stack);
BeforeEach(Stack){ }
@@ -38,12 +39,35 @@ Ensure(Stack, pop_successive_items) {
destroy(stack);
}
+Ensure(Stack, when_popping_an_item_off_an_empty_stack) {
+ Stack *stack = initialize();
+
+ assert_that(pop(stack), is_equal_to(NULL));
+
+ destroy(stack);
+}
+
+Ensure(Stack, when_pushing_an_item_on_to_a_full_stack) {
+ Stack *stack = initialize();
+ int max = 2147483647;
+
+ for (int i = 0; i < max; i++)
+ push(stack, 1);
+
+ push(stack, 1);
+
+ assert_that(size(stack), is_equal_to(max));
+ destroy(stack);
+}
+
TestSuite *stack_tests() {
TestSuite *suite = create_test_suite();
- add_test_with_context(suite, Stack, push_onto_stack);
add_test_with_context(suite, Stack, pop_single_item);
add_test_with_context(suite, Stack, pop_successive_items);
+ add_test_with_context(suite, Stack, push_onto_stack);
+ add_test_with_context(suite, Stack, when_popping_an_item_off_an_empty_stack);
+ add_test_with_context(suite, Stack, when_pushing_an_item_on_to_a_full_stack);
return suite;
}