2 #include<hugo/smart_graph.h>
3 #include<hugo/skeletons/graph.h>
6 //#include<../work/alpar/list_graph.h>
9 This test makes consistency checks of list graph structures.
11 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
17 template<class Graph> void checkCompile(Graph &G)
19 typedef typename Graph::Node Node;
20 typedef typename Graph::NodeIt NodeIt;
21 typedef typename Graph::Edge Edge;
22 typedef typename Graph::EdgeIt EdgeIt;
23 typedef typename Graph::InEdgeIt InEdgeIt;
24 typedef typename Graph::OutEdgeIt OutEdgeIt;
27 Node i; Node j(i); Node k(INVALID);
29 bool b=G.valid(i); b=b;
30 b=(i==j); b=(i!=j); b=(i<j);
33 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
37 bool b=G.valid(i); b=b;
40 b=(i==j); b=(i!=j); b=(i<j);
43 Edge i; Edge j(i); Edge k(INVALID);
45 bool b=G.valid(i); b=b;
46 b=(i==j); b=(i!=j); b=(i<j);
49 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
53 bool b=G.valid(i); b=b;
56 b=(i==j); b=(i!=j); b=(i<j);
60 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
64 bool b=G.valid(i); b=b;
67 b=(i==j); b=(i!=j); b=(i<j);
71 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
75 bool b=G.valid(i); b=b;
78 b=(i==j); b=(i!=j); b=(i<j);
91 { int i=G.id(n); i=i; }
92 { int i=G.id(e); i=i; }
99 typename Graph::template NodeMap<int> m(G);
100 typename Graph::template NodeMap<int> const &cm = m; //Const map
101 //Inicialize with default value
102 typename Graph::template NodeMap<int> mdef(G,12);
103 typename Graph::template NodeMap<int> mm(cm); //Copy
104 typename Graph::template NodeMap<double> dm(cm); //Copy from another type
106 v=m[k]; m[k]=v; m.set(k,v);
110 dm=cm; //Copy from another type
114 typename Graph::template NodeMap<bool> m(G);
115 typename Graph::template NodeMap<bool> const &cm = m; //Const map
116 //Inicialize with default value
117 typename Graph::template NodeMap<bool> mdef(G,12);
118 typename Graph::template NodeMap<bool> mm(cm); //Copy
119 typename Graph::template NodeMap<int> dm(cm); //Copy from another type
121 v=m[k]; m[k]=v; m.set(k,v);
125 dm=cm; //Copy from another type
126 m=dm; //Copy to another type
131 typename Graph::template EdgeMap<int> m(G);
132 typename Graph::template EdgeMap<int> const &cm = m; //Const map
133 //Inicialize with default value
134 typename Graph::template EdgeMap<int> mdef(G,12);
135 typename Graph::template EdgeMap<int> mm(cm); //Copy
136 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
138 v=m[k]; m[k]=v; m.set(k,v);
142 dm=cm; //Copy from another type
146 typename Graph::template EdgeMap<bool> m(G);
147 typename Graph::template EdgeMap<bool> const &cm = m; //Const map
148 //Inicialize with default value
149 typename Graph::template EdgeMap<bool> mdef(G,12);
150 typename Graph::template EdgeMap<bool> mm(cm); //Copy
151 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
153 v=m[k]; m[k]=v; m.set(k,v);
157 dm=cm; //Copy from another type
158 m=dm; //Copy to another type
163 template<class Graph> void checkNodeList(Graph &G, int nn)
165 typename Graph::NodeIt n(G);
166 for(int i=0;i<nn;i++) {
167 check(G.valid(n),"Wrong Node list linking.");
170 check(!G.valid(n),"Wrong Node list linking.");
173 template<class Graph> void checkEdgeList(Graph &G, int nn)
175 typedef typename Graph::EdgeIt EdgeIt;
178 for(int i=0;i<nn;i++) {
179 check(G.valid(e),"Wrong Edge list linking.");
182 check(!G.valid(e),"Wrong Edge list linking.");
185 template<class Graph> void checkOutEdgeList(Graph &G,
186 typename Graph::Node n,
189 typename Graph::OutEdgeIt e(G,n);
190 for(int i=0;i<nn;i++) {
191 check(G.valid(e),"Wrong OutEdge list linking.");
194 check(!G.valid(e),"Wrong OutEdge list linking.");
197 template<class Graph> void checkInEdgeList(Graph &G,
198 typename Graph::Node n,
201 typename Graph::InEdgeIt e(G,n);
202 for(int i=0;i<nn;i++) {
203 check(G.valid(e),"Wrong InEdge list linking.");
206 check(!G.valid(e),"Wrong InEdge list linking.");
209 //Checks head(), tail() as well;
210 template<class Graph> void bidirPetersen(Graph &G)
212 typedef typename Graph::Edge Edge;
213 typedef typename Graph::EdgeIt EdgeIt;
217 std::vector<Edge> ee;
219 for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
221 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
222 G.addEdge(G.head(*p),G.tail(*p));
225 template<class Graph> void checkPetersen(Graph &G)
227 typedef typename Graph::Node Node;
229 typedef typename Graph::EdgeIt EdgeIt;
230 typedef typename Graph::NodeIt NodeIt;
235 for(NodeIt n(G);G.valid(n);G.next(n)) {
236 checkInEdgeList(G,n,3);
237 checkOutEdgeList(G,n,3);
242 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
243 template void checkCompile<SmartGraph>(SmartGraph &);
244 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
245 //template void checkCompile<ListGraph>(ListGraph &);
246 //template void checkCompile<SymListGraph>(SymListGraph &);
248 //Due to some mysterious and some conceptual problems it does not work.
249 //template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
277 //\todo copy constr tests.
279 std::cout << __FILE__ ": All tests passed.\n";