Tests for the existence of 'KeyType' and 'ValueType' in the graph maps.
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}
21 using namespace hugo::skeleton;
23 template<class Graph> void checkCompileStaticGraph(Graph &G)
25 typedef typename Graph::Node Node;
26 typedef typename Graph::NodeIt NodeIt;
27 typedef typename Graph::Edge Edge;
28 typedef typename Graph::EdgeIt EdgeIt;
29 typedef typename Graph::InEdgeIt InEdgeIt;
30 typedef typename Graph::OutEdgeIt OutEdgeIt;
33 Node i; Node j(i); Node k(INVALID);
35 // bool b=G.valid(i); b=b;
37 b=(i==INVALID); b=(i!=INVALID);
38 b=(i==j); b=(i!=j); b=(i<j);
41 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
45 // bool b=G.valid(i); b=b;
47 b=(i==INVALID); b=(i!=INVALID);
50 b=(i==j); b=(i!=j); b=(i<j);
51 //Node ->NodeIt conversion
55 Edge i; Edge j(i); Edge k(INVALID);
57 // bool b=G.valid(i); b=b;
59 b=(i==INVALID); b=(i!=INVALID);
60 b=(i==j); b=(i!=j); b=(i<j);
63 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
67 // bool b=G.valid(i); b=b;
69 b=(i==INVALID); b=(i!=INVALID);
72 b=(i==j); b=(i!=j); b=(i<j);
73 //Edge ->EdgeIt conversion
78 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
82 // bool b=G.valid(i); b=b;
84 b=(i==INVALID); b=(i!=INVALID);
87 b=(i==j); b=(i!=j); b=(i<j);
88 //Edge ->InEdgeIt conversion
93 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
97 // bool b=G.valid(i); b=b;
99 b=(i==INVALID); b=(i!=INVALID);
102 b=(i==j); b=(i!=j); b=(i<j);
103 //Edge ->OutEdgeIt conversion
115 { Node n; int i=G.id(n); i=i; }
116 { Edge e; int i=G.id(e); i=i; }
120 typename Graph::template NodeMap<int> m(G);
122 typename Graph::template NodeMap<int> const &cm = m;
123 //Inicialize with default value
124 typename Graph::template NodeMap<int> mdef(G,12);
126 typename Graph::template NodeMap<int> mm(cm);
127 //Copy from another type
128 typename Graph::template NodeMap<double> dm(cm);
130 v=m[k]; m[k]=v; m.set(k,v);
134 dm=cm; //Copy from another type
136 //Check the typedef's
137 typename Graph::template NodeMap<int>::ValueType val;
139 typename Graph::template NodeMap<int>::KeyType key;
140 key = typename Graph::NodeIt(G);
145 typename Graph::template NodeMap<bool> m(G);
146 typename Graph::template NodeMap<bool> const &cm = m; //Const map
147 //Inicialize with default value
148 typename Graph::template NodeMap<bool> mdef(G,12);
149 typename Graph::template NodeMap<bool> mm(cm); //Copy
150 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
152 v=m[k]; m[k]=v; m.set(k,v);
156 dm=cm; //Copy from another type
157 m=dm; //Copy to another type
160 //Check the typedef's
161 typename Graph::template NodeMap<bool>::ValueType val;
163 typename Graph::template NodeMap<bool>::KeyType key;
164 key= typename Graph::NodeIt(G);
170 typename Graph::template EdgeMap<int> m(G);
171 typename Graph::template EdgeMap<int> const &cm = m; //Const map
172 //Inicialize with default value
173 typename Graph::template EdgeMap<int> mdef(G,12);
174 typename Graph::template EdgeMap<int> mm(cm); //Copy
175 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
177 v=m[k]; m[k]=v; m.set(k,v);
181 dm=cm; //Copy from another type
183 //Check the typedef's
184 typename Graph::template EdgeMap<int>::ValueType val;
186 typename Graph::template EdgeMap<int>::KeyType key;
187 key= typename Graph::EdgeIt(G);
192 typename Graph::template EdgeMap<bool> m(G);
193 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
194 //Inicialize with default value
195 typename Graph::template EdgeMap<bool> mdef(G,12);
196 typename Graph::template EdgeMap<bool> mm(cm); //Copy
197 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
199 v=m[k]; m[k]=v; m.set(k,v);
203 dm=cm; //Copy from another type
204 m=dm; //Copy to another type
206 //Check the typedef's
207 typename Graph::template EdgeMap<bool>::ValueType val;
209 typename Graph::template EdgeMap<bool>::KeyType key;
210 key= typename Graph::EdgeIt(G);
215 template<class Graph> void checkCompile(Graph &G)
217 checkCompileStaticGraph(G);
219 typedef typename Graph::Node Node;
220 typedef typename Graph::NodeIt NodeIt;
221 typedef typename Graph::Edge Edge;
222 typedef typename Graph::EdgeIt EdgeIt;
223 typedef typename Graph::InEdgeIt InEdgeIt;
224 typedef typename Graph::OutEdgeIt OutEdgeIt;
235 template<class Graph> void checkCompileErase(Graph &G)
237 typedef typename Graph::Node Node;
238 typedef typename Graph::Edge Edge;
245 template<class Graph> void checkCompileEraseEdge(Graph &G)
247 typedef typename Graph::Edge Edge;
252 template<class Graph> void checkCompileFindEdge(Graph &G)
254 typedef typename Graph::NodeIt Node;
255 typedef typename Graph::NodeIt NodeIt;
257 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
258 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
262 template<class Graph> void checkNodeList(Graph &G, int nn)
264 typename Graph::NodeIt n(G);
265 for(int i=0;i<nn;i++) {
266 check(n!=INVALID,"Wrong Node list linking.");
269 check(n==INVALID,"Wrong Node list linking.");
272 template<class Graph> void checkEdgeList(Graph &G, int nn)
274 typedef typename Graph::EdgeIt EdgeIt;
277 for(int i=0;i<nn;i++) {
278 check(e!=INVALID,"Wrong Edge list linking.");
281 check(e==INVALID,"Wrong Edge list linking.");
284 template<class Graph> void checkOutEdgeList(Graph &G,
285 typename Graph::Node n,
288 typename Graph::OutEdgeIt e(G,n);
289 for(int i=0;i<nn;i++) {
290 check(e!=INVALID,"Wrong OutEdge list linking.");
293 check(e==INVALID,"Wrong OutEdge list linking.");
296 template<class Graph> void checkInEdgeList(Graph &G,
297 typename Graph::Node n,
300 typename Graph::InEdgeIt e(G,n);
301 for(int i=0;i<nn;i++) {
302 check(e!=INVALID,"Wrong InEdge list linking.");
305 check(e==INVALID,"Wrong InEdge list linking.");
309 ///\todo Checks head(), tail() as well;
311 template<class Graph> void bidirPetersen(Graph &G)
313 typedef typename Graph::Edge Edge;
314 typedef typename Graph::EdgeIt EdgeIt;
318 std::vector<Edge> ee;
320 for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
322 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
323 G.addEdge(G.head(*p),G.tail(*p));
326 template<class Graph> void checkPetersen(Graph &G)
328 typedef typename Graph::Node Node;
330 typedef typename Graph::EdgeIt EdgeIt;
331 typedef typename Graph::NodeIt NodeIt;
336 for(NodeIt n(G);n!=INVALID;++n) {
337 checkInEdgeList(G,n,3);
338 checkOutEdgeList(G,n,3);
343 //Compile GraphSkeleton
345 void checkCompileStaticGraph<StaticGraphSkeleton>(StaticGraphSkeleton &);
346 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
348 void checkCompileErase<EraseableGraphSkeleton>(EraseableGraphSkeleton &);
351 template void checkCompile<SmartGraph>(SmartGraph &);
353 //Compile SymSmartGraph
354 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
357 template void checkCompile<ListGraph>(ListGraph &);
358 template void checkCompileErase<ListGraph>(ListGraph &);
359 template void checkCompileFindEdge<ListGraph>(ListGraph &);
362 //Compile SymListGraph
363 template void checkCompile<SymListGraph>(SymListGraph &);
364 template void checkCompileErase<SymListGraph>(SymListGraph &);
365 template void checkCompileFindEdge<SymListGraph>(SymListGraph &);
368 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
369 template void checkCompileFindEdge<FullGraph>(FullGraph &);
371 //Compile EdgeSet <ListGraph>
372 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
374 void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
376 void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
378 //Compile EdgeSet <NodeSet>
379 template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
381 void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
382 template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
412 ///\todo copy constr tests.
414 std::cout << __FILE__ ": All tests passed.\n";