1 /* Test C_Polyhedron Java test class of the Parma Polyhedra Library Java 2 interface. 3 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 4 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com) 5 6 This file is part of the Parma Polyhedra Library (PPL). 7 8 The PPL is free software; you can redistribute it and/or modify it 9 under the terms of the GNU General Public License as published by the 10 Free Software Foundation; either version 3 of the License, or (at your 11 option) any later version. 12 13 The PPL is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software Foundation, 20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 21 22 For the most up-to-date information see the Parma Polyhedra Library 23 site: http://bugseng.com/products/ppl/ . */ 24 25 import parma_polyhedra_library.*; 26 27 public class C_Polyhedron_test1 { 28 static { 29 try { 30 System.loadLibrary("ppl_java"); 31 } 32 catch (UnsatisfiedLinkError e) { 33 System.out.println("Unable to load the library"); 34 System.out.println(e.getMessage()); 35 System.exit(-1); 36 } 37 } 38 39 // This code tests the method `map_space_dimension(pfunc)'. test01()40 public static boolean test01() { 41 Partial_Function partial_function = new Partial_Function(); 42 partial_function.insert(0, 2); 43 partial_function.insert(2, 0); 44 partial_function.insert(1, 1); 45 Variable A = new Variable(0); 46 Variable B = new Variable(1); 47 Variable C = new Variable(2); 48 Linear_Expression_Variable le_b = new Linear_Expression_Variable(B); 49 Linear_Expression_Variable le_c = new Linear_Expression_Variable(C); 50 Linear_Expression_Variable le_a = new Linear_Expression_Variable(A); 51 Linear_Expression_Sum le_a_plus_b 52 = new Linear_Expression_Sum(le_a, le_b); 53 Linear_Expression_Sum le_a_plus_c 54 = new Linear_Expression_Sum(le_a, le_c); 55 Linear_Expression_Sum le_c_plus_b 56 = new Linear_Expression_Sum(le_c, le_b); 57 Linear_Expression_Sum le_c_plus_a 58 = new Linear_Expression_Sum(le_c, le_a); 59 Linear_Expression_Coefficient le_two 60 = new Linear_Expression_Coefficient(new Coefficient(2)); 61 Linear_Expression_Times le_2c 62 = new Linear_Expression_Times(le_c, new Coefficient(2)); 63 Linear_Expression_Times le_2a 64 = new Linear_Expression_Times(le_a, new Coefficient(2)); 65 66 Generator_System gs = new Generator_System(); 67 gs.add(Generator.point(le_2c, new Coefficient(1))); 68 gs.add(Generator.line(le_a_plus_b)); 69 gs.add(Generator.ray(le_a_plus_c)); 70 71 C_Polyhedron poly1 = new C_Polyhedron(gs); 72 poly1.map_space_dimensions(partial_function); 73 74 Generator_System known_gs = new Generator_System(); 75 known_gs.add(Generator.point(le_2a, new Coefficient(1))); 76 known_gs.add(Generator.line(le_c_plus_b)); 77 known_gs.add(Generator.ray(le_c_plus_a)); 78 79 C_Polyhedron known_result = new C_Polyhedron(known_gs); 80 return known_result.equals(poly1); 81 } 82 83 test02()84 public static boolean test02() { 85 // Test if `minimized_constraints' returns an empty Constraint_System 86 // if the Polyhedron is built from universe with a dimension greater 87 // than zero. 88 Variable X = new Variable(0); 89 Variable Y = new Variable(1); 90 Variable Z = new Variable(2); 91 C_Polyhedron ph = new C_Polyhedron(3, Degenerate_Element.UNIVERSE); 92 Constraint_System cs = ph.minimized_constraints(); 93 return cs.isEmpty(); 94 } 95 test03()96 public static boolean test03() { 97 Variable A = new Variable(0); 98 Variable B = new Variable(1); 99 Generator_System gs = new Generator_System(); 100 gs.add(Generator.point(new Linear_Expression_Variable(A), 101 new Coefficient(2))); 102 gs.add(Generator.point(new Linear_Expression_Variable(B), 103 new Coefficient(2))); 104 C_Polyhedron ph = new C_Polyhedron(gs); 105 Variables_Set var_set = new Variables_Set(); 106 var_set.add(B); 107 ph.drop_some_non_integer_points(var_set, 108 Complexity_Class.ANY_COMPLEXITY); 109 Generator_System gs_out = ph.minimized_generators(); 110 boolean ok = (gs_out.size() == 1); 111 ph.drop_some_non_integer_points(Complexity_Class.ANY_COMPLEXITY); 112 gs_out = ph.minimized_generators(); 113 ok = ok && gs_out.isEmpty(); 114 return ok; 115 } 116 test04()117 public static boolean test04() { 118 Coefficient freq_n = new Coefficient(0); 119 Coefficient freq_d = new Coefficient(0); 120 Coefficient val_n = new Coefficient(0); 121 Coefficient val_d = new Coefficient(0); 122 Linear_Expression le 123 = new Linear_Expression_Coefficient(new Coefficient(0)); 124 C_Polyhedron ph = new C_Polyhedron(0, Degenerate_Element.UNIVERSE); 125 return ph.frequency(le, freq_n, freq_d, val_n, val_d); 126 } 127 main(String[] args)128 public static void main(String[] args) { 129 Parma_Polyhedra_Library.initialize_library(); 130 boolean test_result_ok = 131 Test_Executor.executeTests(C_Polyhedron_test1.class); 132 Parma_Polyhedra_Library.finalize_library(); 133 if (!test_result_ok) 134 System.exit(1); 135 System.exit(0); 136 } 137 } 138