1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/graph_test.h Fri Sep 03 17:34:22 2004 +0000
1.3 @@ -0,0 +1,306 @@
1.4 +#ifndef HUGO_TEST_GRAPH_TEST_H
1.5 +#define HUGO_TEST_GRAPH_TEST_H
1.6 +
1.7 +
1.8 +#include "test_tools.h"
1.9 +
1.10 +//! \ingroup misc
1.11 +//! \file
1.12 +//! \brief Some utility to test graph classes.
1.13 +namespace hugo {
1.14 +
1.15 +
1.16 +template<class Graph> void checkCompileStaticGraph(Graph &G)
1.17 +{
1.18 + typedef typename Graph::Node Node;
1.19 + typedef typename Graph::NodeIt NodeIt;
1.20 + typedef typename Graph::Edge Edge;
1.21 + typedef typename Graph::EdgeIt EdgeIt;
1.22 + typedef typename Graph::InEdgeIt InEdgeIt;
1.23 + typedef typename Graph::OutEdgeIt OutEdgeIt;
1.24 +
1.25 + {
1.26 + Node i; Node j(i); Node k(INVALID);
1.27 + i=j;
1.28 + // bool b=G.valid(i); b=b;
1.29 + bool b; b=b;
1.30 + b=(i==INVALID); b=(i!=INVALID);
1.31 + b=(i==j); b=(i!=j); b=(i<j);
1.32 + }
1.33 + {
1.34 + NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
1.35 + i=j;
1.36 + j=G.first(i);
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; b=b;
1.52 + b=(i==INVALID); b=(i!=INVALID);
1.53 + b=(i==j); b=(i!=j); b=(i<j);
1.54 + }
1.55 + {
1.56 + EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
1.57 + i=j;
1.58 + j=G.first(i);
1.59 + j=++i;
1.60 + // bool b=G.valid(i); b=b;
1.61 + bool b; b=b;
1.62 + b=(i==INVALID); b=(i!=INVALID);
1.63 + Edge e(i);
1.64 + e=i;
1.65 + b=(i==j); b=(i!=j); b=(i<j);
1.66 + //Edge ->EdgeIt conversion
1.67 + EdgeIt ei(G,e);
1.68 + }
1.69 + {
1.70 + Node n;
1.71 + InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
1.72 + i=j;
1.73 + j=G.first(i,n);
1.74 + j=++i;
1.75 + // bool b=G.valid(i); b=b;
1.76 + bool b; b=b;
1.77 + b=(i==INVALID); b=(i!=INVALID);
1.78 + Edge e(i);
1.79 + e=i;
1.80 + b=(i==j); b=(i!=j); b=(i<j);
1.81 + //Edge ->InEdgeIt conversion
1.82 + InEdgeIt ei(G,e);
1.83 + }
1.84 + {
1.85 + Node n;
1.86 + OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
1.87 + i=j;
1.88 + j=G.first(i,n);
1.89 + j=++i;
1.90 + // bool b=G.valid(i); b=b;
1.91 + bool b; b=b;
1.92 + b=(i==INVALID); b=(i!=INVALID);
1.93 + Edge e(i);
1.94 + e=i;
1.95 + b=(i==j); b=(i!=j); b=(i<j);
1.96 + //Edge ->OutEdgeIt conversion
1.97 + OutEdgeIt ei(G,e);
1.98 + }
1.99 + {
1.100 + Node n,m;
1.101 + n=m=INVALID;
1.102 + Edge e;
1.103 + e=INVALID;
1.104 + n=G.tail(e);
1.105 + n=G.head(e);
1.106 + }
1.107 + // id tests
1.108 + { Node n; int i=G.id(n); i=i; }
1.109 + { Edge e; int i=G.id(e); i=i; }
1.110 + //NodeMap tests
1.111 + {
1.112 + Node k;
1.113 + typename Graph::template NodeMap<int> m(G);
1.114 + //Const map
1.115 + typename Graph::template NodeMap<int> const &cm = m;
1.116 + //Inicialize with default value
1.117 + typename Graph::template NodeMap<int> mdef(G,12);
1.118 + //Copy
1.119 + typename Graph::template NodeMap<int> mm(cm);
1.120 + //Copy from another type
1.121 + typename Graph::template NodeMap<double> dm(cm);
1.122 + int v;
1.123 + v=m[k]; m[k]=v; m.set(k,v);
1.124 + v=cm[k];
1.125 +
1.126 + m=cm;
1.127 + dm=cm; //Copy from another type
1.128 + {
1.129 + //Check the typedef's
1.130 + typename Graph::template NodeMap<int>::ValueType val;
1.131 + val=1;
1.132 + typename Graph::template NodeMap<int>::KeyType key;
1.133 + key = typename Graph::NodeIt(G);
1.134 + }
1.135 + }
1.136 + { //bool NodeMap
1.137 + Node k;
1.138 + typename Graph::template NodeMap<bool> m(G);
1.139 + typename Graph::template NodeMap<bool> const &cm = m; //Const map
1.140 + //Inicialize with default value
1.141 + typename Graph::template NodeMap<bool> mdef(G,12);
1.142 + typename Graph::template NodeMap<bool> mm(cm); //Copy
1.143 + typename Graph::template NodeMap<int> dm(cm); //Copy from another type
1.144 + bool v;
1.145 + v=m[k]; m[k]=v; m.set(k,v);
1.146 + v=cm[k];
1.147 +
1.148 + m=cm;
1.149 + dm=cm; //Copy from another type
1.150 + m=dm; //Copy to another type
1.151 +
1.152 + {
1.153 + //Check the typedef's
1.154 + typename Graph::template NodeMap<bool>::ValueType val;
1.155 + val=true;
1.156 + typename Graph::template NodeMap<bool>::KeyType key;
1.157 + key= typename Graph::NodeIt(G);
1.158 + }
1.159 + }
1.160 + //EdgeMap tests
1.161 + {
1.162 + Edge k;
1.163 + typename Graph::template EdgeMap<int> m(G);
1.164 + typename Graph::template EdgeMap<int> const &cm = m; //Const map
1.165 + //Inicialize with default value
1.166 + typename Graph::template EdgeMap<int> mdef(G,12);
1.167 + typename Graph::template EdgeMap<int> mm(cm); //Copy
1.168 + typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
1.169 + int v;
1.170 + v=m[k]; m[k]=v; m.set(k,v);
1.171 + v=cm[k];
1.172 +
1.173 + m=cm;
1.174 + dm=cm; //Copy from another type
1.175 + {
1.176 + //Check the typedef's
1.177 + typename Graph::template EdgeMap<int>::ValueType val;
1.178 + val=1;
1.179 + typename Graph::template EdgeMap<int>::KeyType key;
1.180 + key= typename Graph::EdgeIt(G);
1.181 + }
1.182 + }
1.183 + { //bool EdgeMap
1.184 + Edge k;
1.185 + typename Graph::template EdgeMap<bool> m(G);
1.186 + typename Graph::template EdgeMap<bool> const &cm = m; //Const map
1.187 + //Inicialize with default value
1.188 + typename Graph::template EdgeMap<bool> mdef(G,12);
1.189 + typename Graph::template EdgeMap<bool> mm(cm); //Copy
1.190 + typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
1.191 + bool v;
1.192 + v=m[k]; m[k]=v; m.set(k,v);
1.193 + v=cm[k];
1.194 +
1.195 + m=cm;
1.196 + dm=cm; //Copy from another type
1.197 + m=dm; //Copy to another type
1.198 + {
1.199 + //Check the typedef's
1.200 + typename Graph::template EdgeMap<bool>::ValueType val;
1.201 + val=true;
1.202 + typename Graph::template EdgeMap<bool>::KeyType key;
1.203 + key= typename Graph::EdgeIt(G);
1.204 + }
1.205 + }
1.206 +}
1.207 +
1.208 +template<class Graph> void checkCompileGraph(Graph &G)
1.209 +{
1.210 + checkCompileStaticGraph(G);
1.211 +
1.212 + typedef typename Graph::Node Node;
1.213 + typedef typename Graph::NodeIt NodeIt;
1.214 + typedef typename Graph::Edge Edge;
1.215 + typedef typename Graph::EdgeIt EdgeIt;
1.216 + typedef typename Graph::InEdgeIt InEdgeIt;
1.217 + typedef typename Graph::OutEdgeIt OutEdgeIt;
1.218 +
1.219 + Node n,m;
1.220 + n=G.addNode();
1.221 + m=G.addNode();
1.222 + Edge e;
1.223 + e=G.addEdge(n,m);
1.224 +
1.225 + // G.clear();
1.226 +}
1.227 +
1.228 +template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
1.229 +{
1.230 + typename Graph::Edge e;
1.231 + G.erase(e);
1.232 +}
1.233 +
1.234 +template<class Graph> void checkCompileGraphEraseNode(Graph &G)
1.235 +{
1.236 + typename Graph::Node n;
1.237 + G.erase(n);
1.238 +}
1.239 +
1.240 +template<class Graph> void checkCompileErasableGraph(Graph &G)
1.241 +{
1.242 + checkCompileGraph(G);
1.243 + checkCompileGraphEraseNode(G);
1.244 + checkCompileGraphEraseEdge(G);
1.245 +}
1.246 +
1.247 +template<class Graph> void checkCompileGraphFindEdge(Graph &G)
1.248 +{
1.249 + typedef typename Graph::NodeIt Node;
1.250 + typedef typename Graph::NodeIt NodeIt;
1.251 +
1.252 + G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
1.253 + G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
1.254 +}
1.255 +
1.256 +template<class Graph> void checkGraphNodeList(Graph &G, int nn)
1.257 +{
1.258 + typename Graph::NodeIt n(G);
1.259 + for(int i=0;i<nn;i++) {
1.260 + check(n!=INVALID,"Wrong Node list linking.");
1.261 + ++n;
1.262 + }
1.263 + check(n==INVALID,"Wrong Node list linking.");
1.264 +}
1.265 +
1.266 +template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
1.267 +{
1.268 + typedef typename Graph::EdgeIt EdgeIt;
1.269 +
1.270 + EdgeIt e(G);
1.271 + for(int i=0;i<nn;i++) {
1.272 + check(e!=INVALID,"Wrong Edge list linking.");
1.273 + ++e;
1.274 + }
1.275 + check(e==INVALID,"Wrong Edge list linking.");
1.276 +}
1.277 +
1.278 +template<class Graph> void checkGraphOutEdgeList(Graph &G,
1.279 + typename Graph::Node n,
1.280 + int nn)
1.281 +{
1.282 + typename Graph::OutEdgeIt e(G,n);
1.283 + for(int i=0;i<nn;i++) {
1.284 + check(e!=INVALID,"Wrong OutEdge list linking.");
1.285 + ++e;
1.286 + }
1.287 + check(e==INVALID,"Wrong OutEdge list linking.");
1.288 +}
1.289 +
1.290 +template<class Graph> void checkGraphInEdgeList(Graph &G,
1.291 + typename Graph::Node n,
1.292 + int nn)
1.293 +{
1.294 + typename Graph::InEdgeIt e(G,n);
1.295 + for(int i=0;i<nn;i++) {
1.296 + check(e!=INVALID,"Wrong InEdge list linking.");
1.297 + ++e;
1.298 + }
1.299 + check(e==INVALID,"Wrong InEdge list linking.");
1.300 +}
1.301 +
1.302 +///\file
1.303 +///\todo Check head(), tail() as well;
1.304 +
1.305 +
1.306 +} //namespace hugo
1.307 +
1.308 +
1.309 +#endif