// tester for spBPQueueCopy static bool bpqCopyTest() { SPBPQueue source, source2, copy, copy2; SPListElement e1, e2, e3, e4, epeek; ASSERT_TRUE(spBPQueueCopy(NULL) == NULL); // check edge case source = spBPQueueCreate(10); copy = spBPQueueCopy(source); ASSERT_TRUE(copy != NULL); ASSERT_TRUE(0 == spBPQueueSize(copy)); // e1, e2, e3, e4 CREATE_4_ELEMENTS() spBPQueueEnqueue(source, e1); ASSERT_TRUE(0 == spBPQueueSize(copy)); // ensure the copy is a NEW COPY source2 = quickQ(4, e1, e2, e3, e4); copy2 = spBPQueueCopy(source2); ASSERT_TRUE(4 == spBPQueueSize(copy2)); // check that size of copy is correct // check that all elements copied correctly epeek = spBPQueuePeek(copy2); ASSERT_TRUE(spListElementCompare(e1, epeek) == 0); spBPQueueDequeue(copy2); spListElementDestroy(epeek); // free the element // repeat epeek = spBPQueuePeek(copy2); ASSERT_TRUE(spListElementCompare(e2, epeek) == 0); spBPQueueDequeue(copy2); spListElementDestroy(epeek); epeek = spBPQueuePeek(copy2); ASSERT_TRUE(spListElementCompare(e3, epeek) == 0); spBPQueueDequeue(copy2); spListElementDestroy(epeek); epeek = spBPQueuePeek(copy2); ASSERT_TRUE(spListElementCompare(e4, epeek) == 0); spBPQueueDequeue(copy2); spListElementDestroy(epeek); epeek = spBPQueuePeek(copy2); ASSERT_TRUE(epeek == NULL); // free all remaining memory spListElementDestroy(epeek); spBPQueueDestroy(source); spBPQueueDestroy(source2); spBPQueueDestroy(copy); spBPQueueDestroy(copy2); // e1, e2, e3, e4 DESTROY_4_ELEMENTS() return true; }
//general test bool verifyKNN(SPBPQueue rsltQueue, int k,SPPoint* pointsArray,SPPoint queryPoint, int numOfPoints){ SPBPQueue workingQueue = NULL; SPListElement tempElement = NULL; SP_BPQUEUE_MSG msg; bool emptyFlag; int i, queueSize; int* rsltsArray; if (rsltQueue == NULL || pointsArray == NULL || queryPoint == NULL) return false; workingQueue = spBPQueueCopy(rsltQueue); ASSERT_TRUE(workingQueue != NULL); rsltsArray = getRealRsltsArray(k,pointsArray,queryPoint,numOfPoints); if (rsltsArray == NULL){ spBPQueueDestroy(workingQueue); return false; } queueSize = spBPQueueSize(workingQueue); for (i = 0; i< queueSize ; i++){ tempElement = spBPQueuePeek(workingQueue); if (spListElementGetIndex(tempElement) != rsltsArray[i]){ free(rsltsArray); spBPQueueDestroy(workingQueue); return false; } spListElementDestroy(tempElement); msg = spBPQueueDequeue(workingQueue); if (msg != SP_BPQUEUE_SUCCESS){ free(rsltsArray); spBPQueueDestroy(workingQueue); return false; } } emptyFlag = spBPQueueIsEmpty(workingQueue); spBPQueueDestroy(workingQueue); free(rsltsArray); return emptyFlag; }