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 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=(iNodeIt 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=(iEdgeIt 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=(iInEdgeIt 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=(iOutEdgeIt 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 m(G); alpar@800: //Const map alpar@800: typename Graph::template NodeMap const &cm = m; alpar@800: //Inicialize with default value alpar@800: typename Graph::template NodeMap mdef(G,12); alpar@800: //Copy alpar@800: typename Graph::template NodeMap mm(cm); alpar@800: //Copy from another type alpar@800: typename Graph::template NodeMap 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::ValueType val; alpar@800: val=1; alpar@800: typename Graph::template NodeMap::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 m(G); alpar@800: typename Graph::template NodeMap const &cm = m; //Const map alpar@800: //Inicialize with default value alpar@800: typename Graph::template NodeMap mdef(G,12); alpar@800: typename Graph::template NodeMap mm(cm); //Copy alpar@800: typename Graph::template NodeMap 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::ValueType val; alpar@800: val=true; alpar@800: typename Graph::template NodeMap::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 m(G); alpar@800: typename Graph::template EdgeMap const &cm = m; //Const map alpar@800: //Inicialize with default value alpar@800: typename Graph::template EdgeMap mdef(G,12); alpar@800: typename Graph::template EdgeMap mm(cm); //Copy alpar@800: typename Graph::template EdgeMap 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::ValueType val; alpar@800: val=1; alpar@800: typename Graph::template EdgeMap::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 m(G); alpar@800: typename Graph::template EdgeMap const &cm = m; //Const map alpar@800: //Inicialize with default value alpar@800: typename Graph::template EdgeMap mdef(G,12); alpar@800: typename Graph::template EdgeMap mm(cm); //Copy alpar@800: typename Graph::template EdgeMap 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::ValueType val; alpar@800: val=true; alpar@800: typename Graph::template EdgeMap::KeyType key; alpar@800: key= typename Graph::EdgeIt(G); alpar@800: } alpar@800: } alpar@800: } alpar@800: alpar@800: template 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 void checkCompileGraphEraseEdge(Graph &G) alpar@800: { alpar@800: typename Graph::Edge e; alpar@800: G.erase(e); alpar@800: } alpar@800: alpar@800: template void checkCompileGraphEraseNode(Graph &G) alpar@800: { alpar@800: typename Graph::Node n; alpar@800: G.erase(n); alpar@800: } alpar@800: alpar@800: template 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 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 void checkGraphNodeList(Graph &G, int nn) alpar@800: { alpar@800: typename Graph::NodeIt n(G); alpar@800: for(int i=0;i 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 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 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