src/test/dfs_test.cc
changeset 780 e06d0d16595f
child 793 9cd0aeea47b0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/test/dfs_test.cc	Wed Sep 01 15:08:41 2004 +0000
     1.3 @@ -0,0 +1,79 @@
     1.4 +#include "test_tools.h"
     1.5 +#include <hugo/smart_graph.h>
     1.6 +#include <hugo/dfs.h>
     1.7 +
     1.8 +using namespace hugo;
     1.9 +
    1.10 +const int PET_SIZE =5;
    1.11 +
    1.12 +
    1.13 +void check_Dfs_SmartGraph_Compile() 
    1.14 +{
    1.15 +  typedef int VType;
    1.16 +  typedef SmartGraph Graph;
    1.17 +
    1.18 +  typedef Graph::Edge Edge;
    1.19 +  typedef Graph::Node Node;
    1.20 +  typedef Graph::EdgeIt EdgeIt;
    1.21 +  typedef Graph::NodeIt NodeIt;
    1.22 +  typedef Graph::EdgeMap<VType> LengthMap;
    1.23 + 
    1.24 +  typedef Dfs<Graph> BType;
    1.25 +  
    1.26 +  Graph G;
    1.27 +  Node n;
    1.28 +  Edge e;
    1.29 +  VType l;
    1.30 +  bool b;
    1.31 +  BType::DistMap d(G);
    1.32 +  BType::PredMap p(G);
    1.33 +  BType::PredNodeMap pn(G);
    1.34 +  LengthMap cap(G);
    1.35 +  
    1.36 +  BType dfs_test(G);
    1.37 +  
    1.38 +  dfs_test.run(n);
    1.39 +  
    1.40 +  l  = dfs_test.dist(n);
    1.41 +  e  = dfs_test.pred(n);
    1.42 +  n  = dfs_test.predNode(n);
    1.43 +  d  = dfs_test.distMap();
    1.44 +  p  = dfs_test.predMap();
    1.45 +  pn = dfs_test.predNodeMap();
    1.46 +  b  = dfs_test.reached(n);
    1.47 +
    1.48 +}
    1.49 +
    1.50 +int main()
    1.51 +{
    1.52 +    
    1.53 +  typedef SmartGraph Graph;
    1.54 +
    1.55 +  typedef Graph::Edge Edge;
    1.56 +  typedef Graph::Node Node;
    1.57 +  typedef Graph::EdgeIt EdgeIt;
    1.58 +  typedef Graph::NodeIt NodeIt;
    1.59 +  typedef Graph::EdgeMap<int> LengthMap;
    1.60 +
    1.61 +  Graph G;
    1.62 +  Node s, t;
    1.63 +  PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
    1.64 +   
    1.65 +  s=ps.outer[2];
    1.66 +  t=ps.inner[0];
    1.67 +  
    1.68 +  Dfs<Graph> dfs_test(G);
    1.69 +  dfs_test.run(s);  
    1.70 +  
    1.71 +  for(NodeIt v(G); v!=INVALID; ++v) {
    1.72 +    check(dfs_test.reached(v),"Each node should be reached.");
    1.73 +    if ( dfs_test.pred(v)!=INVALID ) {
    1.74 +      Edge e=dfs_test.pred(v);
    1.75 +      Node u=G.tail(e);
    1.76 +      check(u==dfs_test.predNode(v),"Wrong tree.");
    1.77 +      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
    1.78 +	    "Wrong distance." << dfs_test.dist(v) << " " <<dfs_test.dist(u) );
    1.79 +    }
    1.80 +  }
    1.81 +}
    1.82 +