COIN-OR::LEMON - Graph Library

Changeset 774:4297098d9677 in lemon-0.x for src/test/graph_test.cc


Ignore:
Timestamp:
08/30/04 14:01:47 (20 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1066
Message:

Merge back the whole branches/hugo++ to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/test/graph_test.cc

    r733 r774  
    77#include"test_tools.h"
    88
    9 /*
     9/**
     10\file
    1011This test makes consistency checks of list graph structures.
    1112
    12 G.addNode(), G.addEdge(), G.valid(), G.tail(), G.head()
     13G.addNode(), G.addEdge(), G.tail(), G.head()
    1314
    1415\todo Checks for empty graphs and isolated points.
     16\todo Checks for Node->NodeIt, Edge->{EdgeIt,InEdgeIt,OutEdgeIt}
     17conversion.
    1518*/
    1619
     
    3033    Node i; Node j(i); Node k(INVALID);
    3134    i=j;
    32     bool b=G.valid(i); b=b;
     35    //    bool b=G.valid(i); b=b;
     36    bool b; b=b;
     37    b=(i==INVALID); b=(i!=INVALID);
    3338    b=(i==j); b=(i!=j); b=(i<j);
    3439  }
     
    3742    i=j;
    3843    j=G.first(i);
    39     j=G.next(i);
    40     bool b=G.valid(i); b=b;
     44    j=++i;
     45    //    bool b=G.valid(i); b=b;
     46    bool b; b=b;
     47    b=(i==INVALID); b=(i!=INVALID);
    4148    Node n(i);
    4249    n=i;
    4350    b=(i==j); b=(i!=j); b=(i<j);
     51    //Node ->NodeIt conversion
     52    NodeIt ni(G,n);
    4453  }
    4554  {
    4655    Edge i; Edge j(i); Edge k(INVALID);
    4756    i=j;
    48     bool b=G.valid(i); b=b;
     57    //    bool b=G.valid(i); b=b;
     58    bool b; b=b;
     59    b=(i==INVALID); b=(i!=INVALID);
    4960    b=(i==j); b=(i!=j); b=(i<j);
    5061  }
     
    5364    i=j;
    5465    j=G.first(i);
    55     j=G.next(i);
    56     bool b=G.valid(i); b=b;
     66    j=++i;
     67    //    bool b=G.valid(i); b=b;
     68    bool b; b=b;
     69    b=(i==INVALID); b=(i!=INVALID);
    5770    Edge e(i);
    5871    e=i;
    5972    b=(i==j); b=(i!=j); b=(i<j);
     73    //Edge ->EdgeIt conversion
     74    EdgeIt ei(G,e);
    6075  }
    6176  {
     
    6479    i=j;
    6580    j=G.first(i,n);
    66     j=G.next(i);
    67     bool b=G.valid(i); b=b;
     81    j=++i;
     82    //    bool b=G.valid(i); b=b;
     83    bool b; b=b;
     84    b=(i==INVALID); b=(i!=INVALID);
    6885    Edge e(i);
    6986    e=i;
    7087    b=(i==j); b=(i!=j); b=(i<j);
     88    //Edge ->InEdgeIt conversion
     89    InEdgeIt ei(G,e);
    7190  }
    7291  {
     
    7594    i=j;
    7695    j=G.first(i,n);
    77     j=G.next(i);
    78     bool b=G.valid(i); b=b;
     96    j=++i;
     97    //    bool b=G.valid(i); b=b;
     98    bool b; b=b;
     99    b=(i==INVALID); b=(i!=INVALID);
    79100    Edge e(i);
    80101    e=i;
    81102    b=(i==j); b=(i!=j); b=(i<j);
    82   }
    83 
    84   Node n,m;
    85   n=m=INVALID;
    86   Edge e;
    87   e=INVALID;
    88   n=G.tail(e);
    89   n=G.head(e);
    90 
    91   //aNode, bNode ?
    92 
     103    //Edge ->OutEdgeIt conversion
     104    OutEdgeIt ei(G,e);
     105  }
     106  {
     107    Node n,m;
     108    n=m=INVALID;
     109    Edge e;
     110    e=INVALID;
     111    n=G.tail(e);
     112    n=G.head(e);
     113  }
    93114  // id tests
    94   { int i=G.id(n); i=i; }
    95   { int i=G.id(e); i=i; }
    96  
    97   //  G.clear();
    98 
     115  { Node n; int i=G.id(n); i=i; }
     116  { Edge e; int i=G.id(e); i=i; }
    99117  //NodeMap tests
    100118  {
    101119    Node k;
    102120    typename Graph::template NodeMap<int> m(G);
    103     typename Graph::template NodeMap<int> const &cm = m;  //Const map
     121    //Const map
     122    typename Graph::template NodeMap<int> const &cm = m;
    104123    //Inicialize with default value
    105124    typename Graph::template NodeMap<int> mdef(G,12);
    106     typename Graph::template NodeMap<int> mm(cm);   //Copy
    107     typename Graph::template NodeMap<double> dm(cm); //Copy from another type
     125    //Copy
     126    typename Graph::template NodeMap<int> mm(cm);
     127    //Copy from another type
     128    typename Graph::template NodeMap<double> dm(cm);
    108129    int v;
    109130    v=m[k]; m[k]=v; m.set(k,v);
     
    161182    m=dm; //Copy to another type
    162183  }
    163  
    164184}
    165185
     
    178198  n=G.addNode();
    179199  m=G.addNode();
    180  
    181   G.addEdge(n,m);
     200  Edge e;
     201  e=G.addEdge(n,m);
     202 
     203  //  G.clear();
     204}
     205
     206template<class Graph> void checkCompileErase(Graph &G)
     207{
     208  typedef typename Graph::Node Node;
     209  typedef typename Graph::Edge Edge;
     210  Node n;
     211  Edge e;
     212  G.erase(n);
     213  G.erase(e);
     214}
     215
     216template<class Graph> void checkCompileEraseEdge(Graph &G)
     217{
     218  typedef typename Graph::Edge Edge;
     219  Edge e;
     220  G.erase(e);
     221}
     222
     223template<class Graph> void checkCompileFindEdge(Graph &G)
     224{
     225  typedef typename Graph::NodeIt Node;
     226  typedef typename Graph::NodeIt NodeIt;
     227
     228  G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
     229  G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); 
    182230}
    183231
     
    187235  typename Graph::NodeIt n(G);
    188236  for(int i=0;i<nn;i++) {
    189     check(G.valid(n),"Wrong Node list linking.");
    190     G.next(n);
    191   }
    192   check(!G.valid(n),"Wrong Node list linking.");
     237    check(n!=INVALID,"Wrong Node list linking.");
     238    ++n;
     239  }
     240  check(n==INVALID,"Wrong Node list linking.");
    193241}
    194242
     
    199247  EdgeIt e(G);
    200248  for(int i=0;i<nn;i++) {
    201     check(G.valid(e),"Wrong Edge list linking.");
    202     G.next(e);
    203   }
    204   check(!G.valid(e),"Wrong Edge list linking.");
     249    check(e!=INVALID,"Wrong Edge list linking.");
     250    ++e;
     251  }
     252  check(e==INVALID,"Wrong Edge list linking.");
    205253}
    206254
     
    211259  typename Graph::OutEdgeIt e(G,n);
    212260  for(int i=0;i<nn;i++) {
    213     check(G.valid(e),"Wrong OutEdge list linking.");
    214     G.next(e);
    215   }
    216   check(!G.valid(e),"Wrong OutEdge list linking.");
     261    check(e!=INVALID,"Wrong OutEdge list linking.");
     262    ++e;
     263  }
     264  check(e==INVALID,"Wrong OutEdge list linking.");
    217265}
    218266
    219267template<class Graph> void checkInEdgeList(Graph &G,
    220                                             typename Graph::Node n,
    221                                             int nn)
     268                                           typename Graph::Node n,
     269                                           int nn)
    222270{
    223271  typename Graph::InEdgeIt e(G,n);
    224272  for(int i=0;i<nn;i++) {
    225     check(G.valid(e),"Wrong InEdge list linking.");
    226     G.next(e);
    227   }
    228   check(!G.valid(e),"Wrong InEdge list linking.");
    229 }
    230 
    231 //Checks head(), tail() as well;
     273    check(e!=INVALID,"Wrong InEdge list linking.");
     274    ++e;
     275  }
     276  check(e==INVALID,"Wrong InEdge list linking.");
     277}
     278
     279///\file
     280///\todo Checks head(), tail() as well;
     281
    232282template<class Graph> void bidirPetersen(Graph &G)
    233283{
     
    239289  std::vector<Edge> ee;
    240290 
    241   for(EdgeIt e(G);G.valid(e);G.next(e)) ee.push_back(e);
     291  for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
    242292
    243293  for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
     
    255305  checkEdgeList(G,30);
    256306
    257   for(NodeIt n(G);G.valid(n);G.next(n)) {
     307  for(NodeIt n(G);n!=INVALID;++n) {
    258308    checkInEdgeList(G,n,3);
    259309    checkOutEdgeList(G,n,3);
    260     G.next(n);
     310    ++n;
    261311  } 
    262312}
    263313
    264 template
     314//Compile GraphSkeleton
     315template
    265316void checkCompileStaticGraph<StaticGraphSkeleton>(StaticGraphSkeleton &);
    266317template void checkCompile<GraphSkeleton>(GraphSkeleton &);
    267 
     318template
     319void checkCompileErase<EraseableGraphSkeleton>(EraseableGraphSkeleton &);
     320
     321//Compile SmartGraph
    268322template void checkCompile<SmartGraph>(SmartGraph &);
     323//Compile SymSmartGraph
    269324template void checkCompile<SymSmartGraph>(SymSmartGraph &);
     325
     326//Compile ListGraph
    270327template void checkCompile<ListGraph>(ListGraph &);
     328template void checkCompileErase<ListGraph>(ListGraph &);
     329template void checkCompileFindEdge<ListGraph>(ListGraph &);
     330
     331//Compile SymListGraph
    271332template void checkCompile<SymListGraph>(SymListGraph &);
     333template void checkCompileErase<SymListGraph>(SymListGraph &);
     334template void checkCompileFindEdge<SymListGraph>(SymListGraph &);
     335
     336//Compile FullGraph
    272337template void checkCompileStaticGraph<FullGraph>(FullGraph &);
    273 
     338template void checkCompileFindEdge<FullGraph>(FullGraph &);
     339
     340//Compile EdgeSet <ListGraph>
    274341template void checkCompile<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
     342template
     343void checkCompileEraseEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
     344template
     345void checkCompileFindEdge<EdgeSet <ListGraph> >(EdgeSet <ListGraph> &);
     346
     347//Compile EdgeSet <NodeSet>
    275348template void checkCompile<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
     349template
     350void checkCompileEraseEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
     351template void checkCompileFindEdge<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
     352
    276353
    277354int main()
     
    300377  }
    301378
    302   //\todo map tests.
    303   //\todo copy constr tests.
     379  ///\file
     380  ///\todo map tests.
     381  ///\todo copy constr tests.
    304382
    305383  std::cout << __FILE__ ": All tests passed.\n";
Note: See TracChangeset for help on using the changeset viewer.