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