graph_wrappers now pass the tests.
2 #ifndef HUGO_TEST_GRAPH_TEST_H
3 #define HUGO_TEST_GRAPH_TEST_H
6 #include "test_tools.h"
10 //! \brief Some utility to test graph classes.
16 DummyType(int p) : value(p) {}
17 DummyType& operator=(int p) { value = p; return *this;}
21 template<class Graph> void checkCompileStaticGraph(Graph &G)
23 typedef typename Graph::Node Node;
24 typedef typename Graph::NodeIt NodeIt;
25 typedef typename Graph::Edge Edge;
26 typedef typename Graph::EdgeIt EdgeIt;
27 typedef typename Graph::InEdgeIt InEdgeIt;
28 typedef typename Graph::OutEdgeIt OutEdgeIt;
31 Node i; Node j(i); Node k(INVALID);
34 b=(i==INVALID); b=(i!=INVALID);
35 b=(i==j); b=(i!=j); b=(i<j);
38 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
43 b=(i==INVALID); b=(i!=INVALID);
46 b=(i==j); b=(i!=j); b=(i<j);
47 //Node ->NodeIt conversion
51 Edge i; Edge j(i); Edge k(INVALID);
54 b=(i==INVALID); b=(i!=INVALID);
55 b=(i==j); b=(i!=j); b=(i<j);
58 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
63 b=(i==INVALID); b=(i!=INVALID);
66 b=(i==j); b=(i!=j); b=(i<j);
67 //Edge ->EdgeIt conversion
72 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
77 b=(i==INVALID); b=(i!=INVALID);
80 b=(i==j); b=(i!=j); b=(i<j);
81 //Edge ->InEdgeIt conversion
86 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
91 b=(i==INVALID); b=(i!=INVALID);
94 b=(i==j); b=(i!=j); b=(i<j);
95 //Edge ->OutEdgeIt conversion
107 { Node n; int i=G.id(n); i=i; }
108 { Edge e; int i=G.id(e); i=i; }
112 typename Graph::template NodeMap<int> m(G);
114 typename Graph::template NodeMap<int> const &cm = m;
115 //Inicialize with default value
116 typename Graph::template NodeMap<int> mdef(G,12);
118 typename Graph::template NodeMap<int> mm(cm);
119 //Copy from another type
120 typename Graph::template NodeMap<double> dm(cm);
121 //Copy to more complex type
122 typename Graph::template NodeMap<DummyType> em(cm);
124 v=m[k]; m[k]=v; m.set(k,v);
128 dm=cm; //Copy from another type
129 em=cm; //Copy to more complex type
131 //Check the typedef's
132 typename Graph::template NodeMap<int>::ValueType val;
134 typename Graph::template NodeMap<int>::KeyType key;
135 key = typename Graph::NodeIt(G);
140 typename Graph::template NodeMap<bool> m(G);
141 typename Graph::template NodeMap<bool> const &cm = m; //Const map
142 //Inicialize with default value
143 typename Graph::template NodeMap<bool> mdef(G,12);
144 typename Graph::template NodeMap<bool> mm(cm); //Copy
145 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
147 v=m[k]; m[k]=v; m.set(k,v);
151 dm=cm; //Copy from another type
152 m=dm; //Copy to another type
155 //Check the typedef's
156 typename Graph::template NodeMap<bool>::ValueType val;
158 typename Graph::template NodeMap<bool>::KeyType key;
159 key= typename Graph::NodeIt(G);
165 typename Graph::template EdgeMap<int> m(G);
166 typename Graph::template EdgeMap<int> const &cm = m; //Const map
167 //Inicialize with default value
168 typename Graph::template EdgeMap<int> mdef(G,12);
169 typename Graph::template EdgeMap<int> mm(cm); //Copy
170 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
172 v=m[k]; m[k]=v; m.set(k,v);
176 dm=cm; //Copy from another type
178 //Check the typedef's
179 typename Graph::template EdgeMap<int>::ValueType val;
181 typename Graph::template EdgeMap<int>::KeyType key;
182 key= typename Graph::EdgeIt(G);
187 typename Graph::template EdgeMap<bool> m(G);
188 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
189 //Inicialize with default value
190 typename Graph::template EdgeMap<bool> mdef(G,12);
191 typename Graph::template EdgeMap<bool> mm(cm); //Copy
192 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
194 v=m[k]; m[k]=v; m.set(k,v);
198 dm=cm; //Copy from another type
199 m=dm; //Copy to another type
201 //Check the typedef's
202 typename Graph::template EdgeMap<bool>::ValueType val;
204 typename Graph::template EdgeMap<bool>::KeyType key;
205 key= typename Graph::EdgeIt(G);
210 template<class Graph> void checkCompileGraph(Graph &G)
212 checkCompileStaticGraph(G);
214 typedef typename Graph::Node Node;
215 typedef typename Graph::NodeIt NodeIt;
216 typedef typename Graph::Edge Edge;
217 typedef typename Graph::EdgeIt EdgeIt;
218 typedef typename Graph::InEdgeIt InEdgeIt;
219 typedef typename Graph::OutEdgeIt OutEdgeIt;
230 template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
232 typename Graph::Edge e;
236 template<class Graph> void checkCompileGraphEraseNode(Graph &G)
238 typename Graph::Node n;
242 template<class Graph> void checkCompileErasableGraph(Graph &G)
244 checkCompileGraph(G);
245 checkCompileGraphEraseNode(G);
246 checkCompileGraphEraseEdge(G);
249 template<class Graph> void checkCompileGraphFindEdge(Graph &G)
251 typedef typename Graph::NodeIt Node;
252 typedef typename Graph::NodeIt NodeIt;
254 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
255 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
258 template<class Graph> void checkGraphNodeList(Graph &G, int nn)
260 typename Graph::NodeIt n(G);
261 for(int i=0;i<nn;i++) {
262 check(n!=INVALID,"Wrong Node list linking.");
265 check(n==INVALID,"Wrong Node list linking.");
268 template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
270 typedef typename Graph::EdgeIt EdgeIt;
273 for(int i=0;i<nn;i++) {
274 check(e!=INVALID,"Wrong Edge list linking.");
277 check(e==INVALID,"Wrong Edge list linking.");
280 template<class Graph> void checkGraphOutEdgeList(Graph &G,
281 typename Graph::Node n,
284 typename Graph::OutEdgeIt e(G,n);
285 for(int i=0;i<nn;i++) {
286 check(e!=INVALID,"Wrong OutEdge list linking.");
289 check(e==INVALID,"Wrong OutEdge list linking.");
292 template<class Graph> void checkGraphInEdgeList(Graph &G,
293 typename Graph::Node n,
296 typename Graph::InEdgeIt e(G,n);
297 for(int i=0;i<nn;i++) {
298 check(e!=INVALID,"Wrong InEdge list linking.");
301 check(e==INVALID,"Wrong InEdge list linking.");
305 ///\todo Check head(), tail() as well;