alpar@800: #ifndef HUGO_TEST_GRAPH_TEST_H
alpar@800: #define HUGO_TEST_GRAPH_TEST_H
alpar@800: 
alpar@800: 
alpar@800: #include "test_tools.h"
alpar@800: 
alpar@800: //! \ingroup misc
alpar@800: //! \file
alpar@800: //! \brief Some utility to  test graph classes.
alpar@800: namespace hugo {
alpar@800: 
alpar@800: 
alpar@800: template<class Graph> void checkCompileStaticGraph(Graph &G) 
alpar@800: {
alpar@800:   typedef typename Graph::Node Node;
alpar@800:   typedef typename Graph::NodeIt NodeIt;
alpar@800:   typedef typename Graph::Edge Edge;
alpar@800:   typedef typename Graph::EdgeIt EdgeIt;
alpar@800:   typedef typename Graph::InEdgeIt InEdgeIt;
alpar@800:   typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@800:   
alpar@800:   {
alpar@800:     Node i; Node j(i); Node k(INVALID);
alpar@800:     i=j;
alpar@856:     bool b; b=true;
alpar@800:     b=(i==INVALID); b=(i!=INVALID);
alpar@800:     b=(i==j); b=(i!=j); b=(i<j);
alpar@800:   }
alpar@800:   {
alpar@800:     NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
alpar@800:     i=j;
alpar@800:     j=G.first(i);
alpar@800:     j=++i;
alpar@856:     bool b; b=true;
alpar@800:     b=(i==INVALID); b=(i!=INVALID);
alpar@800:     Node n(i);
alpar@800:     n=i;
alpar@800:     b=(i==j); b=(i!=j); b=(i<j);
alpar@800:     //Node ->NodeIt conversion
alpar@800:     NodeIt ni(G,n);
alpar@800:   }
alpar@800:   {
alpar@800:     Edge i; Edge j(i); Edge k(INVALID);
alpar@800:     i=j;
alpar@856:     bool b; b=true;
alpar@800:     b=(i==INVALID); b=(i!=INVALID);
alpar@800:     b=(i==j); b=(i!=j); b=(i<j);
alpar@800:   }
alpar@800:   {
alpar@800:     EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
alpar@800:     i=j;
alpar@800:     j=G.first(i);
alpar@800:     j=++i;
alpar@856:     bool b; b=true;
alpar@800:     b=(i==INVALID); b=(i!=INVALID);
alpar@800:     Edge e(i);
alpar@800:     e=i;
alpar@800:     b=(i==j); b=(i!=j); b=(i<j);
alpar@800:     //Edge ->EdgeIt conversion
alpar@800:     EdgeIt ei(G,e);
alpar@800:   }
alpar@800:   {
alpar@800:     Node n;
alpar@800:     InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
alpar@800:     i=j;
alpar@800:     j=G.first(i,n);
alpar@800:     j=++i;
alpar@856:     bool b; b=true;
alpar@800:     b=(i==INVALID); b=(i!=INVALID);
alpar@800:     Edge e(i);
alpar@800:     e=i;
alpar@800:     b=(i==j); b=(i!=j); b=(i<j);
alpar@800:     //Edge ->InEdgeIt conversion
alpar@800:     InEdgeIt ei(G,e);
alpar@800:   }
alpar@800:   {
alpar@800:     Node n;
alpar@800:     OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
alpar@800:     i=j;
alpar@800:     j=G.first(i,n);
alpar@800:     j=++i;
alpar@856:     bool b; b=true;
alpar@800:     b=(i==INVALID); b=(i!=INVALID);
alpar@800:     Edge e(i);
alpar@800:     e=i;
alpar@800:     b=(i==j); b=(i!=j); b=(i<j);
alpar@800:     //Edge ->OutEdgeIt conversion
alpar@800:     OutEdgeIt ei(G,e);
alpar@800:   }
alpar@800:   {
alpar@800:     Node n,m;
alpar@800:     n=m=INVALID;
alpar@800:     Edge e;
alpar@800:     e=INVALID;
alpar@800:     n=G.tail(e);
alpar@800:     n=G.head(e);
alpar@800:   }
alpar@800:   // id tests
alpar@800:   { Node n; int i=G.id(n); i=i; }
alpar@800:   { Edge e; int i=G.id(e); i=i; }
alpar@800:   //NodeMap tests
alpar@800:   {
alpar@800:     Node k;
alpar@800:     typename Graph::template NodeMap<int> m(G);
alpar@800:     //Const map
alpar@800:     typename Graph::template NodeMap<int> const &cm = m;
alpar@800:     //Inicialize with default value
alpar@800:     typename Graph::template NodeMap<int> mdef(G,12);
alpar@800:     //Copy
alpar@800:     typename Graph::template NodeMap<int> mm(cm);
alpar@800:     //Copy from another type
alpar@800:     typename Graph::template NodeMap<double> dm(cm);
alpar@800:     int v;
alpar@800:     v=m[k]; m[k]=v; m.set(k,v);
alpar@800:     v=cm[k];
alpar@800:     
alpar@800:     m=cm;  
alpar@800:     dm=cm; //Copy from another type
alpar@800:     {
alpar@800:       //Check the typedef's
alpar@800:       typename Graph::template NodeMap<int>::ValueType val;
alpar@800:       val=1;
alpar@800:       typename Graph::template NodeMap<int>::KeyType key;
alpar@800:       key = typename Graph::NodeIt(G);
alpar@800:     }
alpar@800:   }  
alpar@800:   { //bool NodeMap
alpar@800:     Node k;
alpar@800:     typename Graph::template NodeMap<bool> m(G);
alpar@800:     typename Graph::template NodeMap<bool> const &cm = m;  //Const map
alpar@800:     //Inicialize with default value
alpar@800:     typename Graph::template NodeMap<bool> mdef(G,12);
alpar@800:     typename Graph::template NodeMap<bool> mm(cm);   //Copy
alpar@800:     typename Graph::template NodeMap<int> dm(cm); //Copy from another type
alpar@800:     bool v;
alpar@800:     v=m[k]; m[k]=v; m.set(k,v);
alpar@800:     v=cm[k];
alpar@800:     
alpar@800:     m=cm;  
alpar@800:     dm=cm; //Copy from another type
alpar@800:     m=dm; //Copy to another type
alpar@800: 
alpar@800:     {
alpar@800:       //Check the typedef's
alpar@800:       typename Graph::template NodeMap<bool>::ValueType val;
alpar@800:       val=true;
alpar@800:       typename Graph::template NodeMap<bool>::KeyType key;
alpar@800:       key= typename Graph::NodeIt(G);
alpar@800:     }
alpar@800:   }
alpar@800:   //EdgeMap tests
alpar@800:   {
alpar@800:     Edge k;
alpar@800:     typename Graph::template EdgeMap<int> m(G);
alpar@800:     typename Graph::template EdgeMap<int> const &cm = m;  //Const map
alpar@800:     //Inicialize with default value
alpar@800:     typename Graph::template EdgeMap<int> mdef(G,12);
alpar@800:     typename Graph::template EdgeMap<int> mm(cm);   //Copy
alpar@800:     typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
alpar@800:     int v;
alpar@800:     v=m[k]; m[k]=v; m.set(k,v);
alpar@800:     v=cm[k];
alpar@800:     
alpar@800:     m=cm;  
alpar@800:     dm=cm; //Copy from another type
alpar@800:     {
alpar@800:       //Check the typedef's
alpar@800:       typename Graph::template EdgeMap<int>::ValueType val;
alpar@800:       val=1;
alpar@800:       typename Graph::template EdgeMap<int>::KeyType key;
alpar@800:       key= typename Graph::EdgeIt(G);
alpar@800:     }
alpar@800:   }  
alpar@800:   { //bool EdgeMap
alpar@800:     Edge k;
alpar@800:     typename Graph::template EdgeMap<bool> m(G);
alpar@800:     typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
alpar@800:     //Inicialize with default value
alpar@800:     typename Graph::template EdgeMap<bool> mdef(G,12);
alpar@800:     typename Graph::template EdgeMap<bool> mm(cm);   //Copy
alpar@800:     typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
alpar@800:     bool v;
alpar@800:     v=m[k]; m[k]=v; m.set(k,v);
alpar@800:     v=cm[k];
alpar@800:     
alpar@800:     m=cm;  
alpar@800:     dm=cm; //Copy from another type
alpar@800:     m=dm; //Copy to another type
alpar@800:     {
alpar@800:       //Check the typedef's
alpar@800:       typename Graph::template EdgeMap<bool>::ValueType val;
alpar@800:       val=true;
alpar@800:       typename Graph::template EdgeMap<bool>::KeyType key;
alpar@800:       key= typename Graph::EdgeIt(G);
alpar@800:     }
alpar@800:   }
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkCompileGraph(Graph &G) 
alpar@800: {
alpar@800:   checkCompileStaticGraph(G);
alpar@800: 
alpar@800:   typedef typename Graph::Node Node;
alpar@800:   typedef typename Graph::NodeIt NodeIt;
alpar@800:   typedef typename Graph::Edge Edge;
alpar@800:   typedef typename Graph::EdgeIt EdgeIt;
alpar@800:   typedef typename Graph::InEdgeIt InEdgeIt;
alpar@800:   typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@800:   
alpar@800:   Node n,m;
alpar@800:   n=G.addNode();
alpar@800:   m=G.addNode();
alpar@800:   Edge e;
alpar@800:   e=G.addEdge(n,m); 
alpar@800:   
alpar@800:   //  G.clear();
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 
alpar@800: {
alpar@800:   typename Graph::Edge e;
alpar@800:   G.erase(e);
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkCompileGraphEraseNode(Graph &G) 
alpar@800: {
alpar@800:   typename Graph::Node n;
alpar@800:   G.erase(n);
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkCompileErasableGraph(Graph &G) 
alpar@800: {
alpar@800:   checkCompileGraph(G);
alpar@800:   checkCompileGraphEraseNode(G);
alpar@800:   checkCompileGraphEraseEdge(G);
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkCompileGraphFindEdge(Graph &G) 
alpar@800: {
alpar@800:   typedef typename Graph::NodeIt Node;
alpar@800:   typedef typename Graph::NodeIt NodeIt;
alpar@800: 
alpar@800:   G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
alpar@800:   G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));  
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkGraphNodeList(Graph &G, int nn)
alpar@800: {
alpar@800:   typename Graph::NodeIt n(G);
alpar@800:   for(int i=0;i<nn;i++) {
alpar@800:     check(n!=INVALID,"Wrong Node list linking.");
alpar@800:     ++n;
alpar@800:   }
alpar@800:   check(n==INVALID,"Wrong Node list linking.");
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
alpar@800: {
alpar@800:   typedef typename Graph::EdgeIt EdgeIt;
alpar@800: 
alpar@800:   EdgeIt e(G);
alpar@800:   for(int i=0;i<nn;i++) {
alpar@800:     check(e!=INVALID,"Wrong Edge list linking.");
alpar@800:     ++e;
alpar@800:   }
alpar@800:   check(e==INVALID,"Wrong Edge list linking.");
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkGraphOutEdgeList(Graph &G,
alpar@800: 						 typename Graph::Node n,
alpar@800: 						 int nn)
alpar@800: {
alpar@800:   typename Graph::OutEdgeIt e(G,n);
alpar@800:   for(int i=0;i<nn;i++) {
alpar@800:     check(e!=INVALID,"Wrong OutEdge list linking.");
alpar@800:     ++e;
alpar@800:   }
alpar@800:   check(e==INVALID,"Wrong OutEdge list linking.");
alpar@800: }
alpar@800: 
alpar@800: template<class Graph> void checkGraphInEdgeList(Graph &G,
alpar@800: 						typename Graph::Node n,
alpar@800: 						int nn)
alpar@800: {
alpar@800:   typename Graph::InEdgeIt e(G,n);
alpar@800:   for(int i=0;i<nn;i++) {
alpar@800:     check(e!=INVALID,"Wrong InEdge list linking.");
alpar@800:     ++e;
alpar@800:   }
alpar@800:   check(e==INVALID,"Wrong InEdge list linking.");
alpar@800: }
alpar@800: 
alpar@800: ///\file
alpar@800: ///\todo Check head(), tail() as well;
alpar@800: 
alpar@800:   
alpar@800: } //namespace hugo
alpar@800: 
alpar@800: 
alpar@800: #endif