diff --git a/test_stack.c b/test_stack.c index 8cef152..1bcb056 100644 --- a/test_stack.c +++ b/test_stack.c @@ -49,24 +49,20 @@ void test_push_and_top(void) void test_pop(void) { - StackNode *stack = NULL; + StackNode *stack = NULL; - int *x = malloc(sizeof(int)); *x = 111; - int *y = malloc(sizeof(int)); *y = 222; + int x = 111; + int y = 222; - stack = push(stack, x); - stack = push(stack, y); + stack = push(stack, &x); + stack = push(stack, &y); - void *data; - - stack = pop(stack, &data); - TEST_ASSERT_EQUAL_INT(222, *(int*)data); - free(data); - - stack = pop(stack, &data); - TEST_ASSERT_EQUAL_INT(111, *(int*)data); - free(data); + // pop removes y + stack = pop(stack); + TEST_ASSERT_EQUAL_INT(111, *(int*)top(stack)); + // pop removes x + stack = pop(stack); TEST_ASSERT_NULL(stack); }