From 8f4ab58000727bf2fb135599630479058af8a207 Mon Sep 17 00:00:00 2001 From: Alexei Date: Thu, 11 Dec 2025 11:23:31 +0100 Subject: [PATCH] =?UTF-8?q?test=5Fpop=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_stack.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) 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); }