1 #ifndef HUGO_TEST_GRAPH_TEST_H
2 #define HUGO_TEST_GRAPH_TEST_H
5 #include "test_tools.h"
9 //! \brief Some utility to test graph classes.
13 template<class Graph> void checkCompileStaticGraph(Graph &G)
15 typedef typename Graph::Node Node;
16 typedef typename Graph::NodeIt NodeIt;
17 typedef typename Graph::Edge Edge;
18 typedef typename Graph::EdgeIt EdgeIt;
19 typedef typename Graph::InEdgeIt InEdgeIt;
20 typedef typename Graph::OutEdgeIt OutEdgeIt;
23 Node i; Node j(i); Node k(INVALID);
26 b=(i==INVALID); b=(i!=INVALID);
27 b=(i==j); b=(i!=j); b=(i<j);
30 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
35 b=(i==INVALID); b=(i!=INVALID);
38 b=(i==j); b=(i!=j); b=(i<j);
39 //Node ->NodeIt conversion
43 Edge i; Edge j(i); Edge k(INVALID);
46 b=(i==INVALID); b=(i!=INVALID);
47 b=(i==j); b=(i!=j); b=(i<j);
50 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
55 b=(i==INVALID); b=(i!=INVALID);
58 b=(i==j); b=(i!=j); b=(i<j);
59 //Edge ->EdgeIt conversion
64 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
69 b=(i==INVALID); b=(i!=INVALID);
72 b=(i==j); b=(i!=j); b=(i<j);
73 //Edge ->InEdgeIt conversion
78 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
83 b=(i==INVALID); b=(i!=INVALID);
86 b=(i==j); b=(i!=j); b=(i<j);
87 //Edge ->OutEdgeIt conversion
99 { Node n; int i=G.id(n); i=i; }
100 { Edge e; int i=G.id(e); i=i; }
104 typename Graph::template NodeMap<int> m(G);
106 typename Graph::template NodeMap<int> const &cm = m;
107 //Inicialize with default value
108 typename Graph::template NodeMap<int> mdef(G,12);
110 typename Graph::template NodeMap<int> mm(cm);
111 //Copy from another type
112 typename Graph::template NodeMap<double> dm(cm);
114 v=m[k]; m[k]=v; m.set(k,v);
118 dm=cm; //Copy from another type
120 //Check the typedef's
121 typename Graph::template NodeMap<int>::ValueType val;
123 typename Graph::template NodeMap<int>::KeyType key;
124 key = typename Graph::NodeIt(G);
129 typename Graph::template NodeMap<bool> m(G);
130 typename Graph::template NodeMap<bool> const &cm = m; //Const map
131 //Inicialize with default value
132 typename Graph::template NodeMap<bool> mdef(G,12);
133 typename Graph::template NodeMap<bool> mm(cm); //Copy
134 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
136 v=m[k]; m[k]=v; m.set(k,v);
140 dm=cm; //Copy from another type
141 m=dm; //Copy to another type
144 //Check the typedef's
145 typename Graph::template NodeMap<bool>::ValueType val;
147 typename Graph::template NodeMap<bool>::KeyType key;
148 key= typename Graph::NodeIt(G);
154 typename Graph::template EdgeMap<int> m(G);
155 typename Graph::template EdgeMap<int> const &cm = m; //Const map
156 //Inicialize with default value
157 typename Graph::template EdgeMap<int> mdef(G,12);
158 typename Graph::template EdgeMap<int> mm(cm); //Copy
159 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
161 v=m[k]; m[k]=v; m.set(k,v);
165 dm=cm; //Copy from another type
167 //Check the typedef's
168 typename Graph::template EdgeMap<int>::ValueType val;
170 typename Graph::template EdgeMap<int>::KeyType key;
171 key= typename Graph::EdgeIt(G);
176 typename Graph::template EdgeMap<bool> m(G);
177 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
178 //Inicialize with default value
179 typename Graph::template EdgeMap<bool> mdef(G,12);
180 typename Graph::template EdgeMap<bool> mm(cm); //Copy
181 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
183 v=m[k]; m[k]=v; m.set(k,v);
187 dm=cm; //Copy from another type
188 m=dm; //Copy to another type
190 //Check the typedef's
191 typename Graph::template EdgeMap<bool>::ValueType val;
193 typename Graph::template EdgeMap<bool>::KeyType key;
194 key= typename Graph::EdgeIt(G);
199 template<class Graph> void checkCompileGraph(Graph &G)
201 checkCompileStaticGraph(G);
203 typedef typename Graph::Node Node;
204 typedef typename Graph::NodeIt NodeIt;
205 typedef typename Graph::Edge Edge;
206 typedef typename Graph::EdgeIt EdgeIt;
207 typedef typename Graph::InEdgeIt InEdgeIt;
208 typedef typename Graph::OutEdgeIt OutEdgeIt;
219 template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
221 typename Graph::Edge e;
225 template<class Graph> void checkCompileGraphEraseNode(Graph &G)
227 typename Graph::Node n;
231 template<class Graph> void checkCompileErasableGraph(Graph &G)
233 checkCompileGraph(G);
234 checkCompileGraphEraseNode(G);
235 checkCompileGraphEraseEdge(G);
238 template<class Graph> void checkCompileGraphFindEdge(Graph &G)
240 typedef typename Graph::NodeIt Node;
241 typedef typename Graph::NodeIt NodeIt;
243 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
244 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
247 template<class Graph> void checkGraphNodeList(Graph &G, int nn)
249 typename Graph::NodeIt n(G);
250 for(int i=0;i<nn;i++) {
251 check(n!=INVALID,"Wrong Node list linking.");
254 check(n==INVALID,"Wrong Node list linking.");
257 template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
259 typedef typename Graph::EdgeIt EdgeIt;
262 for(int i=0;i<nn;i++) {
263 check(e!=INVALID,"Wrong Edge list linking.");
266 check(e==INVALID,"Wrong Edge list linking.");
269 template<class Graph> void checkGraphOutEdgeList(Graph &G,
270 typename Graph::Node n,
273 typename Graph::OutEdgeIt e(G,n);
274 for(int i=0;i<nn;i++) {
275 check(e!=INVALID,"Wrong OutEdge list linking.");
278 check(e==INVALID,"Wrong OutEdge list linking.");
281 template<class Graph> void checkGraphInEdgeList(Graph &G,
282 typename Graph::Node n,
285 typename Graph::InEdgeIt e(G,n);
286 for(int i=0;i<nn;i++) {
287 check(e!=INVALID,"Wrong InEdge list linking.");
290 check(e==INVALID,"Wrong InEdge list linking.");
294 ///\todo Check head(), tail() as well;