1.1 --- a/src/test/graph_test.cc Fri Sep 03 15:32:03 2004 +0000
1.2 +++ b/src/test/graph_test.cc Fri Sep 03 17:34:22 2004 +0000
1.3 @@ -5,6 +5,7 @@
1.4 #include<hugo/full_graph.h>
1.5
1.6 #include"test_tools.h"
1.7 +#include"graph_test.h"
1.8
1.9 /**
1.10 \file
1.11 @@ -13,306 +14,17 @@
1.12 G.addNode(), G.addEdge(), G.tail(), G.head()
1.13
1.14 \todo Checks for empty graphs and isolated points.
1.15 -\todo Checks for Node->NodeIt, Edge->{EdgeIt,InEdgeIt,OutEdgeIt}
1.16 conversion.
1.17 */
1.18
1.19 using namespace hugo;
1.20
1.21 -template<class Graph> void checkCompileStaticGraph(Graph &G)
1.22 -{
1.23 - typedef typename Graph::Node Node;
1.24 - typedef typename Graph::NodeIt NodeIt;
1.25 - typedef typename Graph::Edge Edge;
1.26 - typedef typename Graph::EdgeIt EdgeIt;
1.27 - typedef typename Graph::InEdgeIt InEdgeIt;
1.28 - typedef typename Graph::OutEdgeIt OutEdgeIt;
1.29 -
1.30 - {
1.31 - Node i; Node j(i); Node k(INVALID);
1.32 - i=j;
1.33 - // bool b=G.valid(i); b=b;
1.34 - bool b; b=b;
1.35 - b=(i==INVALID); b=(i!=INVALID);
1.36 - b=(i==j); b=(i!=j); b=(i<j);
1.37 - }
1.38 - {
1.39 - NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
1.40 - i=j;
1.41 - j=G.first(i);
1.42 - j=++i;
1.43 - // bool b=G.valid(i); b=b;
1.44 - bool b; b=b;
1.45 - b=(i==INVALID); b=(i!=INVALID);
1.46 - Node n(i);
1.47 - n=i;
1.48 - b=(i==j); b=(i!=j); b=(i<j);
1.49 - //Node ->NodeIt conversion
1.50 - NodeIt ni(G,n);
1.51 - }
1.52 - {
1.53 - Edge i; Edge j(i); Edge k(INVALID);
1.54 - i=j;
1.55 - // bool b=G.valid(i); b=b;
1.56 - bool b; b=b;
1.57 - b=(i==INVALID); b=(i!=INVALID);
1.58 - b=(i==j); b=(i!=j); b=(i<j);
1.59 - }
1.60 - {
1.61 - EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
1.62 - i=j;
1.63 - j=G.first(i);
1.64 - j=++i;
1.65 - // bool b=G.valid(i); b=b;
1.66 - bool b; b=b;
1.67 - b=(i==INVALID); b=(i!=INVALID);
1.68 - Edge e(i);
1.69 - e=i;
1.70 - b=(i==j); b=(i!=j); b=(i<j);
1.71 - //Edge ->EdgeIt conversion
1.72 - EdgeIt ei(G,e);
1.73 - }
1.74 - {
1.75 - Node n;
1.76 - InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
1.77 - i=j;
1.78 - j=G.first(i,n);
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=++i;
1.95 - // bool b=G.valid(i); b=b;
1.96 - bool b; b=b;
1.97 - b=(i==INVALID); b=(i!=INVALID);
1.98 - Edge e(i);
1.99 - e=i;
1.100 - b=(i==j); b=(i!=j); b=(i<j);
1.101 - //Edge ->OutEdgeIt conversion
1.102 - OutEdgeIt ei(G,e);
1.103 - }
1.104 - {
1.105 - Node n,m;
1.106 - n=m=INVALID;
1.107 - Edge e;
1.108 - e=INVALID;
1.109 - n=G.tail(e);
1.110 - n=G.head(e);
1.111 - }
1.112 - // id tests
1.113 - { Node n; int i=G.id(n); i=i; }
1.114 - { Edge e; int i=G.id(e); i=i; }
1.115 - //NodeMap tests
1.116 - {
1.117 - Node k;
1.118 - typename Graph::template NodeMap<int> m(G);
1.119 - //Const map
1.120 - typename Graph::template NodeMap<int> const &cm = m;
1.121 - //Inicialize with default value
1.122 - typename Graph::template NodeMap<int> mdef(G,12);
1.123 - //Copy
1.124 - typename Graph::template NodeMap<int> mm(cm);
1.125 - //Copy from another type
1.126 - typename Graph::template NodeMap<double> dm(cm);
1.127 - int v;
1.128 - v=m[k]; m[k]=v; m.set(k,v);
1.129 - v=cm[k];
1.130 -
1.131 - m=cm;
1.132 - dm=cm; //Copy from another type
1.133 - {
1.134 - //Check the typedef's
1.135 - typename Graph::template NodeMap<int>::ValueType val;
1.136 - val=1;
1.137 - typename Graph::template NodeMap<int>::KeyType key;
1.138 - key = typename Graph::NodeIt(G);
1.139 - }
1.140 - }
1.141 - { //bool NodeMap
1.142 - Node k;
1.143 - typename Graph::template NodeMap<bool> m(G);
1.144 - typename Graph::template NodeMap<bool> const &cm = m; //Const map
1.145 - //Inicialize with default value
1.146 - typename Graph::template NodeMap<bool> mdef(G,12);
1.147 - typename Graph::template NodeMap<bool> mm(cm); //Copy
1.148 - typename Graph::template NodeMap<int> dm(cm); //Copy from another type
1.149 - bool v;
1.150 - v=m[k]; m[k]=v; m.set(k,v);
1.151 - v=cm[k];
1.152 -
1.153 - m=cm;
1.154 - dm=cm; //Copy from another type
1.155 - m=dm; //Copy to another type
1.156 -
1.157 - {
1.158 - //Check the typedef's
1.159 - typename Graph::template NodeMap<bool>::ValueType val;
1.160 - val=true;
1.161 - typename Graph::template NodeMap<bool>::KeyType key;
1.162 - key= typename Graph::NodeIt(G);
1.163 - }
1.164 - }
1.165 - //EdgeMap tests
1.166 - {
1.167 - Edge k;
1.168 - typename Graph::template EdgeMap<int> m(G);
1.169 - typename Graph::template EdgeMap<int> const &cm = m; //Const map
1.170 - //Inicialize with default value
1.171 - typename Graph::template EdgeMap<int> mdef(G,12);
1.172 - typename Graph::template EdgeMap<int> mm(cm); //Copy
1.173 - typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
1.174 - int v;
1.175 - v=m[k]; m[k]=v; m.set(k,v);
1.176 - v=cm[k];
1.177 -
1.178 - m=cm;
1.179 - dm=cm; //Copy from another type
1.180 - {
1.181 - //Check the typedef's
1.182 - typename Graph::template EdgeMap<int>::ValueType val;
1.183 - val=1;
1.184 - typename Graph::template EdgeMap<int>::KeyType key;
1.185 - key= typename Graph::EdgeIt(G);
1.186 - }
1.187 - }
1.188 - { //bool EdgeMap
1.189 - Edge k;
1.190 - typename Graph::template EdgeMap<bool> m(G);
1.191 - typename Graph::template EdgeMap<bool> const &cm = m; //Const map
1.192 - //Inicialize with default value
1.193 - typename Graph::template EdgeMap<bool> mdef(G,12);
1.194 - typename Graph::template EdgeMap<bool> mm(cm); //Copy
1.195 - typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
1.196 - bool v;
1.197 - v=m[k]; m[k]=v; m.set(k,v);
1.198 - v=cm[k];
1.199 -
1.200 - m=cm;
1.201 - dm=cm; //Copy from another type
1.202 - m=dm; //Copy to another type
1.203 - {
1.204 - //Check the typedef's
1.205 - typename Graph::template EdgeMap<bool>::ValueType val;
1.206 - val=true;
1.207 - typename Graph::template EdgeMap<bool>::KeyType key;
1.208 - key= typename Graph::EdgeIt(G);
1.209 - }
1.210 - }
1.211 -}
1.212 -
1.213 -template<class Graph> void checkCompile(Graph &G)
1.214 -{
1.215 - checkCompileStaticGraph(G);
1.216 -
1.217 - typedef typename Graph::Node Node;
1.218 - typedef typename Graph::NodeIt NodeIt;
1.219 - typedef typename Graph::Edge Edge;
1.220 - typedef typename Graph::EdgeIt EdgeIt;
1.221 - typedef typename Graph::InEdgeIt InEdgeIt;
1.222 - typedef typename Graph::OutEdgeIt OutEdgeIt;
1.223 -
1.224 - Node n,m;
1.225 - n=G.addNode();
1.226 - m=G.addNode();
1.227 - Edge e;
1.228 - e=G.addEdge(n,m);
1.229 -
1.230 - // G.clear();
1.231 -}
1.232 -
1.233 -template<class Graph> void checkCompileErase(Graph &G)
1.234 -{
1.235 - typedef typename Graph::Node Node;
1.236 - typedef typename Graph::Edge Edge;
1.237 - Node n;
1.238 - Edge e;
1.239 - G.erase(n);
1.240 - G.erase(e);
1.241 -}
1.242 -
1.243 -template<class Graph> void checkCompileEraseEdge(Graph &G)
1.244 -{
1.245 - typedef typename Graph::Edge Edge;
1.246 - Edge e;
1.247 - G.erase(e);
1.248 -}
1.249 -
1.250 -template<class Graph> void checkCompileFindEdge(Graph &G)
1.251 -{
1.252 - typedef typename Graph::NodeIt Node;
1.253 - typedef typename Graph::NodeIt NodeIt;
1.254 -
1.255 - G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
1.256 - G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
1.257 -}
1.258 -
1.259 -
1.260 -template<class Graph> void checkNodeList(Graph &G, int nn)
1.261 -{
1.262 - typename Graph::NodeIt n(G);
1.263 - for(int i=0;i<nn;i++) {
1.264 - check(n!=INVALID,"Wrong Node list linking.");
1.265 - ++n;
1.266 - }
1.267 - check(n==INVALID,"Wrong Node list linking.");
1.268 -}
1.269 -
1.270 -template<class Graph> void checkEdgeList(Graph &G, int nn)
1.271 -{
1.272 - typedef typename Graph::EdgeIt EdgeIt;
1.273 -
1.274 - EdgeIt e(G);
1.275 - for(int i=0;i<nn;i++) {
1.276 - check(e!=INVALID,"Wrong Edge list linking.");
1.277 - ++e;
1.278 - }
1.279 - check(e==INVALID,"Wrong Edge list linking.");
1.280 -}
1.281 -
1.282 -template<class Graph> void checkOutEdgeList(Graph &G,
1.283 - typename Graph::Node n,
1.284 - int nn)
1.285 -{
1.286 - typename Graph::OutEdgeIt e(G,n);
1.287 - for(int i=0;i<nn;i++) {
1.288 - check(e!=INVALID,"Wrong OutEdge list linking.");
1.289 - ++e;
1.290 - }
1.291 - check(e==INVALID,"Wrong OutEdge list linking.");
1.292 -}
1.293 -
1.294 -template<class Graph> void checkInEdgeList(Graph &G,
1.295 - typename Graph::Node n,
1.296 - int nn)
1.297 -{
1.298 - typename Graph::InEdgeIt e(G,n);
1.299 - for(int i=0;i<nn;i++) {
1.300 - check(e!=INVALID,"Wrong InEdge list linking.");
1.301 - ++e;
1.302 - }
1.303 - check(e==INVALID,"Wrong InEdge list linking.");
1.304 -}
1.305 -
1.306 -///\file
1.307 -///\todo Checks head(), tail() as well;
1.308 -
1.309 template<class Graph> void bidirPetersen(Graph &G)
1.310 {
1.311 typedef typename Graph::Edge Edge;
1.312 typedef typename Graph::EdgeIt EdgeIt;
1.313
1.314 - checkEdgeList(G,15);
1.315 + checkGraphEdgeList(G,15);
1.316
1.317 std::vector<Edge> ee;
1.318
1.319 @@ -329,12 +41,12 @@
1.320 typedef typename Graph::EdgeIt EdgeIt;
1.321 typedef typename Graph::NodeIt NodeIt;
1.322
1.323 - checkNodeList(G,10);
1.324 - checkEdgeList(G,30);
1.325 + checkGraphNodeList(G,10);
1.326 + checkGraphEdgeList(G,30);
1.327
1.328 for(NodeIt n(G);n!=INVALID;++n) {
1.329 - checkInEdgeList(G,n,3);
1.330 - checkOutEdgeList(G,n,3);
1.331 + checkGraphInEdgeList(G,n,3);
1.332 + checkGraphOutEdgeList(G,n,3);
1.333 ++n;
1.334 }
1.335 }
1.336 @@ -343,44 +55,48 @@
1.337 template void checkCompileStaticGraph<skeleton::StaticGraphSkeleton>
1.338 (skeleton::StaticGraphSkeleton &);
1.339
1.340 -template void checkCompile<skeleton::GraphSkeleton>(skeleton::GraphSkeleton &);
1.341 +template void checkCompileGraph<skeleton::GraphSkeleton>
1.342 +(skeleton::GraphSkeleton &);
1.343
1.344 -template void checkCompileErase<skeleton::EraseableGraphSkeleton>
1.345 +template void checkCompileErasableGraph<skeleton::EraseableGraphSkeleton>
1.346 (skeleton::EraseableGraphSkeleton &);
1.347
1.348 //Compile SmartGraph
1.349 -template void checkCompile<SmartGraph>(SmartGraph &);
1.350 +template void checkCompileGraph<SmartGraph>(SmartGraph &);
1.351 +template void checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
1.352
1.353 //Compile SymSmartGraph
1.354 -template void checkCompile<SymSmartGraph>(SymSmartGraph &);
1.355 +template void checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
1.356 +template void checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
1.357
1.358 //Compile ListGraph
1.359 -template void checkCompile<ListGraph>(ListGraph &);
1.360 -template void checkCompileErase<ListGraph>(ListGraph &);
1.361 -template void checkCompileFindEdge<ListGraph>(ListGraph &);
1.362 +template void checkCompileGraph<ListGraph>(ListGraph &);
1.363 +template void checkCompileErasableGraph<ListGraph>(ListGraph &);
1.364 +template void checkCompileGraphFindEdge<ListGraph>(ListGraph &);
1.365
1.366
1.367 //Compile SymListGraph
1.368 -template void checkCompile<SymListGraph>(SymListGraph &);
1.369 -template void checkCompileErase<SymListGraph>(SymListGraph &);
1.370 -template void checkCompileFindEdge<SymListGraph>(SymListGraph &);
1.371 +template void checkCompileGraph<SymListGraph>(SymListGraph &);
1.372 +template void checkCompileErasableGraph<SymListGraph>(SymListGraph &);
1.373 +template void checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
1.374
1.375 //Compile FullGraph
1.376 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
1.377 -template void checkCompileFindEdge<FullGraph>(FullGraph &);
1.378 +template void checkCompileGraphFindEdge<FullGraph>(FullGraph &);
1.379
1.380 //Compile EdgeSet <ListGraph>
1.381 -template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.382 -template
1.383 -void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.384 -template
1.385 -void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.386 +template void checkCompileGraph<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
1.387 +template void checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
1.388 +(EdgeSet <ListGraph> &);
1.389 +template void checkCompileGraphFindEdge<EdgeSet <ListGraph> >
1.390 +(EdgeSet <ListGraph> &);
1.391
1.392 //Compile EdgeSet <NodeSet>
1.393 -template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.394 -template
1.395 -void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.396 -template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.397 +template void checkCompileGraph<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
1.398 +template void checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
1.399 +(EdgeSet <NodeSet> &);
1.400 +template void checkCompileGraphFindEdge<EdgeSet <NodeSet> >
1.401 +(EdgeSet <NodeSet> &);
1.402
1.403
1.404 int main()