[Lemon-commits] Alpar Juttner: Tests and bugfixes for the STL st...
Lemon HG
hg at lemon.cs.elte.hu
Tue Apr 14 20:42:49 CEST 2015
details: http://lemon.cs.elte.hu/hg/lemon/rev/4add05447ca0
changeset: 1337:4add05447ca0
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Tue Apr 14 08:39:40 2015 +0200
description:
Tests and bugfixes for the STL style iterators (#325)
diffstat:
CMakeLists.txt | 4 +-
lemon/bellman_ford.h | 4 +-
lemon/bits/edge_set_extender.h | 33 +++++++
lemon/bits/graph_adaptor_extender.h | 10 +-
lemon/config.h.in | 2 +
lemon/list_graph.h | 4 +-
test/bellman_ford_test.cc | 4 +
test/graph_test.h | 166 ++++++++++++++++++++++++++++++++++++
test/lp_test.cc | 12 ++-
test/maps_test.cc | 43 +++++++++
10 files changed, 270 insertions(+), 12 deletions(-)
diffs (truncated from 556 to 300 lines):
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -264,8 +264,8 @@
INCLUDE(CheckCXXCompilerFlag)
-CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11FLAG)
-IF(CXX11FLAG)
+CHECK_CXX_COMPILER_FLAG("-std=c++11" LEMON_CXX11)
+IF(LEMON_CXX11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ENDIF()
diff --git a/lemon/bellman_ford.h b/lemon/bellman_ford.h
--- a/lemon/bellman_ford.h
+++ b/lemon/bellman_ford.h
@@ -701,8 +701,8 @@
/// like an STL container (by having begin() and end())
/// which you can use in range-based for loops, STL algorithms, etc.
LemonRangeWrapper1<ActiveIt, BellmanFord>
- activeNodes(const BellmanFord& algorithm) const {
- return LemonRangeWrapper1<ActiveIt, BellmanFord>(algorithm);
+ activeNodes() const {
+ return LemonRangeWrapper1<ActiveIt, BellmanFord>(*this);
}
diff --git a/lemon/bits/edge_set_extender.h b/lemon/bits/edge_set_extender.h
--- a/lemon/bits/edge_set_extender.h
+++ b/lemon/bits/edge_set_extender.h
@@ -113,6 +113,9 @@
};
+ LemonRangeWrapper1<NodeIt, Digraph> nodes() const {
+ return LemonRangeWrapper1<NodeIt, Digraph>(*this);
+ }
class ArcIt : public Arc {
const Digraph* digraph;
@@ -136,6 +139,9 @@
};
+ LemonRangeWrapper1<ArcIt, Digraph> arcs() const {
+ return LemonRangeWrapper1<ArcIt, Digraph>(*this);
+ }
class OutArcIt : public Arc {
const Digraph* digraph;
@@ -160,6 +166,9 @@
};
+ LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const {
+ return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u);
+ }
class InArcIt : public Arc {
const Digraph* digraph;
@@ -184,6 +193,10 @@
};
+ LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const {
+ return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u);
+ }
+
// \brief Base node of the iterator
//
// Returns the base node (ie. the source in this case) of the iterator
@@ -372,6 +385,9 @@
};
+ LemonRangeWrapper1<NodeIt, Graph> nodes() const {
+ return LemonRangeWrapper1<NodeIt, Graph>(*this);
+ }
class ArcIt : public Arc {
const Graph* graph;
@@ -395,6 +411,9 @@
};
+ LemonRangeWrapper1<ArcIt, Graph> arcs() const {
+ return LemonRangeWrapper1<ArcIt, Graph>(*this);
+ }
class OutArcIt : public Arc {
const Graph* graph;
@@ -419,6 +438,9 @@
};
+ LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const {
+ return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u);
+ }
class InArcIt : public Arc {
const Graph* graph;
@@ -443,6 +465,9 @@
};
+ LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const {
+ return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u);
+ }
class EdgeIt : public Parent::Edge {
const Graph* graph;
@@ -466,6 +491,10 @@
};
+ LemonRangeWrapper1<EdgeIt, Graph> edges() const {
+ return LemonRangeWrapper1<EdgeIt, Graph>(*this);
+ }
+
class IncEdgeIt : public Parent::Edge {
friend class EdgeSetExtender;
const Graph* graph;
@@ -491,6 +520,10 @@
}
};
+ LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const {
+ return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u);
+ }
+
// \brief Base node of the iterator
//
// Returns the base node (ie. the source in this case) of the iterator
diff --git a/lemon/bits/graph_adaptor_extender.h b/lemon/bits/graph_adaptor_extender.h
--- a/lemon/bits/graph_adaptor_extender.h
+++ b/lemon/bits/graph_adaptor_extender.h
@@ -85,7 +85,7 @@
};
- LemonRangeWrapper1<NodeIt, Adaptor> nodes() {
+ LemonRangeWrapper1<NodeIt, Adaptor> nodes() const {
return LemonRangeWrapper1<NodeIt, Adaptor>(*this);
}
@@ -111,7 +111,7 @@
};
- LemonRangeWrapper1<ArcIt, Adaptor> arcs() {
+ LemonRangeWrapper1<ArcIt, Adaptor> arcs() const {
return LemonRangeWrapper1<ArcIt, Adaptor>(*this);
}
@@ -269,7 +269,7 @@
};
- LemonRangeWrapper1<NodeIt, Adaptor> nodes() {
+ LemonRangeWrapper1<NodeIt, Adaptor> nodes() const {
return LemonRangeWrapper1<NodeIt, Adaptor>(*this);
}
@@ -296,7 +296,7 @@
};
- LemonRangeWrapper1<ArcIt, Adaptor> arcs() {
+ LemonRangeWrapper1<ArcIt, Adaptor> arcs() const {
return LemonRangeWrapper1<ArcIt, Adaptor>(*this);
}
@@ -378,7 +378,7 @@
};
- LemonRangeWrapper1<EdgeIt, Adaptor> edges() {
+ LemonRangeWrapper1<EdgeIt, Adaptor> edges() const {
return LemonRangeWrapper1<EdgeIt, Adaptor>(*this);
}
diff --git a/lemon/config.h.in b/lemon/config.h.in
--- a/lemon/config.h.in
+++ b/lemon/config.h.in
@@ -1,6 +1,8 @@
#define LEMON_VERSION "@PROJECT_VERSION@"
#cmakedefine LEMON_HAVE_LONG_LONG 1
+#cmakedefine LEMON_CXX11 1
+
#cmakedefine LEMON_HAVE_LP 1
#cmakedefine LEMON_HAVE_MIP 1
#cmakedefine LEMON_HAVE_GLPK 1
diff --git a/lemon/list_graph.h b/lemon/list_graph.h
--- a/lemon/list_graph.h
+++ b/lemon/list_graph.h
@@ -1209,7 +1209,7 @@
///
ListGraph() {}
- typedef Parent::OutArcIt IncEdgeIt;
+ typedef Parent::IncEdgeIt IncEdgeIt;
/// \brief Add a new node to the graph.
///
@@ -2136,7 +2136,7 @@
///
ListBpGraph() {}
- typedef Parent::OutArcIt IncEdgeIt;
+ typedef Parent::IncEdgeIt IncEdgeIt;
/// \brief Add a new red node to the graph.
///
diff --git a/test/bellman_ford_test.cc b/test/bellman_ford_test.cc
--- a/test/bellman_ford_test.cc
+++ b/test/bellman_ford_test.cc
@@ -101,6 +101,10 @@
pp = const_bf_test.negativeCycle();
for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
+ for (auto n: const_bf_test.activeNodes()) { ::lemon::ignore_unused_variable_warning(n); }
+ for (Digraph::Node n: const_bf_test.activeNodes()) {
+ ::lemon::ignore_unused_variable_warning(n);
+ }
}
{
BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
diff --git a/test/graph_test.h b/test/graph_test.h
--- a/test/graph_test.h
+++ b/test/graph_test.h
@@ -38,6 +38,27 @@
}
check(n==INVALID,"Wrong Node list linking.");
check(countNodes(G)==cnt,"Wrong Node number.");
+
+#ifdef LEMON_CXX11
+ {
+ typename Graph::NodeIt n(G);
+ for(auto u: G.nodes())
+ {
+ check(n==u,"Wrong STL Node iterator.");
+ ++n;
+ }
+ check(n==INVALID,"Wrong STL Node iterator.");
+ }
+ {
+ typename Graph::NodeIt n(G);
+ for(typename Graph::Node u: G.nodes())
+ {
+ check(n==u,"Wrong STL Node iterator.");
+ ++n;
+ }
+ check(n==INVALID,"Wrong STL Node iterator.");
+ }
+#endif
}
template<class Graph>
@@ -56,6 +77,26 @@
}
check(n==INVALID,"Wrong red Node list linking.");
check(countRedNodes(G)==cnt,"Wrong red Node number.");
+#ifdef LEMON_CXX11
+ {
+ typename Graph::RedNodeIt n(G);
+ for(auto u: G.redNodes())
+ {
+ check(n==u,"Wrong STL RedNode iterator.");
+ ++n;
+ }
+ check(n==INVALID,"Wrong STL RedNode iterator.");
+ }
+ {
+ typename Graph::RedNodeIt n(G);
+ for(typename Graph::RedNode u: G.redNodes())
+ {
+ check(n==u,"Wrong STL RedNode iterator.");
+ ++n;
+ }
+ check(n==INVALID,"Wrong STL RedNode iterator.");
+ }
+#endif
}
template<class Graph>
@@ -74,6 +115,27 @@
}
check(n==INVALID,"Wrong blue Node list linking.");
check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
+#ifdef LEMON_CXX11
+ {
+ typename Graph::BlueNodeIt n(G);
+ for(auto u: G.blueNodes())
+ {
+ check(n==u,"Wrong STL BlueNode iterator.");
+ ++n;
+ }
+ check(n==INVALID,"Wrong STL BlueNode iterator.");
More information about the Lemon-commits
mailing list