1.1 --- a/src/test/graph_test.cc Wed Aug 25 18:55:57 2004 +0000
1.2 +++ b/src/test/graph_test.cc Mon Aug 30 12:01:47 2004 +0000
1.3 @@ -6,12 +6,15 @@
1.4
1.5 #include"test_tools.h"
1.6
1.7 -/*
1.8 +/**
1.9 +\file
1.10 This test makes consistency checks of list graph structures.
1.11
1.12 -G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
1.13 +G.addNode(), G.addEdge(), G.tail(), G.head()
1.14
1.15 \todo Checks for empty graphs and isolated points.
1.16 +\todo Checks for Node->NodeIt, Edge->{EdgeIt,InEdgeIt,OutEdgeIt}
1.17 +conversion.
1.18 */
1.19
1.20 using namespace hugo;
1.21 @@ -29,82 +32,100 @@
1.22 {
1.23 Node i; Node j(i); Node k(INVALID);
1.24 i=j;
1.25 - bool b=G.valid(i); b=b;
1.26 + // bool b=G.valid(i); b=b;
1.27 + bool b; b=b;
1.28 + b=(i==INVALID); b=(i!=INVALID);
1.29 b=(i==j); b=(i!=j); b=(i<j);
1.30 }
1.31 {
1.32 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
1.33 i=j;
1.34 j=G.first(i);
1.35 - j=G.next(i);
1.36 - bool b=G.valid(i); b=b;
1.37 + j=++i;
1.38 + // bool b=G.valid(i); b=b;
1.39 + bool b; b=b;
1.40 + b=(i==INVALID); b=(i!=INVALID);
1.41 Node n(i);
1.42 n=i;
1.43 b=(i==j); b=(i!=j); b=(i<j);
1.44 + //Node ->NodeIt conversion
1.45 + NodeIt ni(G,n);
1.46 }
1.47 {
1.48 Edge i; Edge j(i); Edge k(INVALID);
1.49 i=j;
1.50 - bool b=G.valid(i); b=b;
1.51 + // bool b=G.valid(i); b=b;
1.52 + bool b; b=b;
1.53 + b=(i==INVALID); b=(i!=INVALID);
1.54 b=(i==j); b=(i!=j); b=(i<j);
1.55 }
1.56 {
1.57 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
1.58 i=j;
1.59 j=G.first(i);
1.60 - j=G.next(i);
1.61 - bool b=G.valid(i); b=b;
1.62 + j=++i;
1.63 + // bool b=G.valid(i); b=b;
1.64 + bool b; b=b;
1.65 + b=(i==INVALID); b=(i!=INVALID);
1.66 Edge e(i);
1.67 e=i;
1.68 b=(i==j); b=(i!=j); b=(i<j);
1.69 + //Edge ->EdgeIt conversion
1.70 + EdgeIt ei(G,e);
1.71 }
1.72 {
1.73 Node n;
1.74 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
1.75 i=j;
1.76 j=G.first(i,n);
1.77 - j=G.next(i);
1.78 - bool b=G.valid(i); b=b;
1.79 + j=++i;
1.80 + // bool b=G.valid(i); b=b;
1.81 + bool b; b=b;
1.82 + b=(i==INVALID); b=(i!=INVALID);
1.83 Edge e(i);
1.84 e=i;
1.85 b=(i==j); b=(i!=j); b=(i<j);
1.86 + //Edge ->InEdgeIt conversion
1.87 + InEdgeIt ei(G,e);
1.88 }
1.89 {
1.90 Node n;
1.91 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
1.92 i=j;
1.93 j=G.first(i,n);
1.94 - j=G.next(i);
1.95 - bool b=G.valid(i); b=b;
1.96 + j=++i;
1.97 + // bool b=G.valid(i); b=b;
1.98 + bool b; b=b;
1.99 + b=(i==INVALID); b=(i!=INVALID);
1.100 Edge e(i);
1.101 e=i;
1.102 b=(i==j); b=(i!=j); b=(i<j);
1.103 + //Edge ->OutEdgeIt conversion
1.104 + OutEdgeIt ei(G,e);
1.105 }
1.106 -
1.107 - Node n,m;
1.108 - n=m=INVALID;
1.109 - Edge e;
1.110 - e=INVALID;
1.111 - n=G.tail(e);
1.112 - n=G.head(e);
1.113 -
1.114 - //aNode, bNode ?
1.115 -
1.116 + {
1.117 + Node n,m;
1.118 + n=m=INVALID;
1.119 + Edge e;
1.120 + e=INVALID;
1.121 + n=G.tail(e);
1.122 + n=G.head(e);
1.123 + }
1.124 // id tests
1.125 - { int i=G.id(n); i=i; }
1.126 - { int i=G.id(e); i=i; }
1.127 -
1.128 - // G.clear();
1.129 -
1.130 + { Node n; int i=G.id(n); i=i; }
1.131 + { Edge e; int i=G.id(e); i=i; }
1.132 //NodeMap tests
1.133 {
1.134 Node k;
1.135 typename Graph::template NodeMap<int> m(G);
1.136 - typename Graph::template NodeMap<int> const &cm = m; //Const map
1.137 + //Const map
1.138 + typename Graph::template NodeMap<int> const &cm = m;
1.139 //Inicialize with default value
1.140 typename Graph::template NodeMap<int> mdef(G,12);
1.141 - typename Graph::template NodeMap<int> mm(cm); //Copy
1.142 - typename Graph::template NodeMap<double> dm(cm); //Copy from another type
1.143 + //Copy
1.144 + typename Graph::template NodeMap<int> mm(cm);
1.145 + //Copy from another type
1.146 + typename Graph::template NodeMap<double> dm(cm);
1.147 int v;
1.148 v=m[k]; m[k]=v; m.set(k,v);
1.149 v=cm[k];
1.150 @@ -160,7 +181,6 @@
1.151 dm=cm; //Copy from another type
1.152 m=dm; //Copy to another type
1.153 }
1.154 -
1.155 }
1.156
1.157 template<class Graph> void checkCompile(Graph &G)
1.158 @@ -177,8 +197,36 @@
1.159 Node n,m;
1.160 n=G.addNode();
1.161 m=G.addNode();
1.162 + Edge e;
1.163 + e=G.addEdge(n,m);
1.164
1.165 - G.addEdge(n,m);
1.166 + // G.clear();
1.167 +}
1.168 +
1.169 +template<class Graph> void checkCompileErase(Graph &G)
1.170 +{
1.171 + typedef typename Graph::Node Node;
1.172 + typedef typename Graph::Edge Edge;
1.173 + Node n;
1.174 + Edge e;
1.175 + G.erase(n);
1.176 + G.erase(e);
1.177 +}
1.178 +
1.179 +template<class Graph> void checkCompileEraseEdge(Graph &G)
1.180 +{
1.181 + typedef typename Graph::Edge Edge;
1.182 + Edge e;
1.183 + G.erase(e);
1.184 +}
1.185 +
1.186 +template<class Graph> void checkCompileFindEdge(Graph &G)
1.187 +{
1.188 + typedef typename Graph::NodeIt Node;
1.189 + typedef typename Graph::NodeIt NodeIt;
1.190 +
1.191 + G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
1.192 + G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
1.193 }
1.194
1.195
1.196 @@ -186,10 +234,10 @@
1.197 {
1.198 typename Graph::NodeIt n(G);
1.199 for(int i=0;i<nn;i++) {
1.200 - check(G.valid(n),"Wrong Node list linking.");
1.201 - G.next(n);
1.202 + check(n!=INVALID,"Wrong Node list linking.");
1.203 + ++n;
1.204 }
1.205 - check(!G.valid(n),"Wrong Node list linking.");
1.206 + check(n==INVALID,"Wrong Node list linking.");
1.207 }
1.208
1.209 template<class Graph> void checkEdgeList(Graph &G, int nn)
1.210 @@ -198,10 +246,10 @@
1.211
1.212 EdgeIt e(G);
1.213 for(int i=0;i<nn;i++) {
1.214 - check(G.valid(e),"Wrong Edge list linking.");
1.215 - G.next(e);
1.216 + check(e!=INVALID,"Wrong Edge list linking.");
1.217 + ++e;
1.218 }
1.219 - check(!G.valid(e),"Wrong Edge list linking.");
1.220 + check(e==INVALID,"Wrong Edge list linking.");
1.221 }
1.222
1.223 template<class Graph> void checkOutEdgeList(Graph &G,
1.224 @@ -210,25 +258,27 @@
1.225 {
1.226 typename Graph::OutEdgeIt e(G,n);
1.227 for(int i=0;i<nn;i++) {
1.228 - check(G.valid(e),"Wrong OutEdge list linking.");
1.229 - G.next(e);
1.230 + check(e!=INVALID,"Wrong OutEdge list linking.");
1.231 + ++e;
1.232 }
1.233 - check(!G.valid(e),"Wrong OutEdge list linking.");
1.234 + check(e==INVALID,"Wrong OutEdge list linking.");
1.235 }
1.236
1.237 template<class Graph> void checkInEdgeList(Graph &G,
1.238 - typename Graph::Node n,
1.239 - int nn)
1.240 + typename Graph::Node n,
1.241 + int nn)
1.242 {
1.243 typename Graph::InEdgeIt e(G,n);
1.244 for(int i=0;i<nn;i++) {
1.245 - check(G.valid(e),"Wrong InEdge list linking.");
1.246 - G.next(e);
1.247 + check(e!=INVALID,"Wrong InEdge list linking.");
1.248 + ++e;
1.249 }
1.250 - check(!G.valid(e),"Wrong InEdge list linking.");
1.251 + check(e==INVALID,"Wrong InEdge list linking.");
1.252 }
1.253
1.254 -//Checks head(), tail() as well;
1.255 +///\file
1.256 +///\todo Checks head(), tail() as well;
1.257 +
1.258 template<class Graph> void bidirPetersen(Graph &G)
1.259 {
1.260 typedef typename Graph::Edge Edge;
1.261 @@ -238,7 +288,7 @@
1.262
1.263 std::vector<Edge> ee;
1.264
1.265 - for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
1.266 + for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
1.267
1.268 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
1.269 G.addEdge(G.head(*p),G.tail(*p));
1.270 @@ -254,25 +304,52 @@
1.271 checkNodeList(G,10);
1.272 checkEdgeList(G,30);
1.273
1.274 - for(NodeIt n(G);G.valid(n);G.next(n)) {
1.275 + for(NodeIt n(G);n!=INVALID;++n) {
1.276 checkInEdgeList(G,n,3);
1.277 checkOutEdgeList(G,n,3);
1.278 - G.next(n);
1.279 + ++n;
1.280 }
1.281 }
1.282
1.283 -template
1.284 +//Compile GraphSkeleton
1.285 +template
1.286 void checkCompileStaticGraph<StaticGraphSkeleton>(StaticGraphSkeleton &);
1.287 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
1.288 +template
1.289 +void checkCompileErase<EraseableGraphSkeleton>(EraseableGraphSkeleton &);
1.290
1.291 +//Compile SmartGraph
1.292 template void checkCompile<SmartGraph>(SmartGraph &);
1.293 +//Compile SymSmartGraph
1.294 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
1.295 +
1.296 +//Compile ListGraph
1.297 template void checkCompile<ListGraph>(ListGraph &);
1.298 +template void checkCompileErase<ListGraph>(ListGraph &);
1.299 +template void checkCompileFindEdge<ListGraph>(ListGraph &);
1.300 +
1.301 +//Compile SymListGraph
1.302 template void checkCompile<SymListGraph>(SymListGraph &);
1.303 +template void checkCompileErase<SymListGraph>(SymListGraph &);
1.304 +template void checkCompileFindEdge<SymListGraph>(SymListGraph &);
1.305 +
1.306 +//Compile FullGraph
1.307 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
1.308 +template void checkCompileFindEdge<FullGraph>(FullGraph &);
1.309
1.310 +//Compile EdgeSet <ListGraph>
1.311 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.312 +template
1.313 +void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.314 +template
1.315 +void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.316 +
1.317 +//Compile EdgeSet <NodeSet>
1.318 template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.319 +template
1.320 +void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.321 +template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.322 +
1.323
1.324 int main()
1.325 {
1.326 @@ -299,8 +376,9 @@
1.327 checkPetersen(G);
1.328 }
1.329
1.330 - //\todo map tests.
1.331 - //\todo copy constr tests.
1.332 + ///\file
1.333 + ///\todo map tests.
1.334 + ///\todo copy constr tests.
1.335
1.336 std::cout << __FILE__ ": All tests passed.\n";
1.337