Changes in doc. (New module name for array/vector maps added.)
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
138 typename Graph::template NodeMap<bool> m(G);
139 typename Graph::template NodeMap<bool> const &cm = m; //Const map
140 //Inicialize with default value
141 typename Graph::template NodeMap<bool> mdef(G,12);
142 typename Graph::template NodeMap<bool> mm(cm); //Copy
143 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
145 v=m[k]; m[k]=v; m.set(k,v);
149 dm=cm; //Copy from another type
150 m=dm; //Copy to another type
155 typename Graph::template EdgeMap<int> m(G);
156 typename Graph::template EdgeMap<int> const &cm = m; //Const map
157 //Inicialize with default value
158 typename Graph::template EdgeMap<int> mdef(G,12);
159 typename Graph::template EdgeMap<int> mm(cm); //Copy
160 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
162 v=m[k]; m[k]=v; m.set(k,v);
166 dm=cm; //Copy from another type
170 typename Graph::template EdgeMap<bool> m(G);
171 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
172 //Inicialize with default value
173 typename Graph::template EdgeMap<bool> mdef(G,12);
174 typename Graph::template EdgeMap<bool> mm(cm); //Copy
175 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
177 v=m[k]; m[k]=v; m.set(k,v);
181 dm=cm; //Copy from another type
182 m=dm; //Copy to another type
186 template<class Graph> void checkCompile(Graph &G)
188 checkCompileStaticGraph(G);
190 typedef typename Graph::Node Node;
191 typedef typename Graph::NodeIt NodeIt;
192 typedef typename Graph::Edge Edge;
193 typedef typename Graph::EdgeIt EdgeIt;
194 typedef typename Graph::InEdgeIt InEdgeIt;
195 typedef typename Graph::OutEdgeIt OutEdgeIt;
206 template<class Graph> void checkCompileErase(Graph &G)
208 typedef typename Graph::Node Node;
209 typedef typename Graph::Edge Edge;
216 template<class Graph> void checkCompileEraseEdge(Graph &G)
218 typedef typename Graph::Edge Edge;
223 template<class Graph> void checkCompileFindEdge(Graph &G)
225 typedef typename Graph::NodeIt Node;
226 typedef typename Graph::NodeIt NodeIt;
228 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
229 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
233 template<class Graph> void checkNodeList(Graph &G, int nn)
235 typename Graph::NodeIt n(G);
236 for(int i=0;i<nn;i++) {
237 check(n!=INVALID,"Wrong Node list linking.");
240 check(n==INVALID,"Wrong Node list linking.");
243 template<class Graph> void checkEdgeList(Graph &G, int nn)
245 typedef typename Graph::EdgeIt EdgeIt;
248 for(int i=0;i<nn;i++) {
249 check(e!=INVALID,"Wrong Edge list linking.");
252 check(e==INVALID,"Wrong Edge list linking.");
255 template<class Graph> void checkOutEdgeList(Graph &G,
256 typename Graph::Node n,
259 typename Graph::OutEdgeIt e(G,n);
260 for(int i=0;i<nn;i++) {
261 check(e!=INVALID,"Wrong OutEdge list linking.");
264 check(e==INVALID,"Wrong OutEdge list linking.");
267 template<class Graph> void checkInEdgeList(Graph &G,
268 typename Graph::Node n,
271 typename Graph::InEdgeIt e(G,n);
272 for(int i=0;i<nn;i++) {
273 check(e!=INVALID,"Wrong InEdge list linking.");
276 check(e==INVALID,"Wrong InEdge list linking.");
280 ///\todo Checks head(), tail() as well;
282 template<class Graph> void bidirPetersen(Graph &G)
284 typedef typename Graph::Edge Edge;
285 typedef typename Graph::EdgeIt EdgeIt;
289 std::vector<Edge> ee;
291 for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
293 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
294 G.addEdge(G.head(*p),G.tail(*p));
297 template<class Graph> void checkPetersen(Graph &G)
299 typedef typename Graph::Node Node;
301 typedef typename Graph::EdgeIt EdgeIt;
302 typedef typename Graph::NodeIt NodeIt;
307 for(NodeIt n(G);n!=INVALID;++n) {
308 checkInEdgeList(G,n,3);
309 checkOutEdgeList(G,n,3);
314 //Compile GraphSkeleton
316 void checkCompileStaticGraph<StaticGraphSkeleton>(StaticGraphSkeleton &);
317 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
319 void checkCompileErase<EraseableGraphSkeleton>(EraseableGraphSkeleton &);
322 template void checkCompile<SmartGraph>(SmartGraph &);
324 //Compile SymSmartGraph
325 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
328 template void checkCompile<ListGraph>(ListGraph &);
329 template void checkCompileErase<ListGraph>(ListGraph &);
330 template void checkCompileFindEdge<ListGraph>(ListGraph &);
333 //Compile SymListGraph
334 template void checkCompile<SymListGraph>(SymListGraph &);
335 template void checkCompileErase<SymListGraph>(SymListGraph &);
336 template void checkCompileFindEdge<SymListGraph>(SymListGraph &);
339 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
340 template void checkCompileFindEdge<FullGraph>(FullGraph &);
342 //Compile EdgeSet <ListGraph>
343 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
345 void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
347 void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
349 //Compile EdgeSet <NodeSet>
350 template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
352 void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
353 template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
383 ///\todo copy constr tests.
385 std::cout << __FILE__ ": All tests passed.\n";