#include #include #include #include "stack.h" void test_pushFailsOnNullPointer(StackNode *stack, void *data) { StackNode* test = push(NULL, data); if (test != 0) { printf("Pass test_pushFailsOnNullPointerStack\n"); } else printf("Did Not Pass test_pushFailsOnNullPointerStack EXPECTED Stac Node\n"); StackNode* test = push(stack, NULL); if (test == 0) { printf("Pass test_pushFailsOnNullPointerData\n"); return; } printf("Did Not Pass test_pushFailsOnNullPointerData EXPECTED 0\n"); return; } void test_popFailsOnNullPointer() { StackNode* test = pop(NULL); if (test == 0) { printf("Pass test_pushFailsOnNullPointerStack\n"); return; } printf("Did Not Pass test_pushFailsOnNullPointerStack EXPECTED 0\n"); return; } void test_topFailsOnNullPointer() { int* test = top(NULL); if (test == 0) { printf("Pass test_pushFailsOnNullPointerStack\n"); return; } printf("Did Not Pass test_pushFailsOnNullPointerStack EXPECTED 0\n"); return; } int main() { StackNode *stack0 = NULL; int test0 = 3; int* dataTest0 = &test0; stack0->data = dataTest0; char test1[5] = "test\0"; char* dataTest1 = &test1; float test2 = 3.14; float* dataTest2 = &test2; printf("============================\nstack tests\n============================\n"); test_pushFailsOnNullPointer(stack0, dataTest0); test_popFailsOnNullPointer(); test_topFailsOnNullPointer(); StackNode *stack1 = push(stack0, dataTest1); if(strcmp(stack1->data ,dataTest1) == 0) { printf("Pass test_pushString\n"); } else printf("Fails test_pushString\n expected: %s\n was: %s\n", dataTest1, stack1->data); StackNode *stack2 = push(stack1, dataTest2); if(stack2->data == dataTest2) { printf("Pass test_pushFloat\n"); } else printf("Fails test_pushFloat\n expected: %f\n was: %d\n", dataTest2, stack2->data); int array[10] = {1,2,3,4,5,6,7,8,9,10}; for(size_t i = 0; i<10; i++) { stack2 = push(stack2, &array[i]); } for(size_t i = 0; i<10; i++) { int* data = top(stack2); printf("%d\n", data); stack2 = pop(stack2); } return EXIT_SUCCESS; }