test/graph_test.cc added.
It discovered several bugs and warnings in 'include/smart_graph.h',
in 'include/skeletons/graph.h' and in 'work/alpar/list_graph.h'.
They have also been fixed.
2 #include<smart_graph.h>
3 #include<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::NodeMap<int> m(G);
112 typename Graph::NodeMap<int> const &cm = m; //Const map
113 typename Graph::NodeMap<int> mdef(G,12); //Inicialize with default value
114 typename Graph::NodeMap<int> mm(cm); //Copy
115 typename Graph::NodeMap<double> dm(cm); //Copy from another type
117 v=m[k]; m[k]=v; m.set(k,v);
121 dm=cm; //Copy from another type
125 typename Graph::NodeMap<bool> m(G);
126 typename Graph::NodeMap<bool> const &cm = m; //Const map
127 typename Graph::NodeMap<bool> mdef(G,12); //Inicialize with default value
128 typename Graph::NodeMap<bool> mm(cm); //Copy
129 typename Graph::NodeMap<int> dm(cm); //Copy from another type
131 v=m[k]; m[k]=v; m.set(k,v);
135 dm=cm; //Copy from another type
140 typename Graph::EdgeMap<int> m(G);
141 typename Graph::EdgeMap<int> const &cm = m; //Const map
142 typename Graph::EdgeMap<int> mdef(G,12); //Inicialize with default value
143 typename Graph::EdgeMap<int> mm(cm); //Copy
144 typename Graph::EdgeMap<double> dm(cm); //Copy from another type
146 v=m[k]; m[k]=v; m.set(k,v);
150 dm=cm; //Copy from another type
154 typename Graph::EdgeMap<bool> m(G);
155 typename Graph::EdgeMap<bool> const &cm = m; //Const map
156 typename Graph::EdgeMap<bool> mdef(G,12); //Inicialize with default value
157 typename Graph::EdgeMap<bool> mm(cm); //Copy
158 typename Graph::EdgeMap<int> dm(cm); //Copy from another type
160 v=m[k]; m[k]=v; m.set(k,v);
164 dm=cm; //Copy from another type
171 template<class Graph> void addPetersen(Graph &G)
173 std::vector<typename Graph::Node> outer, inner;
175 for(int i=0;i<5;i++) {
176 outer.push_back(G.addNode());
177 inner.push_back(G.addNode());
180 for(int i=0;i<5;i++) {
181 G.addEdge(outer[i],inner[i]);
182 G.addEdge(outer[i],outer[(i+1)%5]);
183 G.addEdge(inner[i],inner[(i+2)%5]);
187 template<class Graph> void checkNodeList(Graph &G, int nn)
189 typename Graph::NodeIt n(G);
190 for(int i=0;i<nn;i++) {
191 check(G.valid(n),"Wrong Node list linking.");
194 check(!G.valid(n),"Wrong Node list linking.");
197 template<class Graph> void checkEdgeList(Graph &G, int nn)
199 typedef typename Graph::EdgeIt EdgeIt;
202 for(int i=0;i<nn;i++) {
203 check(G.valid(e),"Wrong Edge list linking.");
206 check(!G.valid(e),"Wrong Edge list linking.");
209 template<class Graph> void checkOutEdgeList(Graph &G,
210 typename Graph::Node n,
213 typename Graph::OutEdgeIt e(G,n);
214 for(int i=0;i<nn;i++) {
215 check(G.valid(e),"Wrong OutEdge list linking.");
218 check(!G.valid(e),"Wrong OutEdge list linking.");
221 template<class Graph> void checkInEdgeList(Graph &G,
222 typename Graph::Node n,
225 typename Graph::InEdgeIt e(G,n);
226 for(int i=0;i<nn;i++) {
227 check(G.valid(e),"Wrong InEdge list linking.");
230 check(!G.valid(e),"Wrong InEdge list linking.");
233 //Checks head(), tail() as well;
234 template<class Graph> void bidirPetersen(Graph &G)
236 typedef typename Graph::Edge Edge;
237 typedef typename Graph::EdgeIt EdgeIt;
241 std::vector<Edge> ee;
243 for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
245 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
246 G.addEdge(G.head(*p),G.tail(*p));
249 template<class Graph> void checkPetersen(Graph &G)
251 typedef typename Graph::Node Node;
253 typedef typename Graph::EdgeIt EdgeIt;
254 typedef typename Graph::NodeIt NodeIt;
259 for(NodeIt n(G);G.valid(n);G.next(n)) {
260 checkInEdgeList(G,n,3);
261 checkOutEdgeList(G,n,3);
266 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
267 template void checkCompile<SmartGraph>(SmartGraph &);
268 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
269 template void checkCompile<ListGraph>(ListGraph &);
270 template void checkCompile<SymListGraph>(SymListGraph &);
271 //Due to some mysterious and some conceptual problems it does not work.
272 //template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
300 //\todo copy constr tests.
302 std::cout << __FILE__ ": All tests passed.\n";