test_pop überarbeitet

This commit is contained in:
Alexei Keller 2025-12-11 11:23:31 +01:00
parent be37b3ff21
commit 8f4ab58000

View File

@ -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);
}