[PPL-devel] [GIT] ppl/ppl(floating_point): Added a test for trivial cases of BD_Shape:: affine_image.

Roberto Amadini r.amadini at virgilio.it
Fri Sep 18 16:34:13 CEST 2009


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

Author: Roberto Amadini <r.amadini at virgilio.it>
Date:   Fri Sep 18 16:32:40 2009 +0200

Added a test for trivial cases of BD_Shape::affine_image.

---

 src/BD_Shape.templates.hh                       |   30 ++++++------
 tests/Floating_Point_Expression/affineimage3.cc |    2 +-
 tests/Floating_Point_Expression/bdshape1.cc     |   56 +++++++++++++++++++---
 tests/Floating_Point_Expression/refinelf1.cc    |    2 +-
 4 files changed, 65 insertions(+), 25 deletions(-)

diff --git a/src/BD_Shape.templates.hh b/src/BD_Shape.templates.hh
index c1bb7d7..96b7738 100644
--- a/src/BD_Shape.templates.hh
+++ b/src/BD_Shape.templates.hh
@@ -4051,7 +4051,7 @@ BD_Shape<T>::affine_image(const Variable& var,
 
   // Check that T is a floating point type.
   PPL_COMPILE_TIME_CHECK(!std::numeric_limits<T>::is_exact,
-		    "Octagonal_Shape<T>::affine_image(Variable, Linear_Form):"
+		    "BD_Shape<T>::affine_image(Variable, Linear_Form):"
                     " T not a floating point type.");
 
   // Dimension-compatibility checks.
@@ -4093,7 +4093,7 @@ BD_Shape<T>::affine_image(const Variable& var,
   // Now we know the form of `lf':
   // - If t == 0, then lf == b, with `b' a constant;
   // - If t == 1, then lf == a*w + b, where `w' can be `v' or another
-  //   variable; 
+  //   variable;
   // - If t == 2, the `expr' is of the general form.
 
   PPL_DIRTY_TEMP(N, b_ub);
@@ -4112,7 +4112,7 @@ BD_Shape<T>::affine_image(const Variable& var,
     PPL_ASSERT(OK());
     return;
   }
-  
+
   // General case.
   // Either t == 2, so that
   // lf == i_1*x_1 + i_2*x_2 + ... + i_n*x_n + b, where n >= 2,
@@ -4124,30 +4124,30 @@ BD_Shape<T>::affine_image(const Variable& var,
 
   template <typename T>
   template <typename Interval_Info>
-  void 
+  void
   BD_Shape<T>::inhomogeneous_affine_image(const Variable& var,
-					  const dimension_type& var_id,
-				    const Interval<T, Interval_Info>& term,
-					  const N& ub,
-				          const N& lb) {
+                                 const dimension_type& var_id,
+                       const Interval<T, Interval_Info>& term,
+					                              const N& ub,
+				                                  const N& lb) {
   }
 
   template <typename T>
   template <typename Interval_Info>
-  void 
+  void
   BD_Shape<T>::one_variable_affine_image(const Variable& var,
-					 const dimension_type& var_id,
-				   const Interval<T, Interval_Info>& term,
+					            const dimension_type& var_id,
+                      const Interval<T, Interval_Info>& term,
 				   const Interval<T, Interval_Info>& w_coeff,
-					 const N& ub,
-					 const N& lb) {
+					                             const N& ub,
+                                                 const N& lb) {
   }
 
   template <typename T>
   template <typename Interval_Info>
   void BD_Shape<T>
   ::two_variable_affine_image(const Variable& var,
-			      const dimension_type& var_id,
+			                  const dimension_type& var_id,
 		 const Linear_Form< Interval<T, Interval_Info> >& lf) {
   }
 
@@ -5976,7 +5976,7 @@ template<typename Interval_Info>
 void
 BD_Shape<T>::throw_dimension_incompatible(const char* method,
                                           const char* name_row,
-                                          const Linear_Form< Interval<T, 
+                                          const Linear_Form< Interval<T,
 					  Interval_Info> >& lf) const {
   std::ostringstream s;
   s << "PPL::BD_Shape::" << method << ":" << std::endl
diff --git a/tests/Floating_Point_Expression/affineimage3.cc b/tests/Floating_Point_Expression/affineimage3.cc
index 6633d3e..f439275 100644
--- a/tests/Floating_Point_Expression/affineimage3.cc
+++ b/tests/Floating_Point_Expression/affineimage3.cc
@@ -1,4 +1,4 @@
-/* Test Octagonal_Shape::affine_image on interval linear forms.
+/* Test Octagonal_Shape::affine_image on interval linear forms
    Copyright (C) 2001-2009 Roberto Bagnara <bagnara at cs.unipr.it>
 
 This file is part of the Parma Polyhedra Library (PPL).
diff --git a/tests/Floating_Point_Expression/bdshape1.cc b/tests/Floating_Point_Expression/bdshape1.cc
index 33b6685..09c20f5 100644
--- a/tests/Floating_Point_Expression/bdshape1.cc
+++ b/tests/Floating_Point_Expression/bdshape1.cc
@@ -24,21 +24,60 @@ site: http://www.cs.unipr.it/ppl/ . */
 
 namespace {
 
-// tests affine_image(A, [-2, 1])
+// tests space_dimensions and trivial cases
 bool
 test01() {
   Variable A(0);
   Variable B(1);
+  BD_Shape<double> bd1(0);
+  bool ok1 = false;
+  Linear_Form<db_r_oc> l(A);
+
+  try {
+      bd1.affine_image(A, l);
+  }
+  catch(std::invalid_argument e) {
+    nout << "bd1_space_dim < lf_space_dim" << endl;
+    ok1 = true;
+  }
+
+  bool ok2 = false;
+  BD_Shape<double> bd2(1);
+
+  try {
+    bd2.affine_image(B, l);
+  }
+  catch(std::invalid_argument e) {
+    nout << "space_dim < var_id + 1" << endl;
+    bd2.affine_image(A, l);
+    Constraint_System cs(A < A);
+    bd2.add_constraints(cs);
+    bd2.affine_image(A, l);
+    ok2 = true;
+  }
+
+  return ok1 && ok2;
+}
+
 
-  BD_Shape<float> oc1(3);
-  oc1.add_constraint(A <= 2);
-  oc1.add_constraint(A - B <= 3);
-  oc1.add_constraint(B <= 2);
+// tests affine_image(A, [-2, 1])
+// FIXME: It's a preliminary version, not sound at the moment.
+bool
+test02() {
+  Variable A(0);
+  Variable B(1);
+
+  BD_Shape<float> bd1(3);
+  bd1.add_constraint(A <= 2);
+  bd1.add_constraint(A - B <= 3);
+  bd1.add_constraint(B <= 2);
   fl_r_oc free_term(-2);
   free_term.join_assign(1);
   Linear_Form<fl_r_oc> l(free_term);
-  oc1.affine_image(A, l);
-  print_constraints(oc1, "*** oc1.affine_image(A, [-2, 1]) ***");
+  bd1.affine_image(A, l);
+  print_constraints(bd1, "*** bd1.affine_image(A, [-2, 1]) ***");
+
+  // At the moment, affine_image is simply an identity function.
 
   BD_Shape<float> known_result(3);
   known_result.add_constraint(A <= 2);
@@ -46,7 +85,7 @@ test01() {
   known_result.add_constraint(A - B <= 3);
   print_constraints(known_result, "*** known_result ***");
 
-  bool ok = (oc1 == known_result);
+  bool ok = (bd1 == known_result);
 
   return ok;
 }
@@ -55,4 +94,5 @@ test01() {
 
 BEGIN_MAIN
   DO_TEST(test01);
+  DO_TEST(test02);
 END_MAIN
diff --git a/tests/Floating_Point_Expression/refinelf1.cc b/tests/Floating_Point_Expression/refinelf1.cc
index 5d15285..5c9a7bc 100644
--- a/tests/Floating_Point_Expression/refinelf1.cc
+++ b/tests/Floating_Point_Expression/refinelf1.cc
@@ -1,5 +1,5 @@
 /* Test Octagonal_Shape::refine_fp_interval_abstract_store and
-   Octagonal_Shape::refine_with_linear_form_inequality
+   Octagonal_Shape::refine_with_linear_form_inequality.
    Copyright (C) 2001-2009 Roberto Bagnara <bagnara at cs.unipr.it>
 
 This file is part of the Parma Polyhedra Library (PPL).




More information about the PPL-devel mailing list