weitere test funktionen bearbeitet

This commit is contained in:
Alexei Keller 2025-12-11 11:25:45 +01:00
parent 8f4ab58000
commit 3b0a8a24ff

View File

@ -24,26 +24,22 @@ int main(void)
return UNITY_END();
}
void test_push_and_top(void)
{
StackNode *stack = NULL;
int *a = malloc(sizeof(int)); *a = 10;
int *b = malloc(sizeof(int)); *b = 20;
int *c = malloc(sizeof(int)); *c = 30;
int a = 10;
int b = 20;
int c = 30;
stack = push(stack, a);
stack = push(stack, b);
stack = push(stack, c);
stack = push(stack, &a);
stack = push(stack, &b);
stack = push(stack, &c);
TEST_ASSERT_EQUAL_INT(30, *(int*)top(stack));
// Cleanup data manually
void *data;
stack = pop(stack, &data); free(data);
stack = pop(stack, &data); free(data);
stack = pop(stack, &data); free(data);
clearStack(&stack);
TEST_ASSERT_NULL(stack);
}
@ -70,17 +66,11 @@ void test_clearStack(void)
{
StackNode *stack = NULL;
int *p = malloc(sizeof(int)); *p = 7;
int *q = malloc(sizeof(int)); *q = 8;
int x = 5;
int y = 6;
stack = push(stack, p);
stack = push(stack, q);
// Pop to free data first!
void *data;
stack = pop(stack, &data); free(data);
stack = pop(stack, &data); free(data);
stack = push(stack, &x);
stack = push(stack, &y);
clearStack(&stack);