forked from freudenreichan/info2Praktikum-DobleSpiel
Stack.C fertig gestellt
This commit is contained in:
parent
d816f405f0
commit
4d27f910ff
2
makefile
2
makefile
@ -49,7 +49,7 @@ stackTests: stack.o stackTests.c $(unityfolder)/unity.c
|
||||
# Clean
|
||||
# --------------------------
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
ifeq ($(OS),!Windows_NT)
|
||||
del /f *.o doble *.exe
|
||||
else
|
||||
rm -f *.o doble *runNumbersTests
|
||||
|
||||
19
stack.c
19
stack.c
@ -20,17 +20,28 @@ StackNode *push(StackNode *stack, void *data)
|
||||
// freed by caller.)
|
||||
StackNode *pop(StackNode *stack)
|
||||
{
|
||||
|
||||
if(stack == NULL)
|
||||
return NULL;
|
||||
StackNode *next = stack->next;
|
||||
free(stack);
|
||||
return next;
|
||||
}
|
||||
|
||||
// Returns the data of the top element.
|
||||
void *top(StackNode *stack)
|
||||
{
|
||||
|
||||
if(stack == NULL)
|
||||
return NULL;
|
||||
return stack->data;
|
||||
}
|
||||
|
||||
// Clears stack and releases all memory.
|
||||
void clearStack(StackNode *stack)
|
||||
{
|
||||
|
||||
}
|
||||
while(stack != NULL)
|
||||
{
|
||||
StackNode *next = stack->next;
|
||||
free(stack);
|
||||
stack = next;
|
||||
}
|
||||
}
|
||||
|
||||
30
stackTests.c
30
stackTests.c
@ -9,34 +9,20 @@ void tearDown(void){}
|
||||
|
||||
void test_push_created_new_stacknode(void)
|
||||
{
|
||||
StackNode test = {111,NULL};
|
||||
int testdata = 222;
|
||||
void *data =&testdata;
|
||||
int testdata1 = 111;
|
||||
StackNode test = {&testdata1,NULL};
|
||||
int testdata2 = 222;
|
||||
|
||||
StackNode test1 = push(&test,data);
|
||||
unsigned int n = 50;
|
||||
unsigned int* arr = createNumbers(n);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(arr);
|
||||
|
||||
// Ein paar Werte prüfen (dürfen alles sein, nur kein Segfault)
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
TEST_ASSERT_TRUE(arr[i] >= 0);
|
||||
|
||||
free(arr);
|
||||
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_createNumbers_returns_valid_array);
|
||||
RUN_TEST(test_createNumbers_contains_exactly_one_duplicate);
|
||||
RUN_TEST(test_getDuplicated_finds_correct_duplicate);
|
||||
|
||||
RUN_TEST(test_push_created_new_stacknode);
|
||||
return UNITY_END();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user