diff --git a/test_stack.c b/test_stack.c index abd14c0..9f14a45 100644 --- a/test_stack.c +++ b/test_stack.c @@ -18,11 +18,65 @@ void test_createNode(void) { free(testNode); } -void test_pushDataToStack(void) {} +void test_pushDataToStack(void) { -void test_deleteTopElement(void) {} + int testInt = 27; -void test_returnData(void) {} + StackNode *testNode = push(NULL, &testInt); + + TEST_ASSERT_NOT_NULL(testNode); + TEST_ASSERT_EQUAL_PTR(&testInt, testNode->data); + TEST_ASSERT_NULL(testNode->next); + TEST_ASSERT_NULL(testNode->prev); + + free(testNode); +} + +void test_deleteTopElement(void) { + + int testInts[] = {10, 20, 30}; + StackNode *stack = NULL; + + for (int i = 0; i < 3; i++) { + stack = push(stack, &testInts[i]); + } + + TEST_ASSERT_EQUAL_PTR(&testInts[2], top(stack)); + + stack = pop(stack); + TEST_ASSERT_EQUAL_PTR(&testInts[1], top(stack)); + + stack = pop(stack); + TEST_ASSERT_EQUAL_PTR(&testInts[0], top(stack)); + + stack = pop(stack); + TEST_ASSERT_NULL(stack); +} + +void test_returnData(void) { + + int testInts[] = {10, 20, 30}; + StackNode *stack = NULL; + + for (int i = 0; i < 3; i++) { + stack = push(stack, &testInts[i]); + } + + TEST_ASSERT_EQUAL_PTR(&testInts[2], top(stack)); + + if (stack->next != NULL) { + TEST_ASSERT_EQUAL_PTR(&testInts[1], stack->next->data); + if (stack->next->next != NULL) { + TEST_ASSERT_EQUAL_PTR(&testInts[0], stack->next->next->data); + } + } + + StackNode *last = stack; + while (last->next != NULL) { + last = last->next; + } + TEST_ASSERT_NULL(last->next); +} void test_clearStack(void) { int testInts[] = {1, 2, 3, 4, 5}; @@ -51,7 +105,6 @@ int main(void) { RUN_TEST(test_deleteTopElement); RUN_TEST(test_returnData); RUN_TEST(test_clearStack); - RUN_TEST(test_clearStack); return UNITY_END(); }