added test_push and fixed stack cast
This commit is contained in:
parent
82c72eaf81
commit
4cfe6d9c50
3
stack.c
3
stack.c
@ -13,8 +13,7 @@ StackNode *push(StackNode *stack, void *data)
|
||||
StackNode *tempNode, *newNode;
|
||||
|
||||
newNode = malloc(sizeof(StackNode));
|
||||
newNode->value = (intptr_t) data;
|
||||
//newNode->value = 3;
|
||||
newNode->value = *(int *)data;
|
||||
newNode->next = NULL;
|
||||
|
||||
if (stack == NULL)
|
||||
|
||||
22
test_stack.c
22
test_stack.c
@ -5,15 +5,31 @@
|
||||
|
||||
void test_push(void)
|
||||
{
|
||||
StackNode *testNode;
|
||||
int data = 1;
|
||||
|
||||
int value = 3;
|
||||
TEST_ASSERT_NOT_NULL(push(NULL, &value));
|
||||
TEST_ASSERT_EQUAL_INT(value, (intptr_t) push(NULL, &value)->value);
|
||||
// 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);
|
||||
}
|
||||
|
||||
void test_pop(void)
|
||||
{
|
||||
|
||||
TEST_ASSERT_NULL(pop(NULL));
|
||||
|
||||
}
|
||||
|
||||
void test_top(void)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user