test/unionfind_test.cc
changeset 2214 a886e48e0d91
parent 2005 84ec2948eb1f
child 2308 cddae1c4fee6
equal deleted inserted replaced
4:431657e4ed9a 5:491a4c08d88b
    23 #include "test_tools.h"
    23 #include "test_tools.h"
    24 
    24 
    25 using namespace lemon;
    25 using namespace lemon;
    26 using namespace std;
    26 using namespace std;
    27 
    27 
    28 template <typename T>
    28 typedef UnionFindEnum<int, StdMap<int, int> > UFE;
    29 class BaseMap : public StdMap<int,T> {};
       
    30 
       
    31 typedef UnionFindEnum<int, BaseMap> UFE;
       
    32 
    29 
    33 void print(UFE const &ufe) {
    30 void print(UFE const &ufe) {
    34   UFE::ClassIt cit;
       
    35   cout << "Print the classes of the structure:" << endl;
    31   cout << "Print the classes of the structure:" << endl;
    36   int i = 1;
    32   int i = 1;
    37   for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) {
    33   for (UFE::ClassIt cit(ufe); cit != INVALID; ++cit) {
    38     cout << "  " << i << " (" << cit << "):" << flush;
    34     cout << "  " << i << " (" << cit << "):" << flush;
    39     UFE::ItemIt iit;
    35     for (UFE::ItemIt iit(ufe, cit); iit != INVALID; ++iit) {
    40     for (ufe.first(iit, cit); ufe.valid(iit); ufe.next(iit)) {
       
    41       cout << " " << iit << flush;
    36       cout << " " << iit << flush;
    42     }
    37     }
    43     cout << endl;
    38     cout << endl;
    44     i++;
    39     i++;
    45   }
    40   }
    46   cout << "done" << endl;
    41   cout << "done" << endl;
    47 }
    42 }
    48 
    43 
    49 
    44 
    50 int main() {
    45 int main() {
    51   UFE::MapType base;
    46   StdMap<int, int> base;
    52   UFE U(base);
    47   UFE U(base);
    53 
    48 
    54   U.insert(1);
    49   U.insert(1);
    55   U.insert(2);
    50   U.insert(2);
    56 
    51 
    73   check(U.size(6) == 1,"Test failed.");
    68   check(U.size(6) == 1,"Test failed.");
    74   check(U.size(2) == 3,"Test failed.");
    69   check(U.size(2) == 3,"Test failed.");
    75 
    70 
    76   U.insert(9);
    71   U.insert(9);
    77   U.insert(10,9);
    72   U.insert(10,9);
       
    73 
    78   check(U.join(8,10),"Test failed.");
    74   check(U.join(8,10),"Test failed.");
    79 
    75 
    80   check(U.move(9,4),"Test failed.");
    76   check(U.move(9,4),"Test failed.");
    81   check(!U.move(9,2),"Test failed.");
    77   check(!U.move(9,2),"Test failed.");
    82 
    78