add deleteModel unit test

This commit is contained in:
ZappoMan 2014-06-25 15:08:08 -07:00
parent 34fad16dcf
commit 154f203541

View file

@ -240,7 +240,6 @@ void ModelTests::modelTreeTests(bool verbose) {
{
// seed the random number generator so that our tests are reproducible
srand(0xFEEDBEEF);
ModelTree tree;
testsTaken++;
const int TEST_ITERATIONS = 10000;
@ -343,6 +342,80 @@ void ModelTests::modelTreeTests(bool verbose) {
<< "elapsed Find=" << elapsedInMSecsFind << "msecs";
}
{
testsTaken++;
const int TEST_ITERATIONS = 10000;
QString testName = "Performance - delete model from tree " + QString::number(TEST_ITERATIONS) + " times";
if (verbose) {
qDebug() << "Test" << testsTaken <<":" << qPrintable(testName);
}
int iterationsPassed = 0;
quint64 totalElapsedDelete = 0;
quint64 totalElapsedFind = 0;
for (int i = 0; i < TEST_ITERATIONS; i++) {
uint32_t id = i + 2; // These are the models we added above
ModelItemID modelID(id);
modelID.isKnownID = true; // this is a temporary workaround to allow local tree models to be added with known IDs
if (extraVerbose) {
qDebug() << "before:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount();
}
quint64 startDelete = usecTimestampNow();
tree.deleteModel(modelID);
quint64 endDelete = usecTimestampNow();
totalElapsedDelete += (endDelete - startDelete);
if (extraVerbose) {
qDebug() << "after:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount();
}
quint64 startFind = usecTimestampNow();
const ModelItem* foundModelByID = tree.findModelByID(id);
quint64 endFind = usecTimestampNow();
totalElapsedFind += (endFind - startFind);
ModelTreeElement* containingElement = tree.getContainingElement(modelID);
if (extraVerbose) {
qDebug() << "foundModelByID=" << foundModelByID;
qDebug() << "containingElement=" << containingElement;
}
// Every 1000th test, show the size of the tree...
if (verbose && (i % 1000 == 0)) {
qDebug() << "after test:" << i << "getOctreeElementsCount()=" << tree.getOctreeElementsCount();
}
bool passed = foundModelByID == NULL && containingElement == NULL;
if (passed) {
iterationsPassed++;
} else {
qDebug() << "FAILED - Test" << testsTaken <<":" << qPrintable(testName) << "iteration:" << i
<< "foundModelByID=" << foundModelByID
<< "containingElement=" << containingElement;
}
}
if (extraVerbose) {
qDebug() << "getOctreeElementsCount()=" << tree.getOctreeElementsCount();
}
bool passed = iterationsPassed == TEST_ITERATIONS;
if (passed) {
testsPassed++;
} else {
testsFailed++;
qDebug() << "FAILED - Test" << testsTaken <<":" << qPrintable(testName);
}
float USECS_PER_MSECS = 1000.0f;
float elapsedInMSecsDelete = (float)(totalElapsedDelete) / USECS_PER_MSECS;
float elapsedInMSecsFind = (float)(totalElapsedFind) / USECS_PER_MSECS;
qDebug() << "TIME - Test" << testsTaken <<":" << qPrintable(testName)
<< "elapsed Delete=" << elapsedInMSecsDelete << "msecs"
<< "elapsed Find=" << elapsedInMSecsFind << "msecs";
}
qDebug() << " tests passed:" << testsPassed << "out of" << testsTaken;
if (verbose) {
qDebug() << "******************************************************************************************";