test/dfs_test.cc
changeset 201 9757e3d9bfeb
parent 100 4f754b4cf82b
child 209 765619b7cbb2
equal deleted inserted replaced
0:59863e4ac90c 1:942eac1b77bb
    14  * express or implied, and with no claim as to its suitability for any
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    15  * purpose.
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #include "test_tools.h"
    19 #include <lemon/concepts/digraph.h>
    20 // #include <lemon/smart_graph.h>
    20 #include <lemon/smart_graph.h>
    21 #include <lemon/list_graph.h>
    21 #include <lemon/list_graph.h>
    22 #include <lemon/dfs.h>
    22 #include <lemon/dfs.h>
    23 #include <lemon/path.h>
    23 #include <lemon/path.h>
    24 #include <lemon/concepts/digraph.h>
    24 
       
    25 #include "graph_test.h"
       
    26 #include "test_tools.h"
    25 
    27 
    26 using namespace lemon;
    28 using namespace lemon;
    27 
    29 
    28 const int PET_SIZE =5;
    30 void checkDfsCompile() 
    29 
       
    30 
       
    31 void check_Dfs_SmartDigraph_Compile() 
       
    32 {
    31 {
    33   typedef concepts::Digraph Digraph;
    32   typedef concepts::Digraph Digraph;
    34 
       
    35   typedef Digraph::Arc Arc;
       
    36   typedef Digraph::Node Node;
       
    37   typedef Digraph::ArcIt ArcIt;
       
    38   typedef Digraph::NodeIt NodeIt;
       
    39  
       
    40   typedef Dfs<Digraph> DType;
    33   typedef Dfs<Digraph> DType;
    41   
    34   
    42   Digraph G;
    35   Digraph G;
    43   Node n;
    36   Digraph::Node n;
    44   Arc e;
    37   Digraph::Arc e;
    45   int l;
    38   int l;
    46   bool b;
    39   bool b;
    47   DType::DistMap d(G);
    40   DType::DistMap d(G);
    48   DType::PredMap p(G);
    41   DType::PredMap p(G);
    49   //  DType::PredNodeMap pn(G);
    42   //  DType::PredNodeMap pn(G);
    61   b  = dfs_test.reached(n);
    54   b  = dfs_test.reached(n);
    62 
    55 
    63   Path<Digraph> pp = dfs_test.path(n);
    56   Path<Digraph> pp = dfs_test.path(n);
    64 }
    57 }
    65 
    58 
    66 
    59 void checkDfsFunctionCompile() 
    67 void check_Dfs_Function_Compile() 
       
    68 {
    60 {
    69   typedef int VType;
    61   typedef int VType;
    70   typedef concepts::Digraph Digraph;
    62   typedef concepts::Digraph Digraph;
    71 
       
    72   typedef Digraph::Arc Arc;
    63   typedef Digraph::Arc Arc;
    73   typedef Digraph::Node Node;
    64   typedef Digraph::Node Node;
    74   typedef Digraph::ArcIt ArcIt;
       
    75   typedef Digraph::NodeIt NodeIt;
       
    76   typedef concepts::ReadMap<Arc,VType> LengthMap;
       
    77    
    65    
    78   Digraph g;
    66   Digraph g;
    79   dfs(g,Node()).run();
    67   dfs(g,Node()).run();
    80   dfs(g).source(Node()).run();
    68   dfs(g).source(Node()).run();
    81   dfs(g)
    69   dfs(g)
    82     .predMap(concepts::WriteMap<Node,Arc>())
    70     .predMap(concepts::WriteMap<Node,Arc>())
    83     .distMap(concepts::WriteMap<Node,VType>())
    71     .distMap(concepts::WriteMap<Node,VType>())
    84     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    72     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    85     .processedMap(concepts::WriteMap<Node,bool>())
    73     .processedMap(concepts::WriteMap<Node,bool>())
    86     .run(Node());
    74     .run(Node()); 
    87   
       
    88 }
    75 }
    89 
    76 
    90 int main()
    77 template <class Digraph>
    91 {
    78 void checkDfs() {
    92     
    79   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    93   // typedef SmartDigraph Digraph;
       
    94   typedef ListDigraph Digraph;
       
    95 
       
    96   typedef Digraph::Arc Arc;
       
    97   typedef Digraph::Node Node;
       
    98   typedef Digraph::ArcIt ArcIt;
       
    99   typedef Digraph::NodeIt NodeIt;
       
   100   typedef Digraph::ArcMap<int> LengthMap;
       
   101 
    80 
   102   Digraph G;
    81   Digraph G;
   103   Node s, t;
    82   Node s, t;
   104   PetStruct<Digraph> ps = addPetersen(G,PET_SIZE);
    83   PetStruct<Digraph> ps = addPetersen(G, 5);
   105    
    84    
   106   s=ps.outer[2];
    85   s=ps.outer[2];
   107   t=ps.inner[0];
    86   t=ps.inner[0];
   108   
    87   
   109   Dfs<Digraph> dfs_test(G);
    88   Dfs<Digraph> dfs_test(G);
   110   dfs_test.run(s);  
    89   dfs_test.run(s);  
   111   
    90   
   112   Path<Digraph> p = dfs_test.path(t);
    91   Path<Digraph> p = dfs_test.path(t);
   113   check(p.length()==dfs_test.dist(t),"path() found a wrong path.");
    92   check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
   114   check(checkPath(G, p),"path() found a wrong path.");
    93   check(checkPath(G, p),"path() found a wrong path.");
   115   check(pathSource(G, p) == s,"path() found a wrong path.");
    94   check(pathSource(G, p) == s,"path() found a wrong path.");
   116   check(pathTarget(G, p) == t,"path() found a wrong path.");
    95   check(pathTarget(G, p) == t,"path() found a wrong path.");
   117   
    96   
   118   for(NodeIt v(G); v!=INVALID; ++v) {
    97   for(NodeIt v(G); v!=INVALID; ++v) {
   126 	    <<dfs_test.dist(v) << ')');
   105 	    <<dfs_test.dist(v) << ')');
   127     }
   106     }
   128   }
   107   }
   129 }
   108 }
   130 
   109 
       
   110 int main()
       
   111 {
       
   112   checkDfs<ListDigraph>();
       
   113   checkDfs<SmartDigraph>();
       
   114   return 0;
       
   115 }