2 #include<hugo/smart_graph.h>
3 #include<hugo/skeletons/graph.h>
4 #include<hugo/list_graph.h>
5 #include<hugo/full_graph.h>
11 This test makes consistency checks of list graph structures.
13 G.addNode(), G.addEdge(), G.tail(), G.head()
15 \todo Checks for empty graphs and isolated points.
16 \todo Checks for Node->NodeIt, Edge->{EdgeIt,InEdgeIt,OutEdgeIt}
22 template<class Graph> void checkCompileStaticGraph(Graph &G)
24 typedef typename Graph::Node Node;
25 typedef typename Graph::NodeIt NodeIt;
26 typedef typename Graph::Edge Edge;
27 typedef typename Graph::EdgeIt EdgeIt;
28 typedef typename Graph::InEdgeIt InEdgeIt;
29 typedef typename Graph::OutEdgeIt OutEdgeIt;
32 Node i; Node j(i); Node k(INVALID);
34 // bool b=G.valid(i); b=b;
36 b=(i==INVALID); b=(i!=INVALID);
37 b=(i==j); b=(i!=j); b=(i<j);
40 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
44 // bool b=G.valid(i); b=b;
46 b=(i==INVALID); b=(i!=INVALID);
49 b=(i==j); b=(i!=j); b=(i<j);
50 //Node ->NodeIt conversion
54 Edge i; Edge j(i); Edge k(INVALID);
56 // bool b=G.valid(i); b=b;
58 b=(i==INVALID); b=(i!=INVALID);
59 b=(i==j); b=(i!=j); b=(i<j);
62 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
66 // bool b=G.valid(i); b=b;
68 b=(i==INVALID); b=(i!=INVALID);
71 b=(i==j); b=(i!=j); b=(i<j);
72 //Edge ->EdgeIt conversion
77 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
81 // bool b=G.valid(i); b=b;
83 b=(i==INVALID); b=(i!=INVALID);
86 b=(i==j); b=(i!=j); b=(i<j);
87 //Edge ->InEdgeIt conversion
92 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
96 // bool b=G.valid(i); b=b;
98 b=(i==INVALID); b=(i!=INVALID);
101 b=(i==j); b=(i!=j); b=(i<j);
102 //Edge ->OutEdgeIt conversion
114 { Node n; int i=G.id(n); i=i; }
115 { Edge e; int i=G.id(e); i=i; }
119 typename Graph::template NodeMap<int> m(G);
121 typename Graph::template NodeMap<int> const &cm = m;
122 //Inicialize with default value
123 typename Graph::template NodeMap<int> mdef(G,12);
125 typename Graph::template NodeMap<int> mm(cm);
126 //Copy from another type
127 typename Graph::template NodeMap<double> dm(cm);
129 v=m[k]; m[k]=v; m.set(k,v);
133 dm=cm; //Copy from another type
135 //Check the typedef's
136 typename Graph::template NodeMap<int>::ValueType val;
138 typename Graph::template NodeMap<int>::KeyType key;
139 key = typename Graph::NodeIt(G);
144 typename Graph::template NodeMap<bool> m(G);
145 typename Graph::template NodeMap<bool> const &cm = m; //Const map
146 //Inicialize with default value
147 typename Graph::template NodeMap<bool> mdef(G,12);
148 typename Graph::template NodeMap<bool> mm(cm); //Copy
149 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
151 v=m[k]; m[k]=v; m.set(k,v);
155 dm=cm; //Copy from another type
156 m=dm; //Copy to another type
159 //Check the typedef's
160 typename Graph::template NodeMap<bool>::ValueType val;
162 typename Graph::template NodeMap<bool>::KeyType key;
163 key= typename Graph::NodeIt(G);
169 typename Graph::template EdgeMap<int> m(G);
170 typename Graph::template EdgeMap<int> const &cm = m; //Const map
171 //Inicialize with default value
172 typename Graph::template EdgeMap<int> mdef(G,12);
173 typename Graph::template EdgeMap<int> mm(cm); //Copy
174 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
176 v=m[k]; m[k]=v; m.set(k,v);
180 dm=cm; //Copy from another type
182 //Check the typedef's
183 typename Graph::template EdgeMap<int>::ValueType val;
185 typename Graph::template EdgeMap<int>::KeyType key;
186 key= typename Graph::EdgeIt(G);
191 typename Graph::template EdgeMap<bool> m(G);
192 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
193 //Inicialize with default value
194 typename Graph::template EdgeMap<bool> mdef(G,12);
195 typename Graph::template EdgeMap<bool> mm(cm); //Copy
196 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
198 v=m[k]; m[k]=v; m.set(k,v);
202 dm=cm; //Copy from another type
203 m=dm; //Copy to another type
205 //Check the typedef's
206 typename Graph::template EdgeMap<bool>::ValueType val;
208 typename Graph::template EdgeMap<bool>::KeyType key;
209 key= typename Graph::EdgeIt(G);
214 template<class Graph> void checkCompile(Graph &G)
216 checkCompileStaticGraph(G);
218 typedef typename Graph::Node Node;
219 typedef typename Graph::NodeIt NodeIt;
220 typedef typename Graph::Edge Edge;
221 typedef typename Graph::EdgeIt EdgeIt;
222 typedef typename Graph::InEdgeIt InEdgeIt;
223 typedef typename Graph::OutEdgeIt OutEdgeIt;
234 template<class Graph> void checkCompileErase(Graph &G)
236 typedef typename Graph::Node Node;
237 typedef typename Graph::Edge Edge;
244 template<class Graph> void checkCompileEraseEdge(Graph &G)
246 typedef typename Graph::Edge Edge;
251 template<class Graph> void checkCompileFindEdge(Graph &G)
253 typedef typename Graph::NodeIt Node;
254 typedef typename Graph::NodeIt NodeIt;
256 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
257 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
261 template<class Graph> void checkNodeList(Graph &G, int nn)
263 typename Graph::NodeIt n(G);
264 for(int i=0;i<nn;i++) {
265 check(n!=INVALID,"Wrong Node list linking.");
268 check(n==INVALID,"Wrong Node list linking.");
271 template<class Graph> void checkEdgeList(Graph &G, int nn)
273 typedef typename Graph::EdgeIt EdgeIt;
276 for(int i=0;i<nn;i++) {
277 check(e!=INVALID,"Wrong Edge list linking.");
280 check(e==INVALID,"Wrong Edge list linking.");
283 template<class Graph> void checkOutEdgeList(Graph &G,
284 typename Graph::Node n,
287 typename Graph::OutEdgeIt e(G,n);
288 for(int i=0;i<nn;i++) {
289 check(e!=INVALID,"Wrong OutEdge list linking.");
292 check(e==INVALID,"Wrong OutEdge list linking.");
295 template<class Graph> void checkInEdgeList(Graph &G,
296 typename Graph::Node n,
299 typename Graph::InEdgeIt e(G,n);
300 for(int i=0;i<nn;i++) {
301 check(e!=INVALID,"Wrong InEdge list linking.");
304 check(e==INVALID,"Wrong InEdge list linking.");
308 ///\todo Checks head(), tail() as well;
310 template<class Graph> void bidirPetersen(Graph &G)
312 typedef typename Graph::Edge Edge;
313 typedef typename Graph::EdgeIt EdgeIt;
317 std::vector<Edge> ee;
319 for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
321 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
322 G.addEdge(G.head(*p),G.tail(*p));
325 template<class Graph> void checkPetersen(Graph &G)
327 typedef typename Graph::Node Node;
329 typedef typename Graph::EdgeIt EdgeIt;
330 typedef typename Graph::NodeIt NodeIt;
335 for(NodeIt n(G);n!=INVALID;++n) {
336 checkInEdgeList(G,n,3);
337 checkOutEdgeList(G,n,3);
342 //Compile GraphSkeleton
343 template void checkCompileStaticGraph<skeleton::StaticGraphSkeleton>
344 (skeleton::StaticGraphSkeleton &);
346 template void checkCompile<skeleton::GraphSkeleton>(skeleton::GraphSkeleton &);
348 template void checkCompileErase<skeleton::EraseableGraphSkeleton>
349 (skeleton::EraseableGraphSkeleton &);
352 template void checkCompile<SmartGraph>(SmartGraph &);
354 //Compile SymSmartGraph
355 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
358 template void checkCompile<ListGraph>(ListGraph &);
359 template void checkCompileErase<ListGraph>(ListGraph &);
360 template void checkCompileFindEdge<ListGraph>(ListGraph &);
363 //Compile SymListGraph
364 template void checkCompile<SymListGraph>(SymListGraph &);
365 template void checkCompileErase<SymListGraph>(SymListGraph &);
366 template void checkCompileFindEdge<SymListGraph>(SymListGraph &);
369 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
370 template void checkCompileFindEdge<FullGraph>(FullGraph &);
372 //Compile EdgeSet <ListGraph>
373 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
375 void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
377 void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
379 //Compile EdgeSet <NodeSet>
380 template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
382 void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
383 template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
413 ///\todo copy constr tests.
415 std::cout << __FILE__ ": All tests passed.\n";