#include "AstTestTools.h" #include "AstSortableAssoc.h" #include "AstSorted2Vector.h" #include #include #include #include using std::endl; using std::cout; bool compare (const AstSortableAssoc* lhs, const AstSortableAssoc* rhs) { return (*lhs) < (*rhs); } void AstSortablesTest(){ AstTestBanner("AstSortableAssoc"); SimpleClass *mySP1 = new SimpleClass(4); SimpleClass *mySP2 = new SimpleClass(6); SimpleClass *mySP3 = new SimpleClass(2); std::string *testASA1 = new std::string("Four"); std::string *testASA2 = new std::string("Six"); std::string *testASA3 = new std::string("Two"); std::vector* > *mySortedVector= new std::vector* >(); mySortedVector-> push_back(new AstSortableAssoc(testASA1, mySP1, simpleClassLessThan)); mySortedVector-> push_back(new AstSortableAssoc(testASA2, mySP2, simpleClassLessThan)); mySortedVector-> push_back(new AstSortableAssoc(testASA3, mySP3, simpleClassLessThan)); std::sort(mySortedVector->begin(), mySortedVector->end(), compare); std::vector* >::const_iterator iter; int i = 0; for (iter = mySortedVector->begin(); iter != mySortedVector->end(); iter++) { cout << "Vector entry " << i << ". " << (*iter)->key() << ", " << (*iter)->quality().getInt() << endl; i++; } AstTestBanner("AstSorted2Vector"); AstSorted2Vector myVector(simpleClassLessThan); myVector.insert(testASA1, mySP1); myVector.insert(testASA2, mySP2); myVector.insert(testASA3, mySP3); for (i=0;igetInt() << endl; } if (!myVector.contains(testASA1, mySP2)){ cout << "Correctly did not find combination " << *testASA1 << ", " << mySP2->getInt() << endl; } const std::string* haveFound = myVector.find( *mySP2 ); if ( haveFound != 0 ) { cout << "Correctly found " << *haveFound << endl; } const std::string* haveFound2 = myVector.find( SimpleClass( 1000 ) ); if ( haveFound2 == 0 ) { cout << "Correctly didn't find nonexistant class." << endl; } myVector.clearAndDestroy(); exit(0); }