Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b0fa4601a | ||
|
|
f59489779b | ||
|
|
31a76162ee | ||
|
|
4cfe6d9c50 | ||
|
|
82c72eaf81 |
@@ -13,7 +13,7 @@ StackNode *push(StackNode *stack, void *data)
|
|||||||
StackNode *tempNode, *newNode;
|
StackNode *tempNode, *newNode;
|
||||||
|
|
||||||
newNode = malloc(sizeof(StackNode));
|
newNode = malloc(sizeof(StackNode));
|
||||||
newNode->value = 3;
|
newNode->value = *(int *)data;
|
||||||
newNode->next = NULL;
|
newNode->next = NULL;
|
||||||
|
|
||||||
if (stack == NULL)
|
if (stack == NULL)
|
||||||
|
|||||||
@@ -3,6 +3,28 @@
|
|||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
|
||||||
|
void test_push(void)
|
||||||
|
{
|
||||||
|
StackNode *testNode;
|
||||||
|
int data = 1;
|
||||||
|
|
||||||
|
// Test für leeren Stack
|
||||||
|
testNode = push(NULL, &data);
|
||||||
|
TEST_ASSERT_NOT_NULL(&testNode);
|
||||||
|
TEST_ASSERT_NULL(testNode->next);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, testNode->value);
|
||||||
|
|
||||||
|
data = 2;
|
||||||
|
|
||||||
|
// Test für nicht leeren Stack
|
||||||
|
testNode = push(testNode, &data);
|
||||||
|
TEST_ASSERT_NOT_NULL(&testNode);
|
||||||
|
TEST_ASSERT_NOT_NULL(testNode->next);
|
||||||
|
TEST_ASSERT_NULL(testNode->next->next);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, testNode->value);
|
||||||
|
TEST_ASSERT_EQUAL_INT(2, testNode->next->value);
|
||||||
|
}
|
||||||
|
|
||||||
StackNode* setup(int value, StackNode* next) {
|
StackNode* setup(int value, StackNode* next) {
|
||||||
StackNode* node = malloc(sizeof(StackNode)); // allocate memory on heap
|
StackNode* node = malloc(sizeof(StackNode)); // allocate memory on heap
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
@@ -81,6 +103,7 @@ int main()
|
|||||||
|
|
||||||
printf("============================\nStack tests\n============================\n");
|
printf("============================\nStack tests\n============================\n");
|
||||||
|
|
||||||
|
RUN_TEST(test_push);
|
||||||
RUN_TEST(test_pop);
|
RUN_TEST(test_pop);
|
||||||
RUN_TEST(test_top);
|
RUN_TEST(test_top);
|
||||||
RUN_TEST(test_clear);
|
RUN_TEST(test_clear);
|
||||||
|
|||||||
Reference in New Issue
Block a user