generated from freudenreichan/info2Praktikum-DobleSpiel
51 lines
1.1 KiB
C
51 lines
1.1 KiB
C
|
|
#include <stdint.h>
|
|
#include "unity.h"
|
|
#include "stack.h"
|
|
|
|
void setUp(void) {}
|
|
void tearDown(void) {}
|
|
|
|
static void push_n(StackNode **ps, int n) {
|
|
for (int i = 1; i <= n; ++i)
|
|
*ps = push(*ps, (void*)(intptr_t)i);
|
|
}
|
|
|
|
void test_empty_stack(void) {
|
|
StackNode *s = NULL;
|
|
TEST_ASSERT_NULL(top(s));
|
|
s = pop(s);
|
|
TEST_ASSERT_NULL(s);
|
|
clearStack(s); // kein Crash
|
|
}
|
|
|
|
void test_push_top_pop_order(void) {
|
|
StackNode *s = NULL;
|
|
push_n(&s, 3); // 1,2,3 -> Top = 3
|
|
TEST_ASSERT_EQUAL_INT(3, (int)(intptr_t)top(s));
|
|
s = pop(s); // 2
|
|
TEST_ASSERT_EQUAL_INT(2, (int)(intptr_t)top(s));
|
|
s = pop(s); // 1
|
|
TEST_ASSERT_EQUAL_INT(1, (int)(intptr_t)top(s));
|
|
s = pop(s); // NULL
|
|
TEST_ASSERT_NULL(s);
|
|
}
|
|
|
|
void test_clearStack_then_safe_ops(void) {
|
|
StackNode *s = NULL;
|
|
push_n(&s, 50);
|
|
clearStack(s);
|
|
s = NULL; // WICHTIG: externen Zeiger selbst nullen
|
|
TEST_ASSERT_NULL(top(s));
|
|
s = pop(s);
|
|
TEST_ASSERT_NULL(s);
|
|
}
|
|
|
|
int main(void) {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_empty_stack);
|
|
RUN_TEST(test_push_top_pop_order);
|
|
RUN_TEST(test_clearStack_then_safe_ops);
|
|
return UNITY_END();
|
|
}
|