COIN-OR::LEMON - Graph Library

Changeset 1337:4add05447ca0 in lemon


Ignore:
Timestamp:
04/14/15 08:39:40 (9 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Tests and bugfixes for the STL style iterators (#325)

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r1336 r1337  
    265265
    266266INCLUDE(CheckCXXCompilerFlag)
    267 CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11FLAG)
    268 IF(CXX11FLAG)
     267CHECK_CXX_COMPILER_FLAG("-std=c++11" LEMON_CXX11)
     268IF(LEMON_CXX11)
    269269  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    270270ENDIF()
  • lemon/bellman_ford.h

    r1336 r1337  
    702702    /// which you can use in range-based for loops, STL algorithms, etc.
    703703    LemonRangeWrapper1<ActiveIt, BellmanFord>
    704         activeNodes(const BellmanFord& algorithm) const {
    705       return LemonRangeWrapper1<ActiveIt, BellmanFord>(algorithm);
     704    activeNodes() const {
     705      return LemonRangeWrapper1<ActiveIt, BellmanFord>(*this);
    706706    }
    707707
  • lemon/bits/edge_set_extender.h

    r1270 r1337  
    114114    };
    115115
     116    LemonRangeWrapper1<NodeIt, Digraph> nodes() const {
     117      return LemonRangeWrapper1<NodeIt, Digraph>(*this);
     118    }
    116119
    117120    class ArcIt : public Arc {
     
    137140    };
    138141
     142    LemonRangeWrapper1<ArcIt, Digraph> arcs() const {
     143      return LemonRangeWrapper1<ArcIt, Digraph>(*this);
     144    }
    139145
    140146    class OutArcIt : public Arc {
     
    161167    };
    162168
     169    LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const {
     170      return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u);
     171    }
    163172
    164173    class InArcIt : public Arc {
     
    184193
    185194    };
     195
     196    LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const {
     197      return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u);
     198    }
    186199
    187200    // \brief Base node of the iterator
     
    373386    };
    374387
     388    LemonRangeWrapper1<NodeIt, Graph> nodes() const {
     389      return LemonRangeWrapper1<NodeIt, Graph>(*this);
     390    }
    375391
    376392    class ArcIt : public Arc {
     
    396412    };
    397413
     414    LemonRangeWrapper1<ArcIt, Graph> arcs() const {
     415      return LemonRangeWrapper1<ArcIt, Graph>(*this);
     416    }
    398417
    399418    class OutArcIt : public Arc {
     
    420439    };
    421440
     441    LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const {
     442      return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u);
     443    }
    422444
    423445    class InArcIt : public Arc {
     
    444466    };
    445467
     468    LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const {
     469      return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u);
     470    }
    446471
    447472    class EdgeIt : public Parent::Edge {
     
    466491
    467492    };
     493
     494    LemonRangeWrapper1<EdgeIt, Graph> edges() const {
     495      return LemonRangeWrapper1<EdgeIt, Graph>(*this);
     496    }
    468497
    469498    class IncEdgeIt : public Parent::Edge {
     
    491520      }
    492521    };
     522
     523    LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const {
     524      return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u);
     525    }
    493526
    494527    // \brief Base node of the iterator
  • lemon/bits/graph_adaptor_extender.h

    r1336 r1337  
    8686    };
    8787
    88     LemonRangeWrapper1<NodeIt, Adaptor> nodes() {
     88    LemonRangeWrapper1<NodeIt, Adaptor> nodes() const {
    8989      return LemonRangeWrapper1<NodeIt, Adaptor>(*this);
    9090    }
     
    112112    };
    113113
    114     LemonRangeWrapper1<ArcIt, Adaptor> arcs() {
     114    LemonRangeWrapper1<ArcIt, Adaptor> arcs() const {
    115115      return LemonRangeWrapper1<ArcIt, Adaptor>(*this);
    116116    }
     
    270270    };
    271271
    272     LemonRangeWrapper1<NodeIt, Adaptor> nodes() {
     272    LemonRangeWrapper1<NodeIt, Adaptor> nodes() const {
    273273      return LemonRangeWrapper1<NodeIt, Adaptor>(*this);
    274274    }
     
    297297    };
    298298
    299     LemonRangeWrapper1<ArcIt, Adaptor> arcs() {
     299    LemonRangeWrapper1<ArcIt, Adaptor> arcs() const {
    300300      return LemonRangeWrapper1<ArcIt, Adaptor>(*this);
    301301    }
     
    379379    };
    380380
    381     LemonRangeWrapper1<EdgeIt, Adaptor> edges() {
     381    LemonRangeWrapper1<EdgeIt, Adaptor> edges() const {
    382382      return LemonRangeWrapper1<EdgeIt, Adaptor>(*this);
    383383    }
  • lemon/config.h.in

    r1306 r1337  
    11#define LEMON_VERSION "@PROJECT_VERSION@"
    22#cmakedefine LEMON_HAVE_LONG_LONG 1
     3
     4#cmakedefine LEMON_CXX11 1
    35
    46#cmakedefine LEMON_HAVE_LP 1
  • lemon/list_graph.h

    r1336 r1337  
    12101210    ListGraph() {}
    12111211
    1212     typedef Parent::OutArcIt IncEdgeIt;
     1212    typedef Parent::IncEdgeIt IncEdgeIt;
    12131213
    12141214    /// \brief Add a new node to the graph.
     
    21372137    ListBpGraph() {}
    21382138
    2139     typedef Parent::OutArcIt IncEdgeIt;
     2139    typedef Parent::IncEdgeIt IncEdgeIt;
    21402140
    21412141    /// \brief Add a new red node to the graph.
  • test/bellman_ford_test.cc

    r1270 r1337  
    102102
    103103    for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
     104    for (auto n: const_bf_test.activeNodes()) { ::lemon::ignore_unused_variable_warning(n); }
     105    for (Digraph::Node n: const_bf_test.activeNodes()) {
     106      ::lemon::ignore_unused_variable_warning(n);
     107    }
    104108  }
    105109  {
  • test/graph_test.h

    r1270 r1337  
    3939    check(n==INVALID,"Wrong Node list linking.");
    4040    check(countNodes(G)==cnt,"Wrong Node number.");
     41
     42#ifdef LEMON_CXX11
     43    {
     44      typename Graph::NodeIt n(G);
     45      for(auto u: G.nodes())
     46        {
     47          check(n==u,"Wrong STL Node iterator.");
     48          ++n;
     49        }
     50      check(n==INVALID,"Wrong STL Node iterator.");
     51    }
     52    {
     53      typename Graph::NodeIt n(G);
     54      for(typename Graph::Node u: G.nodes())
     55        {
     56          check(n==u,"Wrong STL Node iterator.");
     57          ++n;
     58        }
     59      check(n==INVALID,"Wrong STL Node iterator.");
     60    }
     61#endif
    4162  }
    4263
     
    5778    check(n==INVALID,"Wrong red Node list linking.");
    5879    check(countRedNodes(G)==cnt,"Wrong red Node number.");
     80#ifdef LEMON_CXX11
     81    {
     82      typename Graph::RedNodeIt n(G);
     83      for(auto u: G.redNodes())
     84        {
     85          check(n==u,"Wrong STL RedNode iterator.");
     86          ++n;
     87        }
     88      check(n==INVALID,"Wrong STL RedNode iterator.");
     89    }
     90    {
     91      typename Graph::RedNodeIt n(G);
     92      for(typename Graph::RedNode u: G.redNodes())
     93        {
     94          check(n==u,"Wrong STL RedNode iterator.");
     95          ++n;
     96        }
     97      check(n==INVALID,"Wrong STL RedNode iterator.");
     98    }
     99#endif
    59100  }
    60101
     
    75116    check(n==INVALID,"Wrong blue Node list linking.");
    76117    check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
     118#ifdef LEMON_CXX11
     119    {
     120      typename Graph::BlueNodeIt n(G);
     121      for(auto u: G.blueNodes())
     122        {
     123          check(n==u,"Wrong STL BlueNode iterator.");
     124          ++n;
     125        }
     126      check(n==INVALID,"Wrong STL BlueNode iterator.");
     127    }
     128    {
     129      typename Graph::BlueNodeIt n(G);
     130      for(typename Graph::BlueNode u: G.blueNodes())
     131        {
     132          check(n==u,"Wrong STL BlueNode iterator.");
     133          ++n;
     134        }
     135      check(n==INVALID,"Wrong STL BlueNode iterator.");
     136    }
     137#endif
     138
    77139  }
    78140
     
    91153    check(e==INVALID,"Wrong Arc list linking.");
    92154    check(countArcs(G)==cnt,"Wrong Arc number.");
     155#ifdef LEMON_CXX11
     156    {
     157      typename Graph::ArcIt a(G);
     158      for(auto e: G.arcs())
     159        {
     160          check(a==e,"Wrong STL Arc iterator.");
     161          ++a;
     162        }
     163      check(a==INVALID,"Wrong STL Arc iterator.");
     164    }
     165    {
     166      typename Graph::ArcIt a(G);
     167      for(typename Graph::Arc e: G.arcs())
     168        {
     169          check(a==e,"Wrong STL Arc iterator.");
     170          ++a;
     171        }
     172      check(a==INVALID,"Wrong STL Arc iterator.");
     173    }
     174#endif
     175
    93176  }
    94177
     
    106189    check(e==INVALID,"Wrong OutArc list linking.");
    107190    check(countOutArcs(G,n)==cnt,"Wrong OutArc number.");
     191#ifdef LEMON_CXX11
     192    {
     193      typename Graph::OutArcIt a(G,n);
     194      for(auto e: G.outArcs(n))
     195        {
     196          check(a==e,"Wrong STL OutArc iterator.");
     197          ++a;
     198        }
     199      check(a==INVALID,"Wrong STL OutArc iterator.");
     200    }
     201    {
     202      typename Graph::OutArcIt a(G,n);
     203      for(typename Graph::Arc e: G.outArcs(n))
     204        {
     205          check(a==e,"Wrong STL OutArc iterator.");
     206          ++a;
     207        }
     208      check(a==INVALID,"Wrong STL OutArc iterator.");
     209    }
     210#endif
     211
    108212  }
    109213
     
    121225    check(e==INVALID,"Wrong InArc list linking.");
    122226    check(countInArcs(G,n)==cnt,"Wrong InArc number.");
     227#ifdef LEMON_CXX11
     228    {
     229      typename Graph::InArcIt a(G,n);
     230      for(auto e: G.inArcs(n))
     231        {
     232          check(a==e,"Wrong STL InArc iterator.");
     233          ++a;
     234        }
     235      check(a==INVALID,"Wrong STL InArc iterator.");
     236    }
     237    {
     238      typename Graph::InArcIt a(G,n);
     239      for(typename Graph::Arc e: G.inArcs(n))
     240        {
     241          check(a==e,"Wrong STL InArc iterator.");
     242          ++a;
     243        }
     244      check(a==INVALID,"Wrong STL InArc iterator.");
     245    }
     246#endif
    123247  }
    124248
     
    135259    check(e==INVALID,"Wrong Edge list linking.");
    136260    check(countEdges(G)==cnt,"Wrong Edge number.");
     261#ifdef LEMON_CXX11
     262    {
     263      typename Graph::EdgeIt a(G);
     264      for(auto e: G.edges())
     265        {
     266          check(a==e,"Wrong STL Edge iterator.");
     267          ++a;
     268        }
     269      check(a==INVALID,"Wrong STL Edge iterator.");
     270    }
     271    {
     272      typename Graph::EdgeIt a(G);
     273      for(typename Graph::Edge e: G.edges())
     274        {
     275          check(a==e,"Wrong STL Edge iterator.");
     276          ++a;
     277        }
     278      check(a==INVALID,"Wrong STL Edge iterator.");
     279    }
     280#endif
     281
    137282  }
    138283
     
    151296    check(e==INVALID,"Wrong IncEdge list linking.");
    152297    check(countIncEdges(G,n)==cnt,"Wrong IncEdge number.");
     298#ifdef LEMON_CXX11
     299    {
     300      typename Graph::IncEdgeIt a(G,n);
     301      for(auto e: G.incEdges(n))
     302        {
     303          check(a==e,"Wrong STL IncEdge iterator.");
     304          ++a;
     305        }
     306      check(a==INVALID,"Wrong STL IncEdge iterator.");
     307    }
     308    {
     309      typename Graph::IncEdgeIt a(G,n);
     310      for(typename Graph::Edge e: G.incEdges(n))
     311        {
     312          check(a==e,"Wrong STL IncEdge iterator.");
     313          ++a;
     314        }
     315      check(a==INVALID,"Wrong STL IncEdge iterator.");
     316    }
     317#endif
     318
    153319  }
    154320
  • test/lp_test.cc

    r1300 r1337  
    2121#include "test_tools.h"
    2222#include <lemon/tolerance.h>
    23 
     23#include <lemon/concept_check.h>
    2424#include <lemon/config.h>
    2525
     
    4848  int count=0;
    4949  for (LpBase::ColIt c(lp); c!=INVALID; ++c) ++count;
     50#ifdef LEMON_CXX11
     51  int cnt = 0;
     52  for(auto c: lp.cols()) { cnt++; ::lemon::ignore_unused_variable_warning(c); }
     53  check(count == cnt, "Wrong STL iterator");
     54#endif
    5055  return count;
    5156}
     
    5459  int count=0;
    5560  for (LpBase::RowIt r(lp); r!=INVALID; ++r) ++count;
     61#ifdef LEMON_CXX11
     62  int cnt = 0;
     63  for(auto r: lp.rows()) { cnt++; ::lemon::ignore_unused_variable_warning(r); }
     64  check(count == cnt, "Wrong STL iterator");
     65#endif
    5666  return count;
    5767}
  • test/maps_test.cc

    r1270 r1337  
    731731    check(n == 3, "Wrong number");
    732732    check(map1.falseNum() == 3, "Wrong number");
     733
     734#ifdef LEMON_CXX11
     735    {
     736      int c = 0;
     737      for(auto v: map1.items(false)) { c++; ::lemon::ignore_unused_variable_warning(v); }
     738      check(c == map1.falseNum(), "Wrong number");
     739    }
     740    {
     741      int c = 0;
     742      for(auto v: map1.items(true)) { c++; ::lemon::ignore_unused_variable_warning(v); }
     743      check(c == map1.trueNum(), "Wrong number");
     744    }
     745    {
     746      int c = 0;
     747      for(auto v: map1.falseKeys()) { c++; ::lemon::ignore_unused_variable_warning(v); }
     748      check(c == map1.falseNum(), "Wrong number");
     749    }
     750    {
     751      int c = 0;
     752      for(auto v: map1.trueKeys()) { c++; ::lemon::ignore_unused_variable_warning(v); }
     753      check(c == map1.trueNum(), "Wrong number");
     754    }
     755#endif
     756
    733757  }
    734758
     
    781805    }
    782806    check(n == num, "Wrong number");
     807#ifdef LEMON_CXX11
     808    {
     809      int c = 0;
     810      for(auto v: map1.items(0)) { c++; ::lemon::ignore_unused_variable_warning(v); }
     811      check(c == (num + 1) / 2, "Wrong number");
     812      for(auto v: map1.items(1)) { c++; ::lemon::ignore_unused_variable_warning(v); }
     813      check(c == num, "Wrong number");
     814    }
     815#endif
    783816
    784817  }
     
    839872    }
    840873    check(n == num, "Wrong number");
     874
     875#ifdef LEMON_CXX11
     876    {
     877      int c = 0;
     878      for(auto v: map1.items(0.0)) { c++; ::lemon::ignore_unused_variable_warning(v); }
     879      check(c == (num + 1) / 2, "Wrong number");
     880      for(auto v: map1.items(1.0)) { c++; ::lemon::ignore_unused_variable_warning(v); }
     881      check(c == num, "Wrong number");
     882    }
     883#endif
    841884
    842885  }
Note: See TracChangeset for help on using the changeset viewer.