summaryrefslogtreecommitdiff
path: root/src/02/05/stack_test.c
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-08-09 15:47:03 -0600
committermo khan <mo.khan@gmail.com>2020-08-09 15:47:03 -0600
commit7c4da6d24d54a971a4e918c3a327e052f4685ccb (patch)
treebf2e8cca2a93c0605a54c5218caea446e9c0833c /src/02/05/stack_test.c
parentce1f797f4af5aee2574a021fd24c0c7405870f45 (diff)
Allow storing void* on Stack
Diffstat (limited to 'src/02/05/stack_test.c')
-rw-r--r--src/02/05/stack_test.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/02/05/stack_test.c b/src/02/05/stack_test.c
index 5c74290..f53fe58 100644
--- a/src/02/05/stack_test.c
+++ b/src/02/05/stack_test.c
@@ -9,7 +9,7 @@ AfterEach(Stack) {}
Ensure(Stack, when_pushing_an_item_on_to_a_stack) {
Stack *stack = stack_init();
- stack_push(stack, 10);
+ stack_push(stack, (void *)10);
assert_that(stack_size(stack), is_equal_to(1));
assert_that(stack_peek(stack), is_equal_to(10));
@@ -18,22 +18,36 @@ Ensure(Stack, when_pushing_an_item_on_to_a_stack) {
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);
+ 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, 20);
- stack_push(stack, 10);
- stack_push(stack, 50);
+ stack_push(stack, (void *)20);
+ stack_push(stack, (void *)10);
+ stack_push(stack, (void *)50);
- int result = stack_pop(stack);
+ void *result = stack_pop(stack);
assert_that(stack_size(stack), is_equal_to(2));
assert_that(stack_peek(stack), is_equal_to(10));