forked from freudenreichan/info2Praktikum-DobleSpiel
130 lines
2.6 KiB
C
130 lines
2.6 KiB
C
/*#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "stack.h"
|
|
#include "unity.h"
|
|
|
|
//Initialisierung
|
|
void setUp(void){}
|
|
void tearDown(void){}
|
|
|
|
void test_push_created_new_stacknode(void)
|
|
{
|
|
int testdata1 = 111;
|
|
StackNode test = {&testdata1,NULL};
|
|
int testdata2 = 222;
|
|
|
|
StackNode *test1 = push(&test,&testdata2);
|
|
TEST_ASSERT_NOT_NULL(test1);
|
|
TEST_ASSERT_EQUAL_PTR(&testdata2,test1->data);
|
|
TEST_ASSERT_EQUAL_PTR(&test,test1->next);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
UNITY_BEGIN();
|
|
|
|
RUN_TEST(test_push_created_new_stacknode);
|
|
return UNITY_END();
|
|
}*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "stack.h"
|
|
#include "unity.h"
|
|
|
|
void setUp(void){}
|
|
void tearDown(void){}
|
|
|
|
/* ---------------- PUSH ---------------- */
|
|
|
|
void test_push_created_new_stacknode(void)
|
|
{
|
|
int testdata1 = 111;
|
|
StackNode test = {&testdata1,NULL};
|
|
int testdata2 = 222;
|
|
|
|
StackNode *test1 = push(&test,&testdata2);
|
|
TEST_ASSERT_NOT_NULL(test1);
|
|
TEST_ASSERT_EQUAL_PTR(&testdata2,test1->data);
|
|
TEST_ASSERT_EQUAL_PTR(&test,test1->next);
|
|
}
|
|
|
|
/* ---------------- TOP ---------------- */
|
|
|
|
void test_top_on_empty_stack_returns_null(void)
|
|
{
|
|
TEST_ASSERT_NULL(top(NULL));
|
|
}
|
|
|
|
void test_top_returns_top_element(void)
|
|
{
|
|
int data = 42;
|
|
StackNode node = {&data, NULL};
|
|
|
|
TEST_ASSERT_EQUAL_PTR(&data, top(&node));
|
|
}
|
|
|
|
/* ---------------- POP ---------------- */
|
|
|
|
void test_pop_on_empty_stack_returns_null(void)
|
|
{
|
|
TEST_ASSERT_NULL(pop(NULL));
|
|
}
|
|
|
|
void test_pop_removes_top_element(void)
|
|
{
|
|
int d1 = 1;
|
|
int d2 = 2;
|
|
|
|
StackNode *s = NULL;
|
|
s = push(s, &d1);
|
|
s = push(s, &d2);
|
|
|
|
StackNode *newTop = pop(s);
|
|
|
|
TEST_ASSERT_NOT_NULL(newTop);
|
|
TEST_ASSERT_EQUAL_PTR(&d1, newTop->data);
|
|
|
|
clearStack(newTop); // Speicher aufräumen
|
|
}
|
|
|
|
/* ---------------- CLEAR ---------------- */
|
|
|
|
void test_clearStack_on_empty_stack_does_not_crash(void)
|
|
{
|
|
clearStack(NULL);
|
|
TEST_PASS(); // Test besteht, wenn kein Crash
|
|
}
|
|
|
|
void test_clearStack_clears_multiple_elements(void)
|
|
{
|
|
int d1 = 1, d2 = 2, d3 = 3;
|
|
|
|
StackNode *s = NULL;
|
|
s = push(s, &d1);
|
|
s = push(s, &d2);
|
|
s = push(s, &d3);
|
|
|
|
clearStack(s);
|
|
|
|
TEST_PASS(); // kein Crash = bestanden
|
|
}
|
|
|
|
/* ---------------- MAIN ---------------- */
|
|
|
|
int main(void)
|
|
{
|
|
UNITY_BEGIN();
|
|
|
|
RUN_TEST(test_push_created_new_stacknode);
|
|
|
|
RUN_TEST(test_top_on_empty_stack_returns_null);
|
|
RUN_TEST(test_top_returns_top_element);
|
|
|
|
RUN_TEST(test_pop_on_empty_stack_returns_null);
|
|
RUN_TEST(test_pop_removes_top_element);
|
|
|
|
RUN_TEST(test_clearStack_on_empty_stack_does_not_crash);
|
|
RUN_TEST(test_clearStack_clears_multiple_elements);
|
|
|
|
return UNITY_END();
|
|
} |