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
136 m=dm; //Copy to another type
141 typename Graph::EdgeMap<int> m(G);
142 typename Graph::EdgeMap<int> const &cm = m; //Const map
143 typename Graph::EdgeMap<int> mdef(G,12); //Inicialize with default value
144 typename Graph::EdgeMap<int> mm(cm); //Copy
145 typename Graph::EdgeMap<double> dm(cm); //Copy from another type
147 v=m[k]; m[k]=v; m.set(k,v);
151 dm=cm; //Copy from another type
155 typename Graph::EdgeMap<bool> m(G);
156 typename Graph::EdgeMap<bool> const &cm = m; //Const map
157 typename Graph::EdgeMap<bool> mdef(G,12); //Inicialize with default value
158 typename Graph::EdgeMap<bool> mm(cm); //Copy
159 typename Graph::EdgeMap<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
173 template<class Graph> void addPetersen(Graph &G)
175 std::vector<typename Graph::Node> outer, inner;
177 for(int i=0;i<5;i++) {
178 outer.push_back(G.addNode());
179 inner.push_back(G.addNode());
182 for(int i=0;i<5;i++) {
183 G.addEdge(outer[i],inner[i]);
184 G.addEdge(outer[i],outer[(i+1)%5]);
185 G.addEdge(inner[i],inner[(i+2)%5]);
189 template<class Graph> void checkNodeList(Graph &G, int nn)
191 typename Graph::NodeIt n(G);
192 for(int i=0;i<nn;i++) {
193 check(G.valid(n),"Wrong Node list linking.");
196 check(!G.valid(n),"Wrong Node list linking.");
199 template<class Graph> void checkEdgeList(Graph &G, int nn)
201 typedef typename Graph::EdgeIt EdgeIt;
204 for(int i=0;i<nn;i++) {
205 check(G.valid(e),"Wrong Edge list linking.");
208 check(!G.valid(e),"Wrong Edge list linking.");
211 template<class Graph> void checkOutEdgeList(Graph &G,
212 typename Graph::Node n,
215 typename Graph::OutEdgeIt e(G,n);
216 for(int i=0;i<nn;i++) {
217 check(G.valid(e),"Wrong OutEdge list linking.");
220 check(!G.valid(e),"Wrong OutEdge list linking.");
223 template<class Graph> void checkInEdgeList(Graph &G,
224 typename Graph::Node n,
227 typename Graph::InEdgeIt e(G,n);
228 for(int i=0;i<nn;i++) {
229 check(G.valid(e),"Wrong InEdge list linking.");
232 check(!G.valid(e),"Wrong InEdge list linking.");
235 //Checks head(), tail() as well;
236 template<class Graph> void bidirPetersen(Graph &G)
238 typedef typename Graph::Edge Edge;
239 typedef typename Graph::EdgeIt EdgeIt;
243 std::vector<Edge> ee;
245 for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
247 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
248 G.addEdge(G.head(*p),G.tail(*p));
251 template<class Graph> void checkPetersen(Graph &G)
253 typedef typename Graph::Node Node;
255 typedef typename Graph::EdgeIt EdgeIt;
256 typedef typename Graph::NodeIt NodeIt;
261 for(NodeIt n(G);G.valid(n);G.next(n)) {
262 checkInEdgeList(G,n,3);
263 checkOutEdgeList(G,n,3);
268 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
269 template void checkCompile<SmartGraph>(SmartGraph &);
270 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
271 template void checkCompile<ListGraph>(ListGraph &);
272 template void checkCompile<SymListGraph>(SymListGraph &);
273 //Due to some mysterious and some conceptual problems it does not work.
274 //template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
302 //\todo copy constr tests.
304 std::cout << __FILE__ ": All tests passed.\n";