int main () { list_t* listPtr; #ifdef LIST_NO_DUPLICATES long data1[] = {3, 1, 4, 1, 5, -1}; #else long data1[] = {3, 1, 4, 5, -1}; #endif long data2[] = {3, 1, 4, 1, 5, -1}; long i; puts("Starting..."); puts("List sorted by values:"); listPtr = list_alloc(&compare); for (i = 0; data1[i] >= 0; i++) { insertInt(listPtr, &data1[i]); assert(*((long*)list_find(listPtr, &data1[i])) == data1[i]); } for (i = 0; data1[i] >= 0; i++) { removeInt(listPtr, &data1[i]); assert(list_find(listPtr, &data1[i]) == NULL); } list_free(listPtr); puts("List sorted by addresses:"); listPtr = list_alloc(NULL); for (i = 0; data2[i] >= 0; i++) { insertInt(listPtr, &data2[i]); assert(*((long*)list_find(listPtr, &data2[i])) == data2[i]); } for (i = 0; data2[i] >= 0; i++) { removeInt(listPtr, &data2[i]); assert(list_find(listPtr, &data2[i]) == NULL); } list_free(listPtr); puts("Done."); return 0; }
int main () { long data[] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7}; long numData = sizeof(data) / sizeof(data[0]); long i; puts("Starting..."); rbtree_t* rbtreePtr = rbtree_alloc(&compare); assert(rbtreePtr); for (i = 0; i < numData; i++) { insertInt(rbtreePtr, &data[i]); } for (i = 0; i < numData; i++) { removeInt(rbtreePtr, &data[i]); } rbtree_free(rbtreePtr); puts("Done."); return 0; }
int main () { hashtable_t* hashtablePtr; long data[] = {3, 1, 4, 1, 5, 9, 2, 6, 8, 7, -1}; long i; puts("Starting..."); hashtablePtr = hashtable_alloc(1, &hash, &comparePairs, -1, -1); for (i = 0; data[i] >= 0; i++) { insertInt(hashtablePtr, &data[i]); assert(*(long*)hashtable_find(hashtablePtr, &data[i]) == data[i]); } for (i = 0; data[i] >= 0; i++) { removeInt(hashtablePtr, &data[i]); assert(hashtable_find(hashtablePtr, &data[i]) == NULL); } hashtable_free(hashtablePtr); puts("Done."); return 0; }
int main () { puts("Starting..."); heap_t* heapPtr = heap_alloc(1, compare); assert(heapPtr); long i; for (i = 0; i < global_numData; i++) { insertInt(heapPtr, &global_data[i]); } for (i = 0; i < global_numData; i++) { removeInt(heapPtr); } assert(heap_remove(heapPtr) == NULL); /* empty */ heap_free(heapPtr); puts("Passed all tests."); return 0; }
int main () { vector_t* vectorPtr; vector_t* copyVectorPtr; long data[] = {3, 1, 4, 1, 5, -1}; long i; puts("Starting..."); vectorPtr = vector_alloc(1); copyVectorPtr = vector_alloc(1); for (i = 0; data[i] >= 0; i++) { insertInt(vectorPtr, &data[i]); } vector_copy(copyVectorPtr, vectorPtr); while (i-- > 0) { removeInt(vectorPtr); } printf("copy "); printVector(copyVectorPtr); printf("sort "); vector_sort(copyVectorPtr, &compareInt); printVector(copyVectorPtr); vector_free(vectorPtr); vector_free(copyVectorPtr); puts("Done."); return 0; }