forked from freudenreichan/info2Praktikum-DobleSpiel
Mein Teil (Sollte Fertig sein)
This commit is contained in:
1 parent
e7a872252a
commit
89067a7ba6
4 files changed
+100
-14
No files matched your search
@@ -0,0 +1,68 @@
|
||||
#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;
|
||||
}
|
||||
Reference in new issue
Block a user