#include "unity.h" #include "stack.h" void test_stackCreate() { int* firstData = calloc(1, sizeof(int)); *firstData = 1; StackNode* initial = push(NULL, firstData); TEST_ASSERT_EQUAL_INT(1, *((int *)initial->data)); TEST_ASSERT_NULL(initial->left); TEST_ASSERT_NULL(initial->right); } void test_stackPush() { int* firstData = calloc(1, sizeof(int)); *firstData = 1; int* secondData = calloc(1, sizeof(int)); *secondData = 2; StackNode* tree = push(NULL, firstData); tree = push(tree, secondData); TEST_ASSERT_EQUAL_INT(2, *((int *)tree->data)); TEST_ASSERT_EQUAL_INT(2, *((int*)top(tree))); } void test_stackPop() { int* firstData = calloc(1, sizeof(int)); *firstData = 1; int* secondData = calloc(1, sizeof(int)); *secondData = 2; StackNode* tree = push(NULL, firstData); tree = push(tree, secondData); free(tree->data); tree = pop(tree); TEST_ASSERT_EQUAL_INT(1, *((int*)top(tree))); } // void test_stackClear() { // int* firstData = calloc(1, sizeof(int)); // *firstData = 1; // int* secondData = calloc(1, sizeof(int)); // *secondData = 2; // StackNode* stack = push(NULL, firstData); // stack = push(stack, secondData); // clearStack(stack); // TEST_ASSERT_NULL(stack); // } void setUp(void) { // Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden } void tearDown(void) { // Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden } int main() { UNITY_BEGIN(); printf("\n============================\nStack tests\n============================\n"); RUN_TEST(test_stackCreate); RUN_TEST(test_stackPush); RUN_TEST(test_stackPop); // RUN_TEST(test_stackClear); return UNITY_END(); }