forked from freudenreichan/info2Praktikum-DobleSpiel
68 lines
1.2 KiB
C
68 lines
1.2 KiB
C
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include "stack.h"
|
|
|
|
void setUp(void)
|
|
{
|
|
}
|
|
void tearDown(void)
|
|
{
|
|
}
|
|
|
|
static void test_empty_stack(void)
|
|
{
|
|
StackNode *stack = NULL;
|
|
assert(top(stack) == NULL);
|
|
assert(pop(stack) == NULL);
|
|
clearStack(stack);
|
|
}
|
|
|
|
static void test_push_top_pop_int(void)
|
|
{
|
|
StackNode *stack = NULL;
|
|
int a = 10;
|
|
int b = 20;
|
|
int c = 30;
|
|
|
|
stack = push(stack, &a);
|
|
assert(top(stack) == &a);
|
|
assert(*(int *)top(stack) == 10);
|
|
|
|
stack = push(stack, &b);
|
|
stack = push(stack, &c);
|
|
assert(*(int *)top(stack) == 30);
|
|
|
|
stack = pop(stack);
|
|
assert(*(int *)top(stack) == 20);
|
|
|
|
stack = pop(stack);
|
|
assert(*(int *)top(stack) == 10);
|
|
|
|
stack = pop(stack);
|
|
assert(stack == NULL);
|
|
assert(top(stack) == NULL);
|
|
}
|
|
|
|
static void test_clear_stack(void)
|
|
{
|
|
StackNode *stack = NULL;
|
|
int values[] = {1, 2, 3, 4, 5};
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
stack = push(stack, &values[i]);
|
|
}
|
|
|
|
assert(*(int *)top(stack) == 5);
|
|
|
|
clearStack(stack);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
test_empty_stack();
|
|
test_push_top_pop_int();
|
|
test_clear_stack();
|
|
|
|
printf("Alle Stack-Tests erfolgreich bestanden!\n");
|
|
return 0;
|
|
} |