//myHelper/DynamicInt64Array.h //Matthew Ellison // Created: 03-08-19 //Modified: 03-09-19 //This is the test for my dynamic array in c /* Copyright (C) 2019 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include #include "DynamicInt64Array.h" int main(){ printf("BEGIN TESTS\n\n\n"); //Define a dynamic array struct DynamicInt64Array testAry; //Initialize the array initDynamicInt64Array(&testAry); //Set some elements in the array pushBackDynamicInt64Array(&testAry, 0); pushBackDynamicInt64Array(&testAry, 1); pushBackDynamicInt64Array(&testAry, 2); pushBackDynamicInt64Array(&testAry, 3); pushBackDynamicInt64Array(&testAry, 4); pushBackDynamicInt64Array(&testAry, 5); if((testAry.ptr[0] == 0) && (testAry.ptr[1] == 1) && (testAry.ptr[2] == 2) && (testAry.ptr[3] == 3) && (testAry.ptr[4] == 4) && (testAry.ptr[5] == 5)){ printf("Adding numbers to the array worked correctly\n"); } else{ printf("Something went wrong adding numbers to the array\n"); printf("The numbers are: %d %d %d %d %d %d\n", testAry.ptr[0], testAry.ptr[1], testAry.ptr[2], testAry.ptr[3], testAry.ptr[4], testAry.ptr[5]); return 1; } //Check that the size is correct if(testAry.size != 6){ printf("Something is wrong with the size: %d\nIt should be &d\n", testAry.size, 6); return 1; } if(testAry.allocated != 8){ printf("Something is wrong with the allocated size: %d\nIt should be %d\n", testAry.allocated, 8); return 1; } //Get some elements from the array if((getDynamicInt64Array(&testAry, 0) == 0) && (getDynamicInt64Array(&testAry, 4) == 4) && (getDynamicInt64Array(&testAry, 6) == 0)){ printf("The get function is working correctly\n"); } else{ printf("The get function has a problem. The numbers are:\n%d %d %d\nThe numbers should be:\n%d %d %d", getDynamicInt64Array(&testAry, 0), getDynamicInt64Array(&testAry, 4), getDynamicInt64Array(&testAry, 6), 0, 4, 0); return 1; } //Search the array for an element if((findDynamicInt64Array(&testAry, 5) == 5) && (findDynamicInt64Array(&testAry, 3) == 3) && (findDynamicInt64Array(&testAry, 7) == -1)){ printf("The find function is working correctly\n"); } else{ printf("The find function has a problem\nThe numbers are: %d %d %d\nThey should be: %d %d %d\n", findDynamicInt64Array(&testAry, 5), findDynamicInt64Array(&testAry, 3), findDynamicInt64Array(&testAry, 7), 5, 3, -1); return 1; } //Add an element to the array pushBackDynamicInt64Array(&testAry, 6); if(testAry.ptr[6] == 6){ printf("The pushback function is working correctly\n"); } else{ printf("There is a problem in the pushback function\n"); return 1; } if(testAry.size != 7){ printf("There is a problem with the size after adding to the array\n"); printf("The size is %d and it should be %d\n", testAry.size, 7); return 1; } //Remove an element from the array removeDynamicInt64Array(&testAry, 2); if((testAry.ptr[2] == 3) && (testAry.ptr[3] == 4) && (testAry.ptr[4] == 5) && (testAry.ptr[5] == 6)){ printf("Removing funcion is working correctly\n"); } else{ printf("There is a problem with the remove function\n"); return 1; } if(testAry.size != 6){ printf("There is a problem with the size after using the remove function\n"); return 1; } removeLocationDynamicInt64Array(&testAry, 4); if(testAry.ptr[4] == 6){ printf("RemoveLocation function is working correctly\n"); } else{ printf("There is a problem with the removeLocation function\n"); printf("The number is %d it should be %d\n", testAry.ptr[4], 6); return 1; } if(testAry.size != 5){ printf("There is a problem with the size after using the removeLocation function\n"); return 1; } //Release all of the memory allocated by the array destroyDynamicInt64Array(&testAry); printf("\n\nEND OF TESTS\n"); return 0; } /* Results: BEGIN TESTS Adding numbers to the array worked correctly The get function is working correctly The find function is working correctly The pushback function is working correctly Removing funcion is working correctly RemoveLocation function is working correctly END OF TESTS */