beckerjc@483: #include <iostream>
beckerjc@483: 
ladanyi@542: #include <hugo/maps.h>
ladanyi@542: #include <hugo/unionfind.h>
alpar@774: #include "test_tools.h"
beckerjc@483: 
beckerjc@483: using namespace hugo;
beckerjc@483: using namespace std;
beckerjc@483: 
beckerjc@483: template <typename T>
beckerjc@483: class BaseMap : public StdMap<int,T> {};
beckerjc@483: 
beckerjc@483: typedef UnionFindEnum<int, BaseMap> UFE;
beckerjc@483: 
beckerjc@483: void print(UFE const &ufe) {
beckerjc@483:   UFE::ClassIt cit;
alpar@774:   cout << "Print 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: 
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Insert 1..." << endl;
beckerjc@483:   U.insert(1);
alpar@774: //   print(U);
beckerjc@483:   
alpar@774:   cout << "Insert 2..." << endl;
beckerjc@483:   U.insert(2);
alpar@774: //   print(U);
beckerjc@483:   
alpar@774:   cout << "Join 1 and 2..." << endl;
alpar@774:   check(U.join(1,2),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Insert 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);
alpar@774: //   print (U);
beckerjc@483: 
alpar@774:   cout << "Join 1 - 4, 2 - 4 and 3 - 5 ..." << endl;
alpar@774:   check(U.join(1,4),"Test failed.");
alpar@774:   check(!U.join(2,4),"Test failed.");
alpar@774:   check(U.join(3,5),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Insert 8 to the component of 5 ..." << endl;
beckerjc@483:   U.insert(8,5);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Size of the class of 4: " << U.size(4) << endl;
alpar@774:   check(U.size(4) == 3,"Test failed.");
alpar@774:   cout << "Size of the class of 5: " << U.size(5) << endl;
alpar@774:   check(U.size(5) == 3,"Test failed.");
alpar@774:   cout << "Size of the class of 6: " << U.size(6) << endl;
alpar@774:   check(U.size(6) == 1,"Test failed.");
alpar@774:   cout << "Size of the class of 2: " << U.size(2) << endl;
alpar@774:   check(U.size(2) == 3,"Test failed.");
beckerjc@483: 
alpar@774:   cout << "Insert 9 ..." << endl;
beckerjc@483:   U.insert(9);
alpar@774: //   print(U);
alpar@774:   cout << "Insert 10 to the component of 9 ..." << endl;
beckerjc@483:   U.insert(10,9);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Join 8 and 10..." << endl;
alpar@774:   check(U.join(8,10),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
beckerjc@483:   cout << "Move 9 to the class of 4 ..." << endl;
alpar@774:   check(U.move(9,4),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
beckerjc@483:   cout << "Move 9 to the class of 2 ..." << endl;
alpar@774:   check(!U.move(9,2),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Size of the class of 4: " << U.size(4) << endl;
alpar@774:   check(U.size(4) == 4,"Test failed.");
alpar@774:   cout << "Size of the class of 9: " << U.size(9) << endl;
alpar@774:   check(U.size(9) == 4,"Test failed.");
beckerjc@483:   
beckerjc@483:   cout << "Move 5 to the class of 6 ..." << endl;
alpar@774:   check(U.move(5,6),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Size of the class of 5: " << U.size(5) << endl;
alpar@774:   check(U.size(5) == 2,"Test failed.");
alpar@774:   cout << "Size of the class of 8: " << U.size(8) << endl;
alpar@774:   check(U.size(8) == 3,"Test failed.");
beckerjc@483: 
beckerjc@483:   cout << "Move 7 to the class of 10 ..." << endl;
alpar@774:   check(U.move(7,10),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Size of the class of 7: " << U.size(7) << endl;
alpar@774:   check(U.size(7) == 4,"Test failed.");
beckerjc@483: 
alpar@774:   cout <<"Erase 9... " << endl;
beckerjc@483:   U.erase(9);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout <<"Erase 1... " << endl;
beckerjc@483:   U.erase(1);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Size of the class of 4: " << U.size(4) << endl;
alpar@774:   check(U.size(4) == 2,"Test failed.");
alpar@774:   cout << "Size of the class of 2: " << U.size(2) << endl;
alpar@774:   check(U.size(2) == 2,"Test failed.");
beckerjc@483: 
beckerjc@483: 
alpar@774:   cout <<"Erase 1... " << endl;
beckerjc@483:   U.erase(1);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout <<"Erase 6... " << endl;
beckerjc@483:   U.erase(6);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Split the class of 8... " << endl;
beckerjc@483:   U.split(8);
alpar@774: //   print(U);
beckerjc@483: 
beckerjc@483: 
alpar@774:   cout << "Size of the class of 4: " << U.size(4) << endl;
alpar@774:   check(U.size(4) == 2,"Test failed.");
alpar@774:   cout << "Size of the class of 3: " << U.size(3) << endl;
alpar@774:   check(U.size(3) == 1,"Test failed.");
alpar@774:   cout << "Size of the class of 2: " << U.size(2) << endl;
alpar@774:   check(U.size(2) == 2,"Test failed.");
beckerjc@483: 
beckerjc@483: 
alpar@774:   cout << "Join 3 - 4 and 2 - 4 ..." << endl;
alpar@774:   check(U.join(3,4),"Test failed.");
alpar@774:   check(!U.join(2,4),"Test failed.");
alpar@774: //   print(U);
beckerjc@483: 
beckerjc@483: 
alpar@774:   cout << "Size of the class of 4: " << U.size(4) << endl;
alpar@774:   check(U.size(4) == 3,"Test failed.");
alpar@774:   cout << "Size of the class of 3: " << U.size(3) << endl;
alpar@774:   check(U.size(3) == 3,"Test failed.");
alpar@774:   cout << "Size of the class of 2: " << U.size(2) << endl;
alpar@774:   check(U.size(2) == 3,"Test failed.");
beckerjc@483: 
alpar@793:   cout << "Calling makeRep(4)..." << endl;
beckerjc@483:   U.makeRep(4);
alpar@774: //   print(U);
alpar@793:   cout << "Calling makeRep(3)..." << endl;
beckerjc@483:   U.makeRep(3);
alpar@774: //   print(U);
alpar@793:   cout << "Calling makeRep(2)..." << endl;
beckerjc@483:   U.makeRep(2);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "Size of the class of 4: " << U.size(4) << endl;
alpar@774:   check(U.size(4) == 3,"Test failed.");
alpar@774:   cout << "Size of the class of 3: " << U.size(3) << endl;
alpar@774:   check(U.size(3) == 3,"Test failed.");
alpar@774:   cout << "Size of the class of 2: " << U.size(2) << endl;
alpar@774:   check(U.size(2) == 3,"Test failed.");
beckerjc@483: 
beckerjc@483: 
beckerjc@483:   cout << "eraseClass 4 ..." << endl;
beckerjc@483:   U.eraseClass(4);
alpar@774: //   print(U);
beckerjc@483: 
beckerjc@483:   cout << "eraseClass 7 ..." << endl;
beckerjc@483:   U.eraseClass(7);
alpar@774: //   print(U);
beckerjc@483: 
alpar@774:   cout << "done." << endl;
beckerjc@483: }