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