[PPL-devel] [GIT] ppl/ppl(pip): Added a few tests for the PIP_Problem ascii_dump/ load methods.

Enea Zaffanella zaffanella at cs.unipr.it
Thu Nov 26 14:44:13 CET 2009


Module: ppl/ppl
Branch: pip
Commit: f83627a474666b6f7d31b4d54095b63c69e22862
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=f83627a474666b6f7d31b4d54095b63c69e22862

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Thu Nov 26 14:42:12 2009 +0100

Added a few tests for the PIP_Problem ascii_dump/load methods.

---

 tests/PIP_Problem/Makefile.am         |    6 +-
 tests/PIP_Problem/ascii_dump_load1.cc |  153 +++++++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+), 1 deletions(-)

diff --git a/tests/PIP_Problem/Makefile.am b/tests/PIP_Problem/Makefile.am
index a01d3af..5ec9c04 100644
--- a/tests/PIP_Problem/Makefile.am
+++ b/tests/PIP_Problem/Makefile.am
@@ -50,6 +50,7 @@ $(top_builddir)/src/libppl.la \
 @extra_libraries@
 
 TESTS = \
+ascii_dump_load1 \
 exceptions1 \
 pipproblem1 pipproblem2
 
@@ -61,6 +62,8 @@ BUGS =
 # Sources for the tests
 #
 
+ascii_dump_load1_SOURCES = ascii_dump_load1.cc
+
 exceptions1_SOURCES = exceptions1.cc
 
 pipproblem1_SOURCES = pipproblem1.cc
@@ -73,7 +76,8 @@ $(BUGS)
 
 #EXTRA_DIST =
 
-#MOSTLYCLEANFILES =
+MOSTLYCLEANFILES = \
+ascii_dump_load1.dat
 
 $(top_builddir)/utils/libppl_utils.a:
 	$(MAKE) $(AM_MAKEFLAGS) -C $(top_builddir)/utils libppl_utils.a
diff --git a/tests/PIP_Problem/ascii_dump_load1.cc b/tests/PIP_Problem/ascii_dump_load1.cc
new file mode 100644
index 0000000..18e8235
--- /dev/null
+++ b/tests/PIP_Problem/ascii_dump_load1.cc
@@ -0,0 +1,153 @@
+/* Test PIP_Problem::ascii_dump() and PIP_Problem::ascii_load().
+   Copyright (C) 2001-2009 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is part of the Parma Polyhedra Library (PPL).
+
+The PPL is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The PPL is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+
+For the most up-to-date information see the Parma Polyhedra Library
+site: http://www.cs.unipr.it/ppl/ . */
+
+#include "ppl_test.hh"
+
+#include "files.hh"
+#include <string>
+#include <fstream>
+
+using std::string;
+using std::fstream;
+using std::ios_base;
+
+namespace {
+
+bool
+test01() {
+  const char* my_file = "ascii_dump_load1.dat";
+
+  Variable A(0);
+  Constraint_System cs;
+  cs.insert(A >= 1);
+
+  PIP_Problem pip1(3, cs.begin(), cs.end(), Variables_Set());
+  pip1.clear();
+
+  fstream f;
+  open(f, my_file, ios_base::out);
+  pip1.ascii_dump(f);
+  close(f);
+
+  open(f, my_file, ios_base::in);
+  PIP_Problem pip2;
+  pip2.ascii_load(f);
+  close(f);
+
+  bool ok = pip1.space_dimension() == 0
+    && pip2.space_dimension() == 0
+    && pip1.constraints_begin() == pip1.constraints_end()
+    && pip2.constraints_begin() == pip2.constraints_end();
+
+  return ok;
+}
+
+bool
+test02() {
+  const char* my_file = "ascii_dump_load1.dat";
+
+  PIP_Problem pip1(3);
+  pip1.solve();
+
+  fstream f;
+  open(f, my_file, ios_base::out);
+  pip1.ascii_dump(f);
+  close(f);
+
+  open(f, my_file, ios_base::in);
+  PIP_Problem pip2;
+  pip2.ascii_load(f);
+  close(f);
+
+  bool ok = pip1.space_dimension() == 3
+    && pip2.space_dimension() == 3
+    && pip1.constraints_begin() == pip1.constraints_end()
+    && pip2.constraints_begin() == pip2.constraints_end();
+
+  return ok;
+}
+
+bool
+test03() {
+  const char* my_file = "ascii_dump_load1.dat";
+
+  Variable A(0);
+  Constraint_System cs;
+  cs.insert(A >= 1);
+  cs.insert(A <= 0);
+
+  PIP_Problem pip1(1, cs.begin(), cs.end(), Variables_Set());
+  pip1.set_control_parameter(PIP_Problem::CUTTING_STRATEGY_DEEPEST);
+  pip1.solve();
+
+  fstream f;
+  open(f, my_file, ios_base::out);
+  pip1.ascii_dump(f);
+  close(f);
+
+  open(f, my_file, ios_base::in);
+  PIP_Problem pip2;
+  pip2.ascii_load(f);
+  close(f);
+
+  bool ok = pip1.space_dimension() == pip2.space_dimension()
+    && 2 == std::distance(pip1.constraints_begin(), pip1.constraints_end())
+    && 2 == std::distance(pip2.constraints_begin(), pip2.constraints_end());
+
+  return ok;
+}
+
+bool
+test04() {
+  const char* my_file = "ascii_dump_load1.dat";
+
+  Variable A(0);
+  Constraint_System cs;
+  cs.insert(A >= 5);
+
+  PIP_Problem pip1(3, cs.begin(), cs.end(), Variables_Set());
+
+  fstream f;
+  open(f, my_file, ios_base::out);
+  pip1.ascii_dump(f);
+  close(f);
+
+  open(f, my_file, ios_base::in);
+  PIP_Problem pip2;
+  pip2.ascii_load(f);
+  close(f);
+
+  bool ok = pip1.space_dimension() == pip2.space_dimension()
+    && 1 == std::distance(pip1.constraints_begin(), pip1.constraints_end())
+    && 1 == std::distance(pip2.constraints_begin(), pip2.constraints_end());
+
+  return ok;
+}
+
+} // namespace
+
+BEGIN_MAIN
+  DO_TEST(test01);
+  DO_TEST(test02);
+  DO_TEST(test03);
+  DO_TEST(test04);
+END_MAIN




More information about the PPL-devel mailing list