generated from freudenreichan/info2Praktikum-DobleSpiel
56 lines
973 B
C
56 lines
973 B
C
//
|
|
// Created by faizi on 05.12.2025.
|
|
//
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "stack.h"
|
|
|
|
#define TEST(description, condition) \
|
|
printf("%-40s: %s\n", description, (condition) ? "OK" : "FAIL")
|
|
|
|
int main(void)
|
|
{
|
|
StackNode *stack = NULL;
|
|
|
|
printf("Starte Stack Test\n");
|
|
|
|
// push test
|
|
int *a = malloc(sizeof(int));
|
|
int *b = malloc(sizeof(int));
|
|
*a = 10;
|
|
*b = 20;
|
|
|
|
|
|
printf("Starte Unit Tests fuer Stack\n");
|
|
stack = push(stack, a);
|
|
stack = push(stack, b);
|
|
|
|
TEST("Top nach zwei Pushes == 20", *(int*)top(stack) == 20);
|
|
|
|
|
|
// pop test
|
|
stack = pop(stack);
|
|
TEST("Top == 10 nach Pop", *(int*)top(stack) == 10);
|
|
|
|
|
|
stack = pop(stack);
|
|
TEST("Stack leer nach zwei Pops", stack == NULL);
|
|
|
|
|
|
|
|
stack = push(stack, a);
|
|
stack = push(stack, b);
|
|
|
|
// clearStack test
|
|
|
|
clearStack(stack);
|
|
stack = NULL;
|
|
|
|
TEST("clearStack ausgefuehrt (kein crash)", 1);
|
|
|
|
free(a);
|
|
free(b);
|
|
|
|
return 0;
|
|
|
|
} |