src/test/graph_test.cc
changeset 702 4207f82a1778
parent 579 859f8c7e2a40
child 717 6874df3f61db
equal deleted inserted replaced
8:d0bcb28821d9 9:64774324bb7f
     1 #include<iostream>
     1 #include<iostream>
     2 #include<hugo/smart_graph.h>
     2 #include<hugo/smart_graph.h>
     3 #include<hugo/skeletons/graph.h>
     3 #include<hugo/skeletons/graph.h>
     4 #include<hugo/list_graph.h>
     4 #include<hugo/list_graph.h>
       
     5 #include<hugo/full_graph.h>
     5 
     6 
     6 #include"test_tools.h"
     7 #include"test_tools.h"
     7 
     8 
     8 /*
     9 /*
     9 This test makes consistency checks of list graph structures.
    10 This test makes consistency checks of list graph structures.
    10 
    11 
    11 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
    12 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
    12 
    13 
       
    14 \todo Checks for empty graphs and isolated points.
    13 */
    15 */
    14 
    16 
    15 using namespace hugo;
    17 using namespace hugo;
    16 
    18 
    17 template<class Graph> void checkCompile(Graph &G) 
    19 template<class Graph> void checkCompileStaticGraph(Graph &G) 
    18 {
    20 {
    19   typedef typename Graph::Node Node;
    21   typedef typename Graph::Node Node;
    20   typedef typename Graph::NodeIt NodeIt;
    22   typedef typename Graph::NodeIt NodeIt;
    21   typedef typename Graph::Edge Edge;
    23   typedef typename Graph::Edge Edge;
    22   typedef typename Graph::EdgeIt EdgeIt;
    24   typedef typename Graph::EdgeIt EdgeIt;
    77     e=i;
    79     e=i;
    78     b=(i==j); b=(i!=j); b=(i<j);
    80     b=(i==j); b=(i!=j); b=(i<j);
    79   }
    81   }
    80 
    82 
    81   Node n,m;
    83   Node n,m;
    82   n=G.addNode();
    84   n=m=INVALID;
    83   Edge e;
    85   Edge e;
    84   e=G.addEdge(n,m);
    86   e=INVALID;
    85   n=G.tail(e);
    87   n=G.tail(e);
    86   n=G.head(e);
    88   n=G.head(e);
    87 
    89 
    88   //aNode, bNode ?
    90   //aNode, bNode ?
    89 
    91 
    90   // id tests
    92   // id tests
    91   { int i=G.id(n); i=i; }
    93   { int i=G.id(n); i=i; }
    92   { int i=G.id(e); i=i; }
    94   { int i=G.id(e); i=i; }
    93   
    95   
    94   G.clear();
    96   //  G.clear();
    95 
    97 
    96   //NodeMap tests
    98   //NodeMap tests
    97   {
    99   {
    98     Node k;
   100     Node k;
    99     typename Graph::template NodeMap<int> m(G);
   101     typename Graph::template NodeMap<int> m(G);
   158     m=dm; //Copy to another type
   160     m=dm; //Copy to another type
   159   }
   161   }
   160   
   162   
   161 }
   163 }
   162 
   164 
       
   165 template<class Graph> void checkCompile(Graph &G) 
       
   166 {
       
   167   checkCompileStaticGraph(G);
       
   168 
       
   169   typedef typename Graph::Node Node;
       
   170   typedef typename Graph::NodeIt NodeIt;
       
   171   typedef typename Graph::Edge Edge;
       
   172   typedef typename Graph::EdgeIt EdgeIt;
       
   173   typedef typename Graph::InEdgeIt InEdgeIt;
       
   174   typedef typename Graph::OutEdgeIt OutEdgeIt;
       
   175   
       
   176   Node n,m;
       
   177   n=G.addNode();
       
   178   m=G.addNode();
       
   179   
       
   180   G.addEdge(n,m);
       
   181 }
       
   182 
       
   183 
   163 template<class Graph> void checkNodeList(Graph &G, int nn)
   184 template<class Graph> void checkNodeList(Graph &G, int nn)
   164 {
   185 {
   165   typename Graph::NodeIt n(G);
   186   typename Graph::NodeIt n(G);
   166   for(int i=0;i<nn;i++) {
   187   for(int i=0;i<nn;i++) {
   167     check(G.valid(n),"Wrong Node list linking.");
   188     check(G.valid(n),"Wrong Node list linking.");
   242 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
   263 template void checkCompile<GraphSkeleton>(GraphSkeleton &);
   243 template void checkCompile<SmartGraph>(SmartGraph &);
   264 template void checkCompile<SmartGraph>(SmartGraph &);
   244 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
   265 template void checkCompile<SymSmartGraph>(SymSmartGraph &);
   245 template void checkCompile<ListGraph>(ListGraph &);
   266 template void checkCompile<ListGraph>(ListGraph &);
   246 template void checkCompile<SymListGraph>(SymListGraph &);
   267 template void checkCompile<SymListGraph>(SymListGraph &);
       
   268 template void checkCompileStaticGraph<FullGraph>(FullGraph &);
   247 
   269 
   248 //Due to some mysterious problems it does not work.
   270 //Due to some mysterious problems it does not work.
   249 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
   271 template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
   250 //template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
   272 //template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
   251 
   273