[Lemon-commits] Akos Ladanyi: Test for euler.h (#65)

Lemon HG hg at lemon.cs.elte.hu
Mon Feb 23 12:32:18 CET 2009


details:   http://lemon.cs.elte.hu/hg/lemon/rev/22f932bbb305
changeset: 538:22f932bbb305
user:      Akos Ladanyi <ladanyi [at] tmit.bme.hu>
date:      Mon Nov 03 11:59:54 2008 +0000
description:
	Test for euler.h (#65)

diffstat:

5 files changed, 157 insertions(+), 3 deletions(-)
lemon/Makefile.am   |    1 
lemon/euler.h       |    3 -
test/CMakeLists.txt |    1 
test/Makefile.am    |    2 
test/euler_test.cc  |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++

diffs (226 lines):

diff --git a/lemon/Makefile.am b/lemon/Makefile.am
--- a/lemon/Makefile.am
+++ b/lemon/Makefile.am
@@ -54,6 +54,7 @@
 	lemon/clp.h \
 	lemon/color.h \
 	lemon/concept_check.h \
+	lemon/connectivity.h \
 	lemon/counter.h \
 	lemon/core.h \
 	lemon/cplex.h \
diff --git a/lemon/euler.h b/lemon/euler.h
--- a/lemon/euler.h
+++ b/lemon/euler.h
@@ -54,7 +54,6 @@
   ///\endcode
   ///If \c g is not Euler then the resulted tour will not be full or closed.
   ///\sa EulerIt
-  ///\todo Test required
   template<class Digraph>
   class DiEulerIt
   {
@@ -146,7 +145,6 @@
   ///
   ///If \c g is not Euler then the resulted tour will not be full or closed.
   ///\sa EulerIt
-  ///\todo Test required
   template<class Digraph>
   class EulerIt
   {
@@ -240,7 +238,6 @@
   ///and only if it is connected and the number of incident arcs is even
   ///for each node. <em>Therefore, there are digraphs which are not Eulerian,
   ///but still have an Euler tour</em>.
-  ///\todo Test required
   template<class Digraph>
 #ifdef DOXYGEN
   bool
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -20,6 +20,7 @@
   dim_test
   edge_set_test
   error_test
+  euler_test
   graph_copy_test
   graph_test
   graph_utils_test
diff --git a/test/Makefile.am b/test/Makefile.am
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,6 +16,7 @@
 	test/dim_test \
 	test/edge_set_test \
 	test/error_test \
+	test/euler_test \
 	test/graph_copy_test \
 	test/graph_test \
 	test/graph_utils_test \
@@ -54,6 +55,7 @@
 test_dim_test_SOURCES = test/dim_test.cc
 test_edge_set_test_SOURCES = test/edge_set_test.cc
 test_error_test_SOURCES = test/error_test.cc
+test_euler_test_SOURCES = test/euler_test.cc
 test_graph_copy_test_SOURCES = test/graph_copy_test.cc
 test_graph_test_SOURCES = test/graph_test.cc
 test_graph_utils_test_SOURCES = test/graph_utils_test.cc
diff --git a/test/euler_test.cc b/test/euler_test.cc
new file mode 100644
--- /dev/null
+++ b/test/euler_test.cc
@@ -0,0 +1,153 @@
+/* -*- mode: C++; indent-tabs-mode: nil; -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library.
+ *
+ * Copyright (C) 2003-2009
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#include <lemon/euler.h>
+#include <lemon/list_graph.h>
+#include <test/test_tools.h>
+
+using namespace lemon;
+
+template <typename Digraph>
+void checkDiEulerIt(const Digraph& g)
+{
+  typename Digraph::template ArcMap<int> visitationNumber(g);
+
+  DiEulerIt<Digraph> e(g);
+  typename Digraph::Node firstNode = g.source(e);
+  typename Digraph::Node lastNode;
+
+  for (; e != INVALID; ++e)
+  {
+    if (e != INVALID)
+    {
+      lastNode = g.target(e);
+    }
+    ++visitationNumber[e];
+  }
+
+  check(firstNode == lastNode,
+      "checkDiEulerIt: first and last node are not the same");
+
+  for (typename Digraph::ArcIt a(g); a != INVALID; ++a)
+  {
+    check(visitationNumber[a] == 1,
+        "checkDiEulerIt: not visited or multiple times visited arc found");
+  }
+}
+
+template <typename Graph>
+void checkEulerIt(const Graph& g)
+{
+  typename Graph::template EdgeMap<int> visitationNumber(g);
+
+  EulerIt<Graph> e(g);
+  typename Graph::Node firstNode = g.u(e);
+  typename Graph::Node lastNode;
+
+  for (; e != INVALID; ++e)
+  {
+    if (e != INVALID)
+    {
+      lastNode = g.v(e);
+    }
+    ++visitationNumber[e];
+  }
+
+  check(firstNode == lastNode,
+      "checkEulerIt: first and last node are not the same");
+
+  for (typename Graph::EdgeIt e(g); e != INVALID; ++e)
+  {
+    check(visitationNumber[e] == 1,
+        "checkEulerIt: not visited or multiple times visited edge found");
+  }
+}
+
+int main()
+{
+  typedef ListDigraph Digraph;
+  typedef ListGraph Graph;
+
+  Digraph digraphWithEulerianCircuit;
+  {
+    Digraph& g = digraphWithEulerianCircuit;
+
+    Digraph::Node n0 = g.addNode();
+    Digraph::Node n1 = g.addNode();
+    Digraph::Node n2 = g.addNode();
+
+    g.addArc(n0, n1);
+    g.addArc(n1, n0);
+    g.addArc(n1, n2);
+    g.addArc(n2, n1);
+  }
+
+  Digraph digraphWithoutEulerianCircuit;
+  {
+    Digraph& g = digraphWithoutEulerianCircuit;
+
+    Digraph::Node n0 = g.addNode();
+    Digraph::Node n1 = g.addNode();
+    Digraph::Node n2 = g.addNode();
+
+    g.addArc(n0, n1);
+    g.addArc(n1, n0);
+    g.addArc(n1, n2);
+  }
+
+  Graph graphWithEulerianCircuit;
+  {
+    Graph& g = graphWithEulerianCircuit;
+
+    Graph::Node n0 = g.addNode();
+    Graph::Node n1 = g.addNode();
+    Graph::Node n2 = g.addNode();
+
+    g.addEdge(n0, n1);
+    g.addEdge(n1, n2);
+    g.addEdge(n2, n0);
+  }
+
+  Graph graphWithoutEulerianCircuit;
+  {
+    Graph& g = graphWithoutEulerianCircuit;
+
+    Graph::Node n0 = g.addNode();
+    Graph::Node n1 = g.addNode();
+    Graph::Node n2 = g.addNode();
+
+    g.addEdge(n0, n1);
+    g.addEdge(n1, n2);
+  }
+
+  checkDiEulerIt(digraphWithEulerianCircuit);
+
+  checkEulerIt(graphWithEulerianCircuit);
+
+  check(eulerian(digraphWithEulerianCircuit),
+      "this graph should have an Eulerian circuit");
+  check(!eulerian(digraphWithoutEulerianCircuit),
+      "this graph should not have an Eulerian circuit");
+
+  check(eulerian(graphWithEulerianCircuit),
+      "this graph should have an Eulerian circuit");
+  check(!eulerian(graphWithoutEulerianCircuit),
+      "this graph should have an Eulerian circuit");
+
+  return 0;
+}



More information about the Lemon-commits mailing list