NodeSubGraphWrapper, test, and ducumentation modifications.
2 * src/test/graph_test.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
16 #ifndef LEMON_TEST_GRAPH_TEST_H
17 #define LEMON_TEST_GRAPH_TEST_H
20 #include "test_tools.h"
24 //! \brief Some utility to test graph classes.
30 DummyType(int p) : value(p) {}
31 DummyType& operator=(int p) { value = p; return *this;}
35 template<class Graph> void checkCompileStaticGraph(Graph &G)
37 typedef typename Graph::Node Node;
38 typedef typename Graph::NodeIt NodeIt;
39 typedef typename Graph::Edge Edge;
40 typedef typename Graph::EdgeIt EdgeIt;
41 typedef typename Graph::InEdgeIt InEdgeIt;
42 typedef typename Graph::OutEdgeIt OutEdgeIt;
45 Node i; Node j(i); Node k(INVALID);
48 b=(i==INVALID); b=(i!=INVALID);
49 b=(i==j); b=(i!=j); b=(i<j);
52 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
57 b=(i==INVALID); b=(i!=INVALID);
60 b=(i==j); b=(i!=j); b=(i<j);
61 //Node ->NodeIt conversion
65 Edge i; Edge j(i); Edge k(INVALID);
68 b=(i==INVALID); b=(i!=INVALID);
69 b=(i==j); b=(i!=j); b=(i<j);
72 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
77 b=(i==INVALID); b=(i!=INVALID);
80 b=(i==j); b=(i!=j); b=(i<j);
81 //Edge ->EdgeIt conversion
86 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
91 b=(i==INVALID); b=(i!=INVALID);
94 b=(i==j); b=(i!=j); b=(i<j);
95 //Edge ->InEdgeIt conversion
100 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
105 b=(i==INVALID); b=(i!=INVALID);
108 b=(i==j); b=(i!=j); b=(i<j);
109 //Edge ->OutEdgeIt conversion
121 { Node n; int i=G.id(n); i=i; }
122 { Edge e; int i=G.id(e); i=i; }
126 typename Graph::template NodeMap<int> m(G);
128 typename Graph::template NodeMap<int> const &cm = m;
129 //Inicialize with default value
130 typename Graph::template NodeMap<int> mdef(G,12);
132 typename Graph::template NodeMap<int> mm(cm);
133 //Copy from another type
134 typename Graph::template NodeMap<double> dm(cm);
135 //Copy to more complex type
136 typename Graph::template NodeMap<DummyType> em(cm);
138 v=m[k]; m[k]=v; m.set(k,v);
142 dm=cm; //Copy from another type
143 em=cm; //Copy to more complex type
145 //Check the typedef's
146 typename Graph::template NodeMap<int>::ValueType val;
148 typename Graph::template NodeMap<int>::KeyType key;
149 key = typename Graph::NodeIt(G);
154 typename Graph::template NodeMap<bool> m(G);
155 typename Graph::template NodeMap<bool> const &cm = m; //Const map
156 //Inicialize with default value
157 typename Graph::template NodeMap<bool> mdef(G,12);
158 typename Graph::template NodeMap<bool> mm(cm); //Copy
159 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
161 v=m[k]; m[k]=v; m.set(k,v);
165 dm=cm; //Copy from another type
166 m=dm; //Copy to another type
169 //Check the typedef's
170 typename Graph::template NodeMap<bool>::ValueType val;
172 typename Graph::template NodeMap<bool>::KeyType key;
173 key= typename Graph::NodeIt(G);
179 typename Graph::template EdgeMap<int> m(G);
180 typename Graph::template EdgeMap<int> const &cm = m; //Const map
181 //Inicialize with default value
182 typename Graph::template EdgeMap<int> mdef(G,12);
183 typename Graph::template EdgeMap<int> mm(cm); //Copy
184 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
186 v=m[k]; m[k]=v; m.set(k,v);
190 dm=cm; //Copy from another type
192 //Check the typedef's
193 typename Graph::template EdgeMap<int>::ValueType val;
195 typename Graph::template EdgeMap<int>::KeyType key;
196 key= typename Graph::EdgeIt(G);
201 typename Graph::template EdgeMap<bool> m(G);
202 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
203 //Inicialize with default value
204 typename Graph::template EdgeMap<bool> mdef(G,12);
205 typename Graph::template EdgeMap<bool> mm(cm); //Copy
206 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
208 v=m[k]; m[k]=v; m.set(k,v);
212 dm=cm; //Copy from another type
213 m=dm; //Copy to another type
215 //Check the typedef's
216 typename Graph::template EdgeMap<bool>::ValueType val;
218 typename Graph::template EdgeMap<bool>::KeyType key;
219 key= typename Graph::EdgeIt(G);
224 template<class Graph> void checkCompileGraph(Graph &G)
226 checkCompileStaticGraph(G);
228 typedef typename Graph::Node Node;
229 typedef typename Graph::NodeIt NodeIt;
230 typedef typename Graph::Edge Edge;
231 typedef typename Graph::EdgeIt EdgeIt;
232 typedef typename Graph::InEdgeIt InEdgeIt;
233 typedef typename Graph::OutEdgeIt OutEdgeIt;
244 template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
246 typename Graph::Edge e;
250 template<class Graph> void checkCompileGraphEraseNode(Graph &G)
252 typename Graph::Node n;
256 template<class Graph> void checkCompileErasableGraph(Graph &G)
258 checkCompileGraph(G);
259 checkCompileGraphEraseNode(G);
260 checkCompileGraphEraseEdge(G);
263 template<class Graph> void checkCompileGraphFindEdge(Graph &G)
265 typedef typename Graph::NodeIt Node;
266 typedef typename Graph::NodeIt NodeIt;
268 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
269 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
272 template<class Graph> void checkGraphNodeList(Graph &G, int nn)
274 typename Graph::NodeIt n(G);
275 for(int i=0;i<nn;i++) {
276 check(n!=INVALID,"Wrong Node list linking.");
279 check(n==INVALID,"Wrong Node list linking.");
282 template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
284 typedef typename Graph::EdgeIt EdgeIt;
287 for(int i=0;i<nn;i++) {
288 check(e!=INVALID,"Wrong Edge list linking.");
291 check(e==INVALID,"Wrong Edge list linking.");
294 template<class Graph> void checkGraphOutEdgeList(Graph &G,
295 typename Graph::Node n,
298 typename Graph::OutEdgeIt e(G,n);
299 for(int i=0;i<nn;i++) {
300 check(e!=INVALID,"Wrong OutEdge list linking.");
303 check(e==INVALID,"Wrong OutEdge list linking.");
306 template<class Graph> void checkGraphInEdgeList(Graph &G,
307 typename Graph::Node n,
310 typename Graph::InEdgeIt e(G,n);
311 for(int i=0;i<nn;i++) {
312 check(e!=INVALID,"Wrong InEdge list linking.");
315 check(e==INVALID,"Wrong InEdge list linking.");
319 ///\todo Check head(), tail() as well;