Changeset 774:4297098d9677 in lemon0.x for src/test/graph_test.cc
 Timestamp:
 08/30/04 14:01:47 (18 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1066
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/test/graph_test.cc
r733 r774 7 7 #include"test_tools.h" 8 8 9 /* 9 /** 10 \file 10 11 This test makes consistency checks of list graph structures. 11 12 12 G.addNode(), G.addEdge(), G. valid(), G.tail(), G.head()13 G.addNode(), G.addEdge(), G.tail(), G.head() 13 14 14 15 \todo Checks for empty graphs and isolated points. 16 \todo Checks for Node>NodeIt, Edge>{EdgeIt,InEdgeIt,OutEdgeIt} 17 conversion. 15 18 */ 16 19 … … 30 33 Node i; Node j(i); Node k(INVALID); 31 34 i=j; 32 bool b=G.valid(i); b=b; 35 // bool b=G.valid(i); b=b; 36 bool b; b=b; 37 b=(i==INVALID); b=(i!=INVALID); 33 38 b=(i==j); b=(i!=j); b=(i<j); 34 39 } … … 37 42 i=j; 38 43 j=G.first(i); 39 j=G.next(i); 40 bool b=G.valid(i); b=b; 44 j=++i; 45 // bool b=G.valid(i); b=b; 46 bool b; b=b; 47 b=(i==INVALID); b=(i!=INVALID); 41 48 Node n(i); 42 49 n=i; 43 50 b=(i==j); b=(i!=j); b=(i<j); 51 //Node >NodeIt conversion 52 NodeIt ni(G,n); 44 53 } 45 54 { 46 55 Edge i; Edge j(i); Edge k(INVALID); 47 56 i=j; 48 bool b=G.valid(i); b=b; 57 // bool b=G.valid(i); b=b; 58 bool b; b=b; 59 b=(i==INVALID); b=(i!=INVALID); 49 60 b=(i==j); b=(i!=j); b=(i<j); 50 61 } … … 53 64 i=j; 54 65 j=G.first(i); 55 j=G.next(i); 56 bool b=G.valid(i); b=b; 66 j=++i; 67 // bool b=G.valid(i); b=b; 68 bool b; b=b; 69 b=(i==INVALID); b=(i!=INVALID); 57 70 Edge e(i); 58 71 e=i; 59 72 b=(i==j); b=(i!=j); b=(i<j); 73 //Edge >EdgeIt conversion 74 EdgeIt ei(G,e); 60 75 } 61 76 { … … 64 79 i=j; 65 80 j=G.first(i,n); 66 j=G.next(i); 67 bool b=G.valid(i); b=b; 81 j=++i; 82 // bool b=G.valid(i); b=b; 83 bool b; b=b; 84 b=(i==INVALID); b=(i!=INVALID); 68 85 Edge e(i); 69 86 e=i; 70 87 b=(i==j); b=(i!=j); b=(i<j); 88 //Edge >InEdgeIt conversion 89 InEdgeIt ei(G,e); 71 90 } 72 91 { … … 75 94 i=j; 76 95 j=G.first(i,n); 77 j=G.next(i); 78 bool b=G.valid(i); b=b; 96 j=++i; 97 // bool b=G.valid(i); b=b; 98 bool b; b=b; 99 b=(i==INVALID); b=(i!=INVALID); 79 100 Edge e(i); 80 101 e=i; 81 102 b=(i==j); b=(i!=j); b=(i<j); 82 }83 84 Node n,m;85 n=m=INVALID;86 Edge e;87 e=INVALID;88 n=G.tail(e);89 n=G.head(e);90 91 //aNode, bNode ?92 103 //Edge >OutEdgeIt conversion 104 OutEdgeIt ei(G,e); 105 } 106 { 107 Node n,m; 108 n=m=INVALID; 109 Edge e; 110 e=INVALID; 111 n=G.tail(e); 112 n=G.head(e); 113 } 93 114 // id tests 94 { int i=G.id(n); i=i; } 95 { int i=G.id(e); i=i; } 96 97 // G.clear(); 98 115 { Node n; int i=G.id(n); i=i; } 116 { Edge e; int i=G.id(e); i=i; } 99 117 //NodeMap tests 100 118 { 101 119 Node k; 102 120 typename Graph::template NodeMap<int> m(G); 103 typename Graph::template NodeMap<int> const &cm = m; //Const map 121 //Const map 122 typename Graph::template NodeMap<int> const &cm = m; 104 123 //Inicialize with default value 105 124 typename Graph::template NodeMap<int> mdef(G,12); 106 typename Graph::template NodeMap<int> mm(cm); //Copy 107 typename Graph::template NodeMap<double> dm(cm); //Copy from another type 125 //Copy 126 typename Graph::template NodeMap<int> mm(cm); 127 //Copy from another type 128 typename Graph::template NodeMap<double> dm(cm); 108 129 int v; 109 130 v=m[k]; m[k]=v; m.set(k,v); … … 161 182 m=dm; //Copy to another type 162 183 } 163 164 184 } 165 185 … … 178 198 n=G.addNode(); 179 199 m=G.addNode(); 180 181 G.addEdge(n,m); 200 Edge e; 201 e=G.addEdge(n,m); 202 203 // G.clear(); 204 } 205 206 template<class Graph> void checkCompileErase(Graph &G) 207 { 208 typedef typename Graph::Node Node; 209 typedef typename Graph::Edge Edge; 210 Node n; 211 Edge e; 212 G.erase(n); 213 G.erase(e); 214 } 215 216 template<class Graph> void checkCompileEraseEdge(Graph &G) 217 { 218 typedef typename Graph::Edge Edge; 219 Edge e; 220 G.erase(e); 221 } 222 223 template<class Graph> void checkCompileFindEdge(Graph &G) 224 { 225 typedef typename Graph::NodeIt Node; 226 typedef typename Graph::NodeIt NodeIt; 227 228 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); 229 G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); 182 230 } 183 231 … … 187 235 typename Graph::NodeIt n(G); 188 236 for(int i=0;i<nn;i++) { 189 check( G.valid(n),"Wrong Node list linking.");190 G.next(n);191 } 192 check( !G.valid(n),"Wrong Node list linking.");237 check(n!=INVALID,"Wrong Node list linking."); 238 ++n; 239 } 240 check(n==INVALID,"Wrong Node list linking."); 193 241 } 194 242 … … 199 247 EdgeIt e(G); 200 248 for(int i=0;i<nn;i++) { 201 check( G.valid(e),"Wrong Edge list linking.");202 G.next(e);203 } 204 check( !G.valid(e),"Wrong Edge list linking.");249 check(e!=INVALID,"Wrong Edge list linking."); 250 ++e; 251 } 252 check(e==INVALID,"Wrong Edge list linking."); 205 253 } 206 254 … … 211 259 typename Graph::OutEdgeIt e(G,n); 212 260 for(int i=0;i<nn;i++) { 213 check( G.valid(e),"Wrong OutEdge list linking.");214 G.next(e);215 } 216 check( !G.valid(e),"Wrong OutEdge list linking.");261 check(e!=INVALID,"Wrong OutEdge list linking."); 262 ++e; 263 } 264 check(e==INVALID,"Wrong OutEdge list linking."); 217 265 } 218 266 219 267 template<class Graph> void checkInEdgeList(Graph &G, 220 221 268 typename Graph::Node n, 269 int nn) 222 270 { 223 271 typename Graph::InEdgeIt e(G,n); 224 272 for(int i=0;i<nn;i++) { 225 check(G.valid(e),"Wrong InEdge list linking."); 226 G.next(e); 227 } 228 check(!G.valid(e),"Wrong InEdge list linking."); 229 } 230 231 //Checks head(), tail() as well; 273 check(e!=INVALID,"Wrong InEdge list linking."); 274 ++e; 275 } 276 check(e==INVALID,"Wrong InEdge list linking."); 277 } 278 279 ///\file 280 ///\todo Checks head(), tail() as well; 281 232 282 template<class Graph> void bidirPetersen(Graph &G) 233 283 { … … 239 289 std::vector<Edge> ee; 240 290 241 for(EdgeIt e(G); G.valid(e);G.next(e)) ee.push_back(e);291 for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e); 242 292 243 293 for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++) … … 255 305 checkEdgeList(G,30); 256 306 257 for(NodeIt n(G); G.valid(n);G.next(n)) {307 for(NodeIt n(G);n!=INVALID;++n) { 258 308 checkInEdgeList(G,n,3); 259 309 checkOutEdgeList(G,n,3); 260 G.next(n);310 ++n; 261 311 } 262 312 } 263 313 264 template 314 //Compile GraphSkeleton 315 template 265 316 void checkCompileStaticGraph<StaticGraphSkeleton>(StaticGraphSkeleton &); 266 317 template void checkCompile<GraphSkeleton>(GraphSkeleton &); 267 318 template 319 void checkCompileErase<EraseableGraphSkeleton>(EraseableGraphSkeleton &); 320 321 //Compile SmartGraph 268 322 template void checkCompile<SmartGraph>(SmartGraph &); 323 //Compile SymSmartGraph 269 324 template void checkCompile<SymSmartGraph>(SymSmartGraph &); 325 326 //Compile ListGraph 270 327 template void checkCompile<ListGraph>(ListGraph &); 328 template void checkCompileErase<ListGraph>(ListGraph &); 329 template void checkCompileFindEdge<ListGraph>(ListGraph &); 330 331 //Compile SymListGraph 271 332 template void checkCompile<SymListGraph>(SymListGraph &); 333 template void checkCompileErase<SymListGraph>(SymListGraph &); 334 template void checkCompileFindEdge<SymListGraph>(SymListGraph &); 335 336 //Compile FullGraph 272 337 template void checkCompileStaticGraph<FullGraph>(FullGraph &); 273 338 template void checkCompileFindEdge<FullGraph>(FullGraph &); 339 340 //Compile EdgeSet <ListGraph> 274 341 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &); 342 template 343 void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &); 344 template 345 void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &); 346 347 //Compile EdgeSet <NodeSet> 275 348 template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &); 349 template 350 void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &); 351 template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &); 352 276 353 277 354 int main() … … 300 377 } 301 378 302 //\todo map tests. 303 //\todo copy constr tests. 379 ///\file 380 ///\todo map tests. 381 ///\todo copy constr tests. 304 382 305 383 std::cout << __FILE__ ": All tests passed.\n";
Note: See TracChangeset
for help on using the changeset viewer.