[PPL-devel] [GIT] ppl/ppl(master): Added test class Custom_Variable_Stringifier and corresponding example
Enea Zaffanella
zaffanella at cs.unipr.it
Tue Aug 7 19:11:11 CEST 2012
Module: ppl/ppl
Branch: master
Commit: a292feb89642e2dcefa1f2092836ca6323e1cb50
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=a292feb89642e2dcefa1f2092836ca6323e1cb50
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Tue Aug 7 19:09:17 2012 +0200
Added test class Custom_Variable_Stringifier and corresponding example
for testing customization of Variable output in the Java interface.
---
.../Java/tests/Custom_Variable_Stringifier.java | 29 ++++++
interfaces/Java/tests/Makefile.am | 7 ++-
interfaces/Java/tests/Variable_Output_test1.java | 94 ++++++++++++++++++++
3 files changed, 129 insertions(+), 1 deletions(-)
diff --git a/interfaces/Java/tests/Custom_Variable_Stringifier.java b/interfaces/Java/tests/Custom_Variable_Stringifier.java
new file mode 100644
index 0000000..f13e27c
--- /dev/null
+++ b/interfaces/Java/tests/Custom_Variable_Stringifier.java
@@ -0,0 +1,29 @@
+/* A class providing customized variable output for Java.
+ Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
+
+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://bugseng.com/products/ppl/ . */
+
+import parma_polyhedra_library.*;
+
+public class Custom_Variable_Stringifier implements Variable_Stringifier {
+ public String stringify(int var_id) {
+ return "Var_" + var_id;
+ }
+}
diff --git a/interfaces/Java/tests/Makefile.am b/interfaces/Java/tests/Makefile.am
index 99c9f2d..62d182f 100644
--- a/interfaces/Java/tests/Makefile.am
+++ b/interfaces/Java/tests/Makefile.am
@@ -49,7 +49,9 @@ PIP_Problem_test1.java \
Parma_Polyhedra_Library_test1.java \
Parma_Polyhedra_Library_test2.java \
PPL_Test.java \
-ppl_java_tests_common
+ppl_java_tests_common \
+Custom_Variable_Stringifier.java \
+Variable_Output_test1.java
if ENABLE_SHARED
@@ -62,6 +64,8 @@ MIP_Problem_test1.java \
PIP_Problem_test1.java \
Parma_Polyhedra_Library_test1.java \
Parma_Polyhedra_Library_test2.java \
+Custom_Variable_Stringifier.java \
+Variable_Output_test1.java \
PPL_Test.java
CLASSPATH = ../ppl_java.jar:.
@@ -88,6 +92,7 @@ check-local: ppl_java_generated_tests.java
$(java_test_environment) PIP_Problem_test1
$(java_test_environment) Parma_Polyhedra_Library_test1
$(java_test_environment) Parma_Polyhedra_Library_test2
+ $(java_test_environment) Variable_Output_test1
CLEANFILES = \
ppl_java_generated_tests.java
diff --git a/interfaces/Java/tests/Variable_Output_test1.java b/interfaces/Java/tests/Variable_Output_test1.java
new file mode 100644
index 0000000..addac43
--- /dev/null
+++ b/interfaces/Java/tests/Variable_Output_test1.java
@@ -0,0 +1,94 @@
+/* Test customization of variable output in Java.
+ Copyright (C) 2010-2012 BUGSENG srl (http://bugseng.com)
+
+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://bugseng.com/products/ppl/ . */
+
+import parma_polyhedra_library.*;
+
+public class Variable_Output_test1 {
+ static {
+ try {
+ System.loadLibrary("ppl_java");
+ }
+ catch (UnsatisfiedLinkError e) {
+ System.out.println("Unable to load the library");
+ System.out.println(e.getMessage());
+ System.exit(-1);
+ }
+ }
+
+ public static boolean test01() {
+ Variable A = new Variable(0);
+ Variable B = new Variable(1);
+ Variable C = new Variable(2);
+ Linear_Expression_Variable le_a = new Linear_Expression_Variable(A);
+ Coefficient coeff_1 = new Coefficient(1);
+ Linear_Expression le_1 = new Linear_Expression_Coefficient(coeff_1);
+ Constraint con
+ = new Constraint(le_a, Relation_Symbol.GREATER_OR_EQUAL, le_1);
+ C_Polyhedron ph = new C_Polyhedron(1, Degenerate_Element.UNIVERSE);
+ ph.add_constraint(con);
+ boolean ok = false;
+
+ // Printing with default output function.
+ ok = (A.toString().equals("A") &&
+ B.toString().equals("B") &&
+ C.toString().equals("C") &&
+ con.toString().equals("A >= 1") &&
+ ph.toString().equals("A >= 1"));
+ if (!ok)
+ return false;
+
+ // Changing output function to custom one.
+ Variable_Stringifier vs = new Custom_Variable_Stringifier();
+ Variable.setStringifier(vs);
+
+ ok = (A.toString().equals("Var_0") &&
+ B.toString().equals("Var_1") &&
+ C.toString().equals("Var_2") &&
+ con.toString().equals("Var_0 >= 1") &&
+ ph.toString().equals("Var_0 >= 1"));
+ if (!ok)
+ return false;
+
+ // Restoring default output function.
+ Variable.setStringifier(null);
+
+ ok = (A.toString().equals("A") &&
+ B.toString().equals("B") &&
+ C.toString().equals("C") &&
+ con.toString().equals("A >= 1") &&
+ ph.toString().equals("A >= 1"));
+ if (!ok)
+ return false;
+
+ return ok;
+ }
+
+ public static void main(String[] args) {
+ Parma_Polyhedra_Library.initialize_library();
+ boolean test_result_ok =
+ Test_Executor.executeTests(Variable_Output_test1.class);
+ Parma_Polyhedra_Library.finalize_library();
+ if (!test_result_ok)
+ System.exit(1);
+ System.exit(0);
+ }
+}
More information about the PPL-devel
mailing list