1.1 --- a/test/unionfind_test.cc Fri Feb 29 11:01:39 2008 +0000
1.2 +++ b/test/unionfind_test.cc Thu Mar 20 22:59:58 2008 +0000
1.3 @@ -18,6 +18,7 @@
1.4
1.5 #include <iostream>
1.6
1.7 +#include <lemon/list_graph.h>
1.8 #include <lemon/maps.h>
1.9 #include <lemon/unionfind.h>
1.10 #include "test_tools.h"
1.11 @@ -25,90 +26,79 @@
1.12 using namespace lemon;
1.13 using namespace std;
1.14
1.15 -typedef UnionFindEnum<StdMap<int, int> > UFE;
1.16 -
1.17 -void print(UFE const &ufe) {
1.18 - cout << "Print the classes of the structure:" << endl;
1.19 - int i = 1;
1.20 - for (UFE::ClassIt cit(ufe); cit != INVALID; ++cit) {
1.21 - cout << " " << i << " (" << cit << "):" << flush;
1.22 - for (UFE::ItemIt iit(ufe, cit); iit != INVALID; ++iit) {
1.23 - cout << " " << iit << flush;
1.24 - }
1.25 - cout << endl;
1.26 - i++;
1.27 - }
1.28 - cout << "done" << endl;
1.29 -}
1.30 -
1.31 +typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE;
1.32
1.33 int main() {
1.34 - StdMap<int, int> base;
1.35 + ListGraph g;
1.36 + ListGraph::NodeMap<int> base(g);
1.37 UFE U(base);
1.38 + vector<ListGraph::Node> n;
1.39 +
1.40 + for(int i=0;i<20;i++) n.push_back(g.addNode());
1.41
1.42 - U.insert(1);
1.43 - U.insert(2);
1.44 + U.insert(n[1]);
1.45 + U.insert(n[2]);
1.46
1.47 - check(U.join(1,2) != -1,"Test failed.");
1.48 + check(U.join(n[1],n[2]) != -1,"Test failed.");
1.49
1.50 - U.insert(3);
1.51 - U.insert(4);
1.52 - U.insert(5);
1.53 - U.insert(6);
1.54 - U.insert(7);
1.55 + U.insert(n[3]);
1.56 + U.insert(n[4]);
1.57 + U.insert(n[5]);
1.58 + U.insert(n[6]);
1.59 + U.insert(n[7]);
1.60
1.61
1.62 - check(U.join(1,4) != -1,"Test failed.");
1.63 - check(U.join(2,4) == -1,"Test failed.");
1.64 - check(U.join(3,5) != -1,"Test failed.");
1.65 + check(U.join(n[1],n[4]) != -1,"Test failed.");
1.66 + check(U.join(n[2],n[4]) == -1,"Test failed.");
1.67 + check(U.join(n[3],n[5]) != -1,"Test failed.");
1.68
1.69
1.70 - U.insert(8,U.find(5));
1.71 + U.insert(n[8],U.find(n[5]));
1.72
1.73
1.74 - check(U.size(U.find(4)) == 3,"Test failed.");
1.75 - check(U.size(U.find(5)) == 3,"Test failed.");
1.76 - check(U.size(U.find(6)) == 1,"Test failed.");
1.77 - check(U.size(U.find(2)) == 3,"Test failed.");
1.78 + check(U.size(U.find(n[4])) == 3,"Test failed.");
1.79 + check(U.size(U.find(n[5])) == 3,"Test failed.");
1.80 + check(U.size(U.find(n[6])) == 1,"Test failed.");
1.81 + check(U.size(U.find(n[2])) == 3,"Test failed.");
1.82
1.83
1.84 - U.insert(9);
1.85 - U.insert(10,U.find(9));
1.86 + U.insert(n[9]);
1.87 + U.insert(n[10],U.find(n[9]));
1.88
1.89
1.90 - check(U.join(8,10) != -1,"Test failed.");
1.91 + check(U.join(n[8],n[10]) != -1,"Test failed.");
1.92
1.93
1.94 - check(U.size(U.find(4)) == 3,"Test failed.");
1.95 - check(U.size(U.find(9)) == 5,"Test failed.");
1.96 + check(U.size(U.find(n[4])) == 3,"Test failed.");
1.97 + check(U.size(U.find(n[9])) == 5,"Test failed.");
1.98
1.99 - check(U.size(U.find(8)) == 5,"Test failed.");
1.100 + check(U.size(U.find(n[8])) == 5,"Test failed.");
1.101
1.102 - U.erase(9);
1.103 - U.erase(1);
1.104 + U.erase(n[9]);
1.105 + U.erase(n[1]);
1.106
1.107 - check(U.size(U.find(10)) == 4,"Test failed.");
1.108 - check(U.size(U.find(2)) == 2,"Test failed.");
1.109 + check(U.size(U.find(n[10])) == 4,"Test failed.");
1.110 + check(U.size(U.find(n[2])) == 2,"Test failed.");
1.111
1.112 - U.erase(6);
1.113 - U.split(U.find(8));
1.114 + U.erase(n[6]);
1.115 + U.split(U.find(n[8]));
1.116
1.117
1.118 - check(U.size(U.find(4)) == 2,"Test failed.");
1.119 - check(U.size(U.find(3)) == 1,"Test failed.");
1.120 - check(U.size(U.find(2)) == 2,"Test failed.");
1.121 + check(U.size(U.find(n[4])) == 2,"Test failed.");
1.122 + check(U.size(U.find(n[3])) == 1,"Test failed.");
1.123 + check(U.size(U.find(n[2])) == 2,"Test failed.");
1.124
1.125
1.126 - check(U.join(3,4) != -1,"Test failed.");
1.127 - check(U.join(2,4) == -1,"Test failed.");
1.128 + check(U.join(n[3],n[4]) != -1,"Test failed.");
1.129 + check(U.join(n[2],n[4]) == -1,"Test failed.");
1.130
1.131
1.132 - check(U.size(U.find(4)) == 3,"Test failed.");
1.133 - check(U.size(U.find(3)) == 3,"Test failed.");
1.134 - check(U.size(U.find(2)) == 3,"Test failed.");
1.135 + check(U.size(U.find(n[4])) == 3,"Test failed.");
1.136 + check(U.size(U.find(n[3])) == 3,"Test failed.");
1.137 + check(U.size(U.find(n[2])) == 3,"Test failed.");
1.138
1.139 - U.eraseClass(U.find(4));
1.140 - U.eraseClass(U.find(7));
1.141 + U.eraseClass(U.find(n[4]));
1.142 + U.eraseClass(U.find(n[7]));
1.143
1.144 return 0;
1.145 }