src/test/graph_test.h
author klao
Wed, 15 Sep 2004 14:38:13 +0000
changeset 859 2570784896d8
parent 800 b70a494b4912
child 891 74589d20dbc3
permissions -rw-r--r--
Forgotten std::
Apropos, why does it compile without it?
     1 #ifndef HUGO_TEST_GRAPH_TEST_H
     2 #define HUGO_TEST_GRAPH_TEST_H
     3 
     4 
     5 #include "test_tools.h"
     6 
     7 //! \ingroup misc
     8 //! \file
     9 //! \brief Some utility to  test graph classes.
    10 namespace hugo {
    11 
    12 
    13 template<class Graph> void checkCompileStaticGraph(Graph &G) 
    14 {
    15   typedef typename Graph::Node Node;
    16   typedef typename Graph::NodeIt NodeIt;
    17   typedef typename Graph::Edge Edge;
    18   typedef typename Graph::EdgeIt EdgeIt;
    19   typedef typename Graph::InEdgeIt InEdgeIt;
    20   typedef typename Graph::OutEdgeIt OutEdgeIt;
    21   
    22   {
    23     Node i; Node j(i); Node k(INVALID);
    24     i=j;
    25     bool b; b=true;
    26     b=(i==INVALID); b=(i!=INVALID);
    27     b=(i==j); b=(i!=j); b=(i<j);
    28   }
    29   {
    30     NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
    31     i=j;
    32     j=G.first(i);
    33     j=++i;
    34     bool b; b=true;
    35     b=(i==INVALID); b=(i!=INVALID);
    36     Node n(i);
    37     n=i;
    38     b=(i==j); b=(i!=j); b=(i<j);
    39     //Node ->NodeIt conversion
    40     NodeIt ni(G,n);
    41   }
    42   {
    43     Edge i; Edge j(i); Edge k(INVALID);
    44     i=j;
    45     bool b; b=true;
    46     b=(i==INVALID); b=(i!=INVALID);
    47     b=(i==j); b=(i!=j); b=(i<j);
    48   }
    49   {
    50     EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
    51     i=j;
    52     j=G.first(i);
    53     j=++i;
    54     bool b; b=true;
    55     b=(i==INVALID); b=(i!=INVALID);
    56     Edge e(i);
    57     e=i;
    58     b=(i==j); b=(i!=j); b=(i<j);
    59     //Edge ->EdgeIt conversion
    60     EdgeIt ei(G,e);
    61   }
    62   {
    63     Node n;
    64     InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
    65     i=j;
    66     j=G.first(i,n);
    67     j=++i;
    68     bool b; b=true;
    69     b=(i==INVALID); b=(i!=INVALID);
    70     Edge e(i);
    71     e=i;
    72     b=(i==j); b=(i!=j); b=(i<j);
    73     //Edge ->InEdgeIt conversion
    74     InEdgeIt ei(G,e);
    75   }
    76   {
    77     Node n;
    78     OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
    79     i=j;
    80     j=G.first(i,n);
    81     j=++i;
    82     bool b; b=true;
    83     b=(i==INVALID); b=(i!=INVALID);
    84     Edge e(i);
    85     e=i;
    86     b=(i==j); b=(i!=j); b=(i<j);
    87     //Edge ->OutEdgeIt conversion
    88     OutEdgeIt ei(G,e);
    89   }
    90   {
    91     Node n,m;
    92     n=m=INVALID;
    93     Edge e;
    94     e=INVALID;
    95     n=G.tail(e);
    96     n=G.head(e);
    97   }
    98   // id tests
    99   { Node n; int i=G.id(n); i=i; }
   100   { Edge e; int i=G.id(e); i=i; }
   101   //NodeMap tests
   102   {
   103     Node k;
   104     typename Graph::template NodeMap<int> m(G);
   105     //Const map
   106     typename Graph::template NodeMap<int> const &cm = m;
   107     //Inicialize with default value
   108     typename Graph::template NodeMap<int> mdef(G,12);
   109     //Copy
   110     typename Graph::template NodeMap<int> mm(cm);
   111     //Copy from another type
   112     typename Graph::template NodeMap<double> dm(cm);
   113     int v;
   114     v=m[k]; m[k]=v; m.set(k,v);
   115     v=cm[k];
   116     
   117     m=cm;  
   118     dm=cm; //Copy from another type
   119     {
   120       //Check the typedef's
   121       typename Graph::template NodeMap<int>::ValueType val;
   122       val=1;
   123       typename Graph::template NodeMap<int>::KeyType key;
   124       key = typename Graph::NodeIt(G);
   125     }
   126   }  
   127   { //bool NodeMap
   128     Node k;
   129     typename Graph::template NodeMap<bool> m(G);
   130     typename Graph::template NodeMap<bool> const &cm = m;  //Const map
   131     //Inicialize with default value
   132     typename Graph::template NodeMap<bool> mdef(G,12);
   133     typename Graph::template NodeMap<bool> mm(cm);   //Copy
   134     typename Graph::template NodeMap<int> dm(cm); //Copy from another type
   135     bool v;
   136     v=m[k]; m[k]=v; m.set(k,v);
   137     v=cm[k];
   138     
   139     m=cm;  
   140     dm=cm; //Copy from another type
   141     m=dm; //Copy to another type
   142 
   143     {
   144       //Check the typedef's
   145       typename Graph::template NodeMap<bool>::ValueType val;
   146       val=true;
   147       typename Graph::template NodeMap<bool>::KeyType key;
   148       key= typename Graph::NodeIt(G);
   149     }
   150   }
   151   //EdgeMap tests
   152   {
   153     Edge k;
   154     typename Graph::template EdgeMap<int> m(G);
   155     typename Graph::template EdgeMap<int> const &cm = m;  //Const map
   156     //Inicialize with default value
   157     typename Graph::template EdgeMap<int> mdef(G,12);
   158     typename Graph::template EdgeMap<int> mm(cm);   //Copy
   159     typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
   160     int v;
   161     v=m[k]; m[k]=v; m.set(k,v);
   162     v=cm[k];
   163     
   164     m=cm;  
   165     dm=cm; //Copy from another type
   166     {
   167       //Check the typedef's
   168       typename Graph::template EdgeMap<int>::ValueType val;
   169       val=1;
   170       typename Graph::template EdgeMap<int>::KeyType key;
   171       key= typename Graph::EdgeIt(G);
   172     }
   173   }  
   174   { //bool EdgeMap
   175     Edge k;
   176     typename Graph::template EdgeMap<bool> m(G);
   177     typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
   178     //Inicialize with default value
   179     typename Graph::template EdgeMap<bool> mdef(G,12);
   180     typename Graph::template EdgeMap<bool> mm(cm);   //Copy
   181     typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
   182     bool v;
   183     v=m[k]; m[k]=v; m.set(k,v);
   184     v=cm[k];
   185     
   186     m=cm;  
   187     dm=cm; //Copy from another type
   188     m=dm; //Copy to another type
   189     {
   190       //Check the typedef's
   191       typename Graph::template EdgeMap<bool>::ValueType val;
   192       val=true;
   193       typename Graph::template EdgeMap<bool>::KeyType key;
   194       key= typename Graph::EdgeIt(G);
   195     }
   196   }
   197 }
   198 
   199 template<class Graph> void checkCompileGraph(Graph &G) 
   200 {
   201   checkCompileStaticGraph(G);
   202 
   203   typedef typename Graph::Node Node;
   204   typedef typename Graph::NodeIt NodeIt;
   205   typedef typename Graph::Edge Edge;
   206   typedef typename Graph::EdgeIt EdgeIt;
   207   typedef typename Graph::InEdgeIt InEdgeIt;
   208   typedef typename Graph::OutEdgeIt OutEdgeIt;
   209   
   210   Node n,m;
   211   n=G.addNode();
   212   m=G.addNode();
   213   Edge e;
   214   e=G.addEdge(n,m); 
   215   
   216   //  G.clear();
   217 }
   218 
   219 template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 
   220 {
   221   typename Graph::Edge e;
   222   G.erase(e);
   223 }
   224 
   225 template<class Graph> void checkCompileGraphEraseNode(Graph &G) 
   226 {
   227   typename Graph::Node n;
   228   G.erase(n);
   229 }
   230 
   231 template<class Graph> void checkCompileErasableGraph(Graph &G) 
   232 {
   233   checkCompileGraph(G);
   234   checkCompileGraphEraseNode(G);
   235   checkCompileGraphEraseEdge(G);
   236 }
   237 
   238 template<class Graph> void checkCompileGraphFindEdge(Graph &G) 
   239 {
   240   typedef typename Graph::NodeIt Node;
   241   typedef typename Graph::NodeIt NodeIt;
   242 
   243   G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
   244   G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));  
   245 }
   246 
   247 template<class Graph> void checkGraphNodeList(Graph &G, int nn)
   248 {
   249   typename Graph::NodeIt n(G);
   250   for(int i=0;i<nn;i++) {
   251     check(n!=INVALID,"Wrong Node list linking.");
   252     ++n;
   253   }
   254   check(n==INVALID,"Wrong Node list linking.");
   255 }
   256 
   257 template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
   258 {
   259   typedef typename Graph::EdgeIt EdgeIt;
   260 
   261   EdgeIt e(G);
   262   for(int i=0;i<nn;i++) {
   263     check(e!=INVALID,"Wrong Edge list linking.");
   264     ++e;
   265   }
   266   check(e==INVALID,"Wrong Edge list linking.");
   267 }
   268 
   269 template<class Graph> void checkGraphOutEdgeList(Graph &G,
   270 						 typename Graph::Node n,
   271 						 int nn)
   272 {
   273   typename Graph::OutEdgeIt e(G,n);
   274   for(int i=0;i<nn;i++) {
   275     check(e!=INVALID,"Wrong OutEdge list linking.");
   276     ++e;
   277   }
   278   check(e==INVALID,"Wrong OutEdge list linking.");
   279 }
   280 
   281 template<class Graph> void checkGraphInEdgeList(Graph &G,
   282 						typename Graph::Node n,
   283 						int nn)
   284 {
   285   typename Graph::InEdgeIt e(G,n);
   286   for(int i=0;i<nn;i++) {
   287     check(e!=INVALID,"Wrong InEdge list linking.");
   288     ++e;
   289   }
   290   check(e==INVALID,"Wrong InEdge list linking.");
   291 }
   292 
   293 ///\file
   294 ///\todo Check head(), tail() as well;
   295 
   296   
   297 } //namespace hugo
   298 
   299 
   300 #endif