beckerjc@394: #include beckerjc@394: beckerjc@394: #include beckerjc@394: #include beckerjc@394: beckerjc@394: using namespace hugo; beckerjc@394: using namespace std; beckerjc@394: beckerjc@394: bool passed = true; beckerjc@394: beckerjc@394: void check(bool rc) { beckerjc@394: passed = passed && rc; beckerjc@394: if(!rc) { beckerjc@394: cout << "Test failed!" << endl; beckerjc@394: } beckerjc@394: } beckerjc@394: beckerjc@394: template beckerjc@394: class BaseMap : public StdMap {}; beckerjc@394: beckerjc@394: typedef UnionFindEnum UFE; beckerjc@394: beckerjc@394: void print(UFE const &ufe) { beckerjc@394: UFE::ClassIt cit; beckerjc@394: cout << "printing the classes of the structure:" << endl; beckerjc@394: int i = 1; beckerjc@394: for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) { beckerjc@394: cout << " " << i << " (" << cit << "):" << flush; beckerjc@394: UFE::ItemIt iit; beckerjc@394: for (ufe.first(iit, cit); ufe.valid(iit); ufe.next(iit)) { beckerjc@394: cout << " " << iit << flush; beckerjc@394: } beckerjc@394: cout << endl; beckerjc@394: i++; beckerjc@394: } beckerjc@394: cout << "done" << endl; beckerjc@394: } beckerjc@394: beckerjc@394: beckerjc@394: int main() { beckerjc@394: UFE::MapType base; beckerjc@394: UFE U(base); beckerjc@394: beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "Inserting 1..." << endl; beckerjc@394: U.insert(1); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "Inserting 2..." << endl; beckerjc@394: U.insert(2); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "Joining 1 and 2..." << endl; beckerjc@394: check(U.join(1,2)); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "Inserting 3, 4, 5, 6, 7..." << endl; beckerjc@394: U.insert(3); beckerjc@394: U.insert(4); beckerjc@394: U.insert(5); beckerjc@394: U.insert(6); beckerjc@394: U.insert(7); beckerjc@394: print (U); beckerjc@394: beckerjc@394: cout << "Joining 1 - 4, 2 - 4 and 3 - 5 ..." << endl; beckerjc@394: check(U.join(1,4)); beckerjc@394: check(!U.join(2,4)); beckerjc@394: check(U.join(3,5)); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "size of the class of 4: " << U.size(4) << endl; beckerjc@394: check(U.size(4) == 3); beckerjc@394: cout << "size of the class of 5: " << U.size(5) << endl; beckerjc@394: check(U.size(5) == 2); beckerjc@394: cout << "size of the class of 6: " << U.size(6) << endl; beckerjc@394: check(U.size(6) == 1); beckerjc@462: cout << "size of the class of 2: " << U.size(2) << endl; beckerjc@462: check(U.size(2) == 3); beckerjc@394: beckerjc@394: cout <<"erase 1: " << endl; beckerjc@394: U.erase(1); beckerjc@394: print(U); beckerjc@394: beckerjc@462: cout << "size of the class of 4: " << U.size(4) << endl; beckerjc@462: check(U.size(4) == 2); beckerjc@462: cout << "size of the class of 2: " << U.size(2) << endl; beckerjc@462: check(U.size(2) == 2); beckerjc@462: beckerjc@462: beckerjc@394: cout <<"erase 1: " << endl; beckerjc@394: U.erase(1); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout <<"erase 6: " << endl; beckerjc@394: U.erase(6); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "split the class of 5: " << endl; beckerjc@394: U.split(5); beckerjc@394: print(U); beckerjc@394: beckerjc@462: beckerjc@462: cout << "size of the class of 4: " << U.size(4) << endl; beckerjc@462: check(U.size(4) == 2); beckerjc@462: cout << "size of the class of 3: " << U.size(3) << endl; beckerjc@462: check(U.size(3) == 1); beckerjc@462: cout << "size of the class of 2: " << U.size(2) << endl; beckerjc@462: check(U.size(2) == 2); beckerjc@462: beckerjc@462: beckerjc@394: cout << "Joining 3 - 4 and 2 - 4 ..." << endl; beckerjc@394: check(U.join(3,4)); beckerjc@394: check(!U.join(2,4)); beckerjc@394: print(U); beckerjc@394: beckerjc@462: beckerjc@462: cout << "size of the class of 4: " << U.size(4) << endl; beckerjc@462: check(U.size(4) == 3); beckerjc@462: cout << "size of the class of 3: " << U.size(3) << endl; beckerjc@462: check(U.size(3) == 3); beckerjc@462: cout << "size of the class of 2: " << U.size(2) << endl; beckerjc@462: check(U.size(2) == 3); beckerjc@462: beckerjc@462: cout << "makeRep(4)" << endl; beckerjc@462: U.makeRep(4); beckerjc@462: print(U); beckerjc@462: cout << "makeRep(3)" << endl; beckerjc@462: U.makeRep(3); beckerjc@462: print(U); beckerjc@462: cout << "makeRep(2)" << endl; beckerjc@462: U.makeRep(2); beckerjc@462: print(U); beckerjc@462: beckerjc@462: cout << "size of the class of 4: " << U.size(4) << endl; beckerjc@462: check(U.size(4) == 3); beckerjc@462: cout << "size of the class of 3: " << U.size(3) << endl; beckerjc@462: check(U.size(3) == 3); beckerjc@462: cout << "size of the class of 2: " << U.size(2) << endl; beckerjc@462: check(U.size(2) == 3); beckerjc@462: beckerjc@462: beckerjc@394: cout << "eraseClass 4 ..." << endl; beckerjc@394: U.eraseClass(4); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "eraseClass 7 ..." << endl; beckerjc@394: U.eraseClass(7); beckerjc@394: print(U); beckerjc@394: beckerjc@394: cout << "done" << endl; beckerjc@394: beckerjc@394: cout << (passed ? "All tests passed." : "Some of the tests failed!!!") beckerjc@394: << endl; beckerjc@394: beckerjc@394: return passed ? 0 : 1; beckerjc@394: }