Some tests must have been commented out temporarily.
2 #include<hugo/smart_graph.h>
3 //#include<hugo/skeletons/graph.h>
4 //#include<../work/alpar/list_graph.h>
7 This test makes consistency checks of list graph structures.
9 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
15 // void check(bool rc, const char *msg) {
17 // std::cerr << msg << std::endl;
22 #define check(rc, msg) \
24 std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
29 template<class Graph> void checkCompile(Graph &G)
31 typedef typename Graph::Node Node;
32 typedef typename Graph::NodeIt NodeIt;
33 typedef typename Graph::Edge Edge;
34 typedef typename Graph::EdgeIt EdgeIt;
35 typedef typename Graph::InEdgeIt InEdgeIt;
36 typedef typename Graph::OutEdgeIt OutEdgeIt;
39 Node i; Node j(i); Node k(INVALID);
41 bool b=G.valid(i); b=b;
42 b=(i==j); b=(i!=j); b=(i<j);
45 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
49 bool b=G.valid(i); b=b;
52 b=(i==j); b=(i!=j); b=(i<j);
55 Edge i; Edge j(i); Edge k(INVALID);
57 bool b=G.valid(i); b=b;
58 b=(i==j); b=(i!=j); b=(i<j);
61 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
65 bool b=G.valid(i); b=b;
68 b=(i==j); b=(i!=j); b=(i<j);
72 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
76 bool b=G.valid(i); b=b;
79 b=(i==j); b=(i!=j); b=(i<j);
83 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
87 bool b=G.valid(i); b=b;
90 b=(i==j); b=(i!=j); b=(i<j);
103 { int i=G.id(n); i=i; }
104 { int i=G.id(e); i=i; }
111 typename Graph::template NodeMap<int> m(G);
112 typename Graph::template NodeMap<int> const &cm = m; //Const map
113 //Inicialize with default value
114 typename Graph::template NodeMap<int> mdef(G,12);
115 typename Graph::template NodeMap<int> mm(cm); //Copy
116 typename Graph::template NodeMap<double> dm(cm); //Copy from another type
118 v=m[k]; m[k]=v; m.set(k,v);
122 dm=cm; //Copy from another type
126 typename Graph::template NodeMap<bool> m(G);
127 typename Graph::template NodeMap<bool> const &cm = m; //Const map
128 //Inicialize with default value
129 typename Graph::template NodeMap<bool> mdef(G,12);
130 typename Graph::template NodeMap<bool> mm(cm); //Copy
131 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
133 v=m[k]; m[k]=v; m.set(k,v);
137 dm=cm; //Copy from another type
138 m=dm; //Copy to another type
143 typename Graph::template EdgeMap<int> m(G);
144 typename Graph::template EdgeMap<int> const &cm = m; //Const map
145 //Inicialize with default value
146 typename Graph::template EdgeMap<int> mdef(G,12);
147 typename Graph::template EdgeMap<int> mm(cm); //Copy
148 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
150 v=m[k]; m[k]=v; m.set(k,v);
154 dm=cm; //Copy from another type
158 typename Graph::template EdgeMap<bool> m(G);
159 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
160 //Inicialize with default value
161 typename Graph::template EdgeMap<bool> mdef(G,12);
162 typename Graph::template EdgeMap<bool> mm(cm); //Copy
163 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
165 v=m[k]; m[k]=v; m.set(k,v);
169 dm=cm; //Copy from another type
170 m=dm; //Copy to another type
177 template<class Graph> void addPetersen(Graph &G)
179 std::vector<typename Graph::Node> outer, inner;
181 for(int i=0;i<5;i++) {
182 outer.push_back(G.addNode());
183 inner.push_back(G.addNode());
186 for(int i=0;i<5;i++) {
187 G.addEdge(outer[i],inner[i]);
188 G.addEdge(outer[i],outer[(i+1)%5]);
189 G.addEdge(inner[i],inner[(i+2)%5]);
193 template<class Graph> void checkNodeList(Graph &G, int nn)
195 typename Graph::NodeIt n(G);
196 for(int i=0;i<nn;i++) {
197 check(G.valid(n),"Wrong Node list linking.");
200 check(!G.valid(n),"Wrong Node list linking.");
203 template<class Graph> void checkEdgeList(Graph &G, int nn)
205 typedef typename Graph::EdgeIt EdgeIt;
208 for(int i=0;i<nn;i++) {
209 check(G.valid(e),"Wrong Edge list linking.");
212 check(!G.valid(e),"Wrong Edge list linking.");
215 template<class Graph> void checkOutEdgeList(Graph &G,
216 typename Graph::Node n,
219 typename Graph::OutEdgeIt e(G,n);
220 for(int i=0;i<nn;i++) {
221 check(G.valid(e),"Wrong OutEdge list linking.");
224 check(!G.valid(e),"Wrong OutEdge list linking.");
227 template<class Graph> void checkInEdgeList(Graph &G,
228 typename Graph::Node n,
231 typename Graph::InEdgeIt e(G,n);
232 for(int i=0;i<nn;i++) {
233 check(G.valid(e),"Wrong InEdge list linking.");
236 check(!G.valid(e),"Wrong InEdge list linking.");
239 //Checks head(), tail() as well;
240 template<class Graph> void bidirPetersen(Graph &G)
242 typedef typename Graph::Edge Edge;
243 typedef typename Graph::EdgeIt EdgeIt;
247 std::vector<Edge> ee;
249 for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
251 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
252 G.addEdge(G.head(*p),G.tail(*p));
255 template<class Graph> void checkPetersen(Graph &G)
257 typedef typename Graph::Node Node;
259 typedef typename Graph::EdgeIt EdgeIt;
260 typedef typename Graph::NodeIt NodeIt;
265 for(NodeIt n(G);G.valid(n);G.next(n)) {
266 checkInEdgeList(G,n,3);
267 checkOutEdgeList(G,n,3);
272 //template void checkCompile<GraphSkeleton>(GraphSkeleton &);
273 template void checkCompile<SmartGraph>(SmartGraph &);
274 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
275 //template void checkCompile<ListGraph>(ListGraph &);
276 //template void checkCompile<SymListGraph>(SymListGraph &);
278 //Due to some mysterious and some conceptual problems it does not work.
279 //template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
307 //\todo copy constr tests.
309 std::cout << __FILE__ ": All tests passed.\n";