1.1 --- a/src/test/graph_test.h Mon Sep 20 17:53:33 2004 +0000
1.2 +++ b/src/test/graph_test.h Mon Sep 20 22:57:48 2004 +0000
1.3 @@ -1,3 +1,4 @@
1.4 +// -*- c++ -*-
1.5 #ifndef HUGO_TEST_GRAPH_TEST_H
1.6 #define HUGO_TEST_GRAPH_TEST_H
1.7
1.8 @@ -9,289 +10,299 @@
1.9 //! \brief Some utility to test graph classes.
1.10 namespace hugo {
1.11
1.12 + struct DummyType {
1.13 + int value;
1.14 + DummyType() {}
1.15 + DummyType(int p) : value(p) {}
1.16 + DummyType& operator=(int p) { value = p; return *this;}
1.17 + };
1.18
1.19 -template<class Graph> void checkCompileStaticGraph(Graph &G)
1.20 -{
1.21 - typedef typename Graph::Node Node;
1.22 - typedef typename Graph::NodeIt NodeIt;
1.23 - typedef typename Graph::Edge Edge;
1.24 - typedef typename Graph::EdgeIt EdgeIt;
1.25 - typedef typename Graph::InEdgeIt InEdgeIt;
1.26 - typedef typename Graph::OutEdgeIt OutEdgeIt;
1.27 +
1.28 + template<class Graph> void checkCompileStaticGraph(Graph &G)
1.29 + {
1.30 + typedef typename Graph::Node Node;
1.31 + typedef typename Graph::NodeIt NodeIt;
1.32 + typedef typename Graph::Edge Edge;
1.33 + typedef typename Graph::EdgeIt EdgeIt;
1.34 + typedef typename Graph::InEdgeIt InEdgeIt;
1.35 + typedef typename Graph::OutEdgeIt OutEdgeIt;
1.36
1.37 - {
1.38 - Node i; Node j(i); Node k(INVALID);
1.39 - i=j;
1.40 - bool b; b=true;
1.41 - b=(i==INVALID); b=(i!=INVALID);
1.42 - b=(i==j); b=(i!=j); b=(i<j);
1.43 - }
1.44 - {
1.45 - NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
1.46 - i=j;
1.47 - j=G.first(i);
1.48 - j=++i;
1.49 - bool b; b=true;
1.50 - b=(i==INVALID); b=(i!=INVALID);
1.51 - Node n(i);
1.52 - n=i;
1.53 - b=(i==j); b=(i!=j); b=(i<j);
1.54 - //Node ->NodeIt conversion
1.55 - NodeIt ni(G,n);
1.56 - }
1.57 - {
1.58 - Edge i; Edge j(i); Edge k(INVALID);
1.59 - i=j;
1.60 - bool b; b=true;
1.61 - b=(i==INVALID); b=(i!=INVALID);
1.62 - b=(i==j); b=(i!=j); b=(i<j);
1.63 - }
1.64 - {
1.65 - EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
1.66 - i=j;
1.67 - j=G.first(i);
1.68 - j=++i;
1.69 - bool b; b=true;
1.70 - b=(i==INVALID); b=(i!=INVALID);
1.71 - Edge e(i);
1.72 - e=i;
1.73 - b=(i==j); b=(i!=j); b=(i<j);
1.74 - //Edge ->EdgeIt conversion
1.75 - EdgeIt ei(G,e);
1.76 - }
1.77 - {
1.78 - Node n;
1.79 - InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
1.80 - i=j;
1.81 - j=G.first(i,n);
1.82 - j=++i;
1.83 - bool b; b=true;
1.84 - b=(i==INVALID); b=(i!=INVALID);
1.85 - Edge e(i);
1.86 - e=i;
1.87 - b=(i==j); b=(i!=j); b=(i<j);
1.88 - //Edge ->InEdgeIt conversion
1.89 - InEdgeIt ei(G,e);
1.90 - }
1.91 - {
1.92 - Node n;
1.93 - OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
1.94 - i=j;
1.95 - j=G.first(i,n);
1.96 - j=++i;
1.97 - bool b; b=true;
1.98 - b=(i==INVALID); b=(i!=INVALID);
1.99 - Edge e(i);
1.100 - e=i;
1.101 - b=(i==j); b=(i!=j); b=(i<j);
1.102 - //Edge ->OutEdgeIt conversion
1.103 - OutEdgeIt ei(G,e);
1.104 - }
1.105 - {
1.106 - Node n,m;
1.107 - n=m=INVALID;
1.108 - Edge e;
1.109 - e=INVALID;
1.110 - n=G.tail(e);
1.111 - n=G.head(e);
1.112 - }
1.113 - // id tests
1.114 - { Node n; int i=G.id(n); i=i; }
1.115 - { Edge e; int i=G.id(e); i=i; }
1.116 - //NodeMap tests
1.117 - {
1.118 - Node k;
1.119 - typename Graph::template NodeMap<int> m(G);
1.120 - //Const map
1.121 - typename Graph::template NodeMap<int> const &cm = m;
1.122 - //Inicialize with default value
1.123 - typename Graph::template NodeMap<int> mdef(G,12);
1.124 - //Copy
1.125 - typename Graph::template NodeMap<int> mm(cm);
1.126 - //Copy from another type
1.127 - typename Graph::template NodeMap<double> dm(cm);
1.128 - int v;
1.129 - v=m[k]; m[k]=v; m.set(k,v);
1.130 - v=cm[k];
1.131 + {
1.132 + Node i; Node j(i); Node k(INVALID);
1.133 + i=j;
1.134 + bool b; b=true;
1.135 + b=(i==INVALID); b=(i!=INVALID);
1.136 + b=(i==j); b=(i!=j); b=(i<j);
1.137 + }
1.138 + {
1.139 + NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
1.140 + i=j;
1.141 + j=G.first(i);
1.142 + j=++i;
1.143 + bool b; b=true;
1.144 + b=(i==INVALID); b=(i!=INVALID);
1.145 + Node n(i);
1.146 + n=i;
1.147 + b=(i==j); b=(i!=j); b=(i<j);
1.148 + //Node ->NodeIt conversion
1.149 + NodeIt ni(G,n);
1.150 + }
1.151 + {
1.152 + Edge i; Edge j(i); Edge k(INVALID);
1.153 + i=j;
1.154 + bool b; b=true;
1.155 + b=(i==INVALID); b=(i!=INVALID);
1.156 + b=(i==j); b=(i!=j); b=(i<j);
1.157 + }
1.158 + {
1.159 + EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
1.160 + i=j;
1.161 + j=G.first(i);
1.162 + j=++i;
1.163 + bool b; b=true;
1.164 + b=(i==INVALID); b=(i!=INVALID);
1.165 + Edge e(i);
1.166 + e=i;
1.167 + b=(i==j); b=(i!=j); b=(i<j);
1.168 + //Edge ->EdgeIt conversion
1.169 + EdgeIt ei(G,e);
1.170 + }
1.171 + {
1.172 + Node n;
1.173 + InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
1.174 + i=j;
1.175 + j=G.first(i,n);
1.176 + j=++i;
1.177 + bool b; b=true;
1.178 + b=(i==INVALID); b=(i!=INVALID);
1.179 + Edge e(i);
1.180 + e=i;
1.181 + b=(i==j); b=(i!=j); b=(i<j);
1.182 + //Edge ->InEdgeIt conversion
1.183 + InEdgeIt ei(G,e);
1.184 + }
1.185 + {
1.186 + Node n;
1.187 + OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
1.188 + i=j;
1.189 + j=G.first(i,n);
1.190 + j=++i;
1.191 + bool b; b=true;
1.192 + b=(i==INVALID); b=(i!=INVALID);
1.193 + Edge e(i);
1.194 + e=i;
1.195 + b=(i==j); b=(i!=j); b=(i<j);
1.196 + //Edge ->OutEdgeIt conversion
1.197 + OutEdgeIt ei(G,e);
1.198 + }
1.199 + {
1.200 + Node n,m;
1.201 + n=m=INVALID;
1.202 + Edge e;
1.203 + e=INVALID;
1.204 + n=G.tail(e);
1.205 + n=G.head(e);
1.206 + }
1.207 + // id tests
1.208 + { Node n; int i=G.id(n); i=i; }
1.209 + { Edge e; int i=G.id(e); i=i; }
1.210 + //NodeMap tests
1.211 + {
1.212 + Node k;
1.213 + typename Graph::template NodeMap<int> m(G);
1.214 + //Const map
1.215 + typename Graph::template NodeMap<int> const &cm = m;
1.216 + //Inicialize with default value
1.217 + typename Graph::template NodeMap<int> mdef(G,12);
1.218 + //Copy
1.219 + typename Graph::template NodeMap<int> mm(cm);
1.220 + //Copy from another type
1.221 + typename Graph::template NodeMap<double> dm(cm);
1.222 + //Copy to more complex type
1.223 + typename Graph::template NodeMap<DummyType> em(cm);
1.224 + int v;
1.225 + v=m[k]; m[k]=v; m.set(k,v);
1.226 + v=cm[k];
1.227
1.228 - m=cm;
1.229 - dm=cm; //Copy from another type
1.230 + m=cm;
1.231 + dm=cm; //Copy from another type
1.232 + em=cm; //Copy to more complex type
1.233 + {
1.234 + //Check the typedef's
1.235 + typename Graph::template NodeMap<int>::ValueType val;
1.236 + val=1;
1.237 + typename Graph::template NodeMap<int>::KeyType key;
1.238 + key = typename Graph::NodeIt(G);
1.239 + }
1.240 + }
1.241 + { //bool NodeMap
1.242 + Node k;
1.243 + typename Graph::template NodeMap<bool> m(G);
1.244 + typename Graph::template NodeMap<bool> const &cm = m; //Const map
1.245 + //Inicialize with default value
1.246 + typename Graph::template NodeMap<bool> mdef(G,12);
1.247 + typename Graph::template NodeMap<bool> mm(cm); //Copy
1.248 + typename Graph::template NodeMap<int> dm(cm); //Copy from another type
1.249 + bool v;
1.250 + v=m[k]; m[k]=v; m.set(k,v);
1.251 + v=cm[k];
1.252 +
1.253 + m=cm;
1.254 + dm=cm; //Copy from another type
1.255 + m=dm; //Copy to another type
1.256 +
1.257 + {
1.258 + //Check the typedef's
1.259 + typename Graph::template NodeMap<bool>::ValueType val;
1.260 + val=true;
1.261 + typename Graph::template NodeMap<bool>::KeyType key;
1.262 + key= typename Graph::NodeIt(G);
1.263 + }
1.264 + }
1.265 + //EdgeMap tests
1.266 + {
1.267 + Edge k;
1.268 + typename Graph::template EdgeMap<int> m(G);
1.269 + typename Graph::template EdgeMap<int> const &cm = m; //Const map
1.270 + //Inicialize with default value
1.271 + typename Graph::template EdgeMap<int> mdef(G,12);
1.272 + typename Graph::template EdgeMap<int> mm(cm); //Copy
1.273 + typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
1.274 + int v;
1.275 + v=m[k]; m[k]=v; m.set(k,v);
1.276 + v=cm[k];
1.277 +
1.278 + m=cm;
1.279 + dm=cm; //Copy from another type
1.280 + {
1.281 + //Check the typedef's
1.282 + typename Graph::template EdgeMap<int>::ValueType val;
1.283 + val=1;
1.284 + typename Graph::template EdgeMap<int>::KeyType key;
1.285 + key= typename Graph::EdgeIt(G);
1.286 + }
1.287 + }
1.288 + { //bool EdgeMap
1.289 + Edge k;
1.290 + typename Graph::template EdgeMap<bool> m(G);
1.291 + typename Graph::template EdgeMap<bool> const &cm = m; //Const map
1.292 + //Inicialize with default value
1.293 + typename Graph::template EdgeMap<bool> mdef(G,12);
1.294 + typename Graph::template EdgeMap<bool> mm(cm); //Copy
1.295 + typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
1.296 + bool v;
1.297 + v=m[k]; m[k]=v; m.set(k,v);
1.298 + v=cm[k];
1.299 +
1.300 + m=cm;
1.301 + dm=cm; //Copy from another type
1.302 + m=dm; //Copy to another type
1.303 + {
1.304 + //Check the typedef's
1.305 + typename Graph::template EdgeMap<bool>::ValueType val;
1.306 + val=true;
1.307 + typename Graph::template EdgeMap<bool>::KeyType key;
1.308 + key= typename Graph::EdgeIt(G);
1.309 + }
1.310 + }
1.311 + }
1.312 +
1.313 + template<class Graph> void checkCompileGraph(Graph &G)
1.314 {
1.315 - //Check the typedef's
1.316 - typename Graph::template NodeMap<int>::ValueType val;
1.317 - val=1;
1.318 - typename Graph::template NodeMap<int>::KeyType key;
1.319 - key = typename Graph::NodeIt(G);
1.320 + checkCompileStaticGraph(G);
1.321 +
1.322 + typedef typename Graph::Node Node;
1.323 + typedef typename Graph::NodeIt NodeIt;
1.324 + typedef typename Graph::Edge Edge;
1.325 + typedef typename Graph::EdgeIt EdgeIt;
1.326 + typedef typename Graph::InEdgeIt InEdgeIt;
1.327 + typedef typename Graph::OutEdgeIt OutEdgeIt;
1.328 +
1.329 + Node n,m;
1.330 + n=G.addNode();
1.331 + m=G.addNode();
1.332 + Edge e;
1.333 + e=G.addEdge(n,m);
1.334 +
1.335 + // G.clear();
1.336 }
1.337 - }
1.338 - { //bool NodeMap
1.339 - Node k;
1.340 - typename Graph::template NodeMap<bool> m(G);
1.341 - typename Graph::template NodeMap<bool> const &cm = m; //Const map
1.342 - //Inicialize with default value
1.343 - typename Graph::template NodeMap<bool> mdef(G,12);
1.344 - typename Graph::template NodeMap<bool> mm(cm); //Copy
1.345 - typename Graph::template NodeMap<int> dm(cm); //Copy from another type
1.346 - bool v;
1.347 - v=m[k]; m[k]=v; m.set(k,v);
1.348 - v=cm[k];
1.349 -
1.350 - m=cm;
1.351 - dm=cm; //Copy from another type
1.352 - m=dm; //Copy to another type
1.353
1.354 + template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
1.355 {
1.356 - //Check the typedef's
1.357 - typename Graph::template NodeMap<bool>::ValueType val;
1.358 - val=true;
1.359 - typename Graph::template NodeMap<bool>::KeyType key;
1.360 - key= typename Graph::NodeIt(G);
1.361 + typename Graph::Edge e;
1.362 + G.erase(e);
1.363 }
1.364 - }
1.365 - //EdgeMap tests
1.366 - {
1.367 - Edge k;
1.368 - typename Graph::template EdgeMap<int> m(G);
1.369 - typename Graph::template EdgeMap<int> const &cm = m; //Const map
1.370 - //Inicialize with default value
1.371 - typename Graph::template EdgeMap<int> mdef(G,12);
1.372 - typename Graph::template EdgeMap<int> mm(cm); //Copy
1.373 - typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
1.374 - int v;
1.375 - v=m[k]; m[k]=v; m.set(k,v);
1.376 - v=cm[k];
1.377 -
1.378 - m=cm;
1.379 - dm=cm; //Copy from another type
1.380 +
1.381 + template<class Graph> void checkCompileGraphEraseNode(Graph &G)
1.382 {
1.383 - //Check the typedef's
1.384 - typename Graph::template EdgeMap<int>::ValueType val;
1.385 - val=1;
1.386 - typename Graph::template EdgeMap<int>::KeyType key;
1.387 - key= typename Graph::EdgeIt(G);
1.388 + typename Graph::Node n;
1.389 + G.erase(n);
1.390 }
1.391 - }
1.392 - { //bool EdgeMap
1.393 - Edge k;
1.394 - typename Graph::template EdgeMap<bool> m(G);
1.395 - typename Graph::template EdgeMap<bool> const &cm = m; //Const map
1.396 - //Inicialize with default value
1.397 - typename Graph::template EdgeMap<bool> mdef(G,12);
1.398 - typename Graph::template EdgeMap<bool> mm(cm); //Copy
1.399 - typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
1.400 - bool v;
1.401 - v=m[k]; m[k]=v; m.set(k,v);
1.402 - v=cm[k];
1.403 -
1.404 - m=cm;
1.405 - dm=cm; //Copy from another type
1.406 - m=dm; //Copy to another type
1.407 +
1.408 + template<class Graph> void checkCompileErasableGraph(Graph &G)
1.409 {
1.410 - //Check the typedef's
1.411 - typename Graph::template EdgeMap<bool>::ValueType val;
1.412 - val=true;
1.413 - typename Graph::template EdgeMap<bool>::KeyType key;
1.414 - key= typename Graph::EdgeIt(G);
1.415 + checkCompileGraph(G);
1.416 + checkCompileGraphEraseNode(G);
1.417 + checkCompileGraphEraseEdge(G);
1.418 }
1.419 - }
1.420 -}
1.421
1.422 -template<class Graph> void checkCompileGraph(Graph &G)
1.423 -{
1.424 - checkCompileStaticGraph(G);
1.425 + template<class Graph> void checkCompileGraphFindEdge(Graph &G)
1.426 + {
1.427 + typedef typename Graph::NodeIt Node;
1.428 + typedef typename Graph::NodeIt NodeIt;
1.429
1.430 - typedef typename Graph::Node Node;
1.431 - typedef typename Graph::NodeIt NodeIt;
1.432 - typedef typename Graph::Edge Edge;
1.433 - typedef typename Graph::EdgeIt EdgeIt;
1.434 - typedef typename Graph::InEdgeIt InEdgeIt;
1.435 - typedef typename Graph::OutEdgeIt OutEdgeIt;
1.436 -
1.437 - Node n,m;
1.438 - n=G.addNode();
1.439 - m=G.addNode();
1.440 - Edge e;
1.441 - e=G.addEdge(n,m);
1.442 -
1.443 - // G.clear();
1.444 -}
1.445 + G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
1.446 + G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
1.447 + }
1.448
1.449 -template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
1.450 -{
1.451 - typename Graph::Edge e;
1.452 - G.erase(e);
1.453 -}
1.454 + template<class Graph> void checkGraphNodeList(Graph &G, int nn)
1.455 + {
1.456 + typename Graph::NodeIt n(G);
1.457 + for(int i=0;i<nn;i++) {
1.458 + check(n!=INVALID,"Wrong Node list linking.");
1.459 + ++n;
1.460 + }
1.461 + check(n==INVALID,"Wrong Node list linking.");
1.462 + }
1.463
1.464 -template<class Graph> void checkCompileGraphEraseNode(Graph &G)
1.465 -{
1.466 - typename Graph::Node n;
1.467 - G.erase(n);
1.468 -}
1.469 + template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
1.470 + {
1.471 + typedef typename Graph::EdgeIt EdgeIt;
1.472
1.473 -template<class Graph> void checkCompileErasableGraph(Graph &G)
1.474 -{
1.475 - checkCompileGraph(G);
1.476 - checkCompileGraphEraseNode(G);
1.477 - checkCompileGraphEraseEdge(G);
1.478 -}
1.479 + EdgeIt e(G);
1.480 + for(int i=0;i<nn;i++) {
1.481 + check(e!=INVALID,"Wrong Edge list linking.");
1.482 + ++e;
1.483 + }
1.484 + check(e==INVALID,"Wrong Edge list linking.");
1.485 + }
1.486
1.487 -template<class Graph> void checkCompileGraphFindEdge(Graph &G)
1.488 -{
1.489 - typedef typename Graph::NodeIt Node;
1.490 - typedef typename Graph::NodeIt NodeIt;
1.491 + template<class Graph> void checkGraphOutEdgeList(Graph &G,
1.492 + typename Graph::Node n,
1.493 + int nn)
1.494 + {
1.495 + typename Graph::OutEdgeIt e(G,n);
1.496 + for(int i=0;i<nn;i++) {
1.497 + check(e!=INVALID,"Wrong OutEdge list linking.");
1.498 + ++e;
1.499 + }
1.500 + check(e==INVALID,"Wrong OutEdge list linking.");
1.501 + }
1.502
1.503 - G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
1.504 - G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
1.505 -}
1.506 + template<class Graph> void checkGraphInEdgeList(Graph &G,
1.507 + typename Graph::Node n,
1.508 + int nn)
1.509 + {
1.510 + typename Graph::InEdgeIt e(G,n);
1.511 + for(int i=0;i<nn;i++) {
1.512 + check(e!=INVALID,"Wrong InEdge list linking.");
1.513 + ++e;
1.514 + }
1.515 + check(e==INVALID,"Wrong InEdge list linking.");
1.516 + }
1.517
1.518 -template<class Graph> void checkGraphNodeList(Graph &G, int nn)
1.519 -{
1.520 - typename Graph::NodeIt n(G);
1.521 - for(int i=0;i<nn;i++) {
1.522 - check(n!=INVALID,"Wrong Node list linking.");
1.523 - ++n;
1.524 - }
1.525 - check(n==INVALID,"Wrong Node list linking.");
1.526 -}
1.527 -
1.528 -template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
1.529 -{
1.530 - typedef typename Graph::EdgeIt EdgeIt;
1.531 -
1.532 - EdgeIt e(G);
1.533 - for(int i=0;i<nn;i++) {
1.534 - check(e!=INVALID,"Wrong Edge list linking.");
1.535 - ++e;
1.536 - }
1.537 - check(e==INVALID,"Wrong Edge list linking.");
1.538 -}
1.539 -
1.540 -template<class Graph> void checkGraphOutEdgeList(Graph &G,
1.541 - typename Graph::Node n,
1.542 - int nn)
1.543 -{
1.544 - typename Graph::OutEdgeIt e(G,n);
1.545 - for(int i=0;i<nn;i++) {
1.546 - check(e!=INVALID,"Wrong OutEdge list linking.");
1.547 - ++e;
1.548 - }
1.549 - check(e==INVALID,"Wrong OutEdge list linking.");
1.550 -}
1.551 -
1.552 -template<class Graph> void checkGraphInEdgeList(Graph &G,
1.553 - typename Graph::Node n,
1.554 - int nn)
1.555 -{
1.556 - typename Graph::InEdgeIt e(G,n);
1.557 - for(int i=0;i<nn;i++) {
1.558 - check(e!=INVALID,"Wrong InEdge list linking.");
1.559 - ++e;
1.560 - }
1.561 - check(e==INVALID,"Wrong InEdge list linking.");
1.562 -}
1.563 -
1.564 -///\file
1.565 -///\todo Check head(), tail() as well;
1.566 + ///\file
1.567 + ///\todo Check head(), tail() as well;
1.568
1.569
1.570 } //namespace hugo