[PPL-devel] [GIT] ppl/ppl(pip): Improving test coverage ratio.

Enea Zaffanella zaffanella at cs.unipr.it
Sun Feb 7 09:58:13 CET 2010


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

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Sat Feb  6 17:16:05 2010 +0100

Improving test coverage ratio.

---

 tests/PIP_Problem/ascii_dump_load1.cc |   33 ++++++++
 tests/PIP_Problem/exceptions1.cc      |  143 +++++++++++++++++++++++++++++++++
 tests/PIP_Problem/pipproblem1.cc      |   34 ++++++++
 3 files changed, 210 insertions(+), 0 deletions(-)

diff --git a/tests/PIP_Problem/ascii_dump_load1.cc b/tests/PIP_Problem/ascii_dump_load1.cc
index 3ff394b..a89c8a1 100644
--- a/tests/PIP_Problem/ascii_dump_load1.cc
+++ b/tests/PIP_Problem/ascii_dump_load1.cc
@@ -143,6 +143,38 @@ test04() {
   return ok;
 }
 
+bool
+test05() {
+  const char* my_file = "ascii_dump_load1.dat";
+
+  Variable A(0);
+  Variable P(1);
+  Constraint_System cs;
+  cs.insert(A >= 1);
+  cs.insert(A <= 0);
+
+  PIP_Problem pip1(2, cs.begin(), cs.end(), Variables_Set(P));
+  pip1.set_control_parameter(PIP_Problem::CUTTING_STRATEGY_ALL);
+  pip1.set_big_parameter_dimension(1);
+  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;
+}
+
 } // namespace
 
 BEGIN_MAIN
@@ -150,4 +182,5 @@ BEGIN_MAIN
   DO_TEST(test02);
   DO_TEST(test03);
   DO_TEST(test04);
+  DO_TEST(test05);
 END_MAIN
diff --git a/tests/PIP_Problem/exceptions1.cc b/tests/PIP_Problem/exceptions1.cc
index c227c1f..5b27b09 100644
--- a/tests/PIP_Problem/exceptions1.cc
+++ b/tests/PIP_Problem/exceptions1.cc
@@ -121,6 +121,143 @@ test05() {
   return false;
 }
 
+bool
+test06() {
+  PIP_Problem pip;
+  try {
+    // Adding invalid parameter space dimensions.
+    Variable m(4);
+    pip.add_to_parameter_space_dimensions(Variables_Set(m));
+  }
+  catch (std::invalid_argument& e) {
+    nout << "invalid_argument: " << e.what() << endl << endl;
+    return true;
+  }
+  catch (...) {
+  }
+  return false;
+}
+
+bool
+test07() {
+  PIP_Problem pip;
+  try {
+    // Adding space dimension incompatible constraint.
+    Variable x(2);
+    pip.add_constraint(x >= 0);
+  }
+  catch (std::invalid_argument& e) {
+    nout << "invalid_argument: " << e.what() << endl << endl;
+    return true;
+  }
+  catch (...) {
+  }
+  return false;
+}
+
+bool
+test08() {
+  PIP_Problem pip;
+  try {
+    // Setting an invalid control parameter value.
+    pip.set_control_parameter(PIP_Problem::CONTROL_PARAMETER_VALUE_SIZE);
+  }
+  catch (std::invalid_argument& e) {
+    nout << "invalid_argument: " << e.what() << endl << endl;
+    return true;
+  }
+  catch (...) {
+  }
+  return false;
+}
+
+bool
+test09() {
+  Variable X1(0);
+  Variable X2(1);
+  Variable I0(2);
+  Variable J0(3);
+  Variable N(4);
+  Variables_Set params(I0, N);
+
+  Constraint_System cs;
+  cs.insert(-X1 + N - 1 >= 0);
+  cs.insert(X1 - X2 >= 0);
+  cs.insert(X1 + I0 == N);
+  cs.insert(X2 + J0 - N - 1 >= 0);
+  cs.insert(I0 >= 1);
+  cs.insert(N >= 1);
+
+  PIP_Problem pip(cs.space_dimension(), cs.begin(), cs.end(), params);
+  (void) pip.is_satisfiable();
+  // Adding 2 additional space dimensions.
+  pip.add_space_dimensions_and_embed(2, 0);
+
+  try {
+    // Trying to mark a problem variable as a parameter.
+    pip.add_to_parameter_space_dimensions(Variables_Set(X1));
+  }
+  catch (std::invalid_argument& e) {
+    nout << "invalid_argument: " << e.what() << endl << endl;
+    return true;
+  }
+  catch (...) {
+  }
+  return false;
+}
+
+bool
+test10() {
+  PIP_Problem pip;
+
+  try {
+    // Trying to set an invalid big parameter dimension.
+    pip.set_big_parameter_dimension(1);
+  }
+  catch (std::invalid_argument& e) {
+    nout << "invalid_argument: " << e.what() << endl << endl;
+    return true;
+  }
+  catch (...) {
+  }
+  return false;
+}
+
+bool
+test11() {
+  Variable X1(0);
+  Variable X2(1);
+  Variable I0(2);
+  Variable J0(3);
+  Variable N(4);
+  Variables_Set params(I0, N);
+
+  Constraint_System cs;
+  cs.insert(-X1 + N - 1 >= 0);
+  cs.insert(X1 - X2 >= 0);
+  cs.insert(X1 + I0 == N);
+  cs.insert(X2 + J0 - N - 1 >= 0);
+  cs.insert(I0 >= 1);
+  cs.insert(N >= 1);
+
+  PIP_Problem pip(cs.space_dimension(), cs.begin(), cs.end(), params);
+  (void) pip.is_satisfiable();
+  // Adding 2 additional space dimensions.
+  pip.add_space_dimensions_and_embed(2, 0);
+
+  try {
+    // Trying to set an invalid big parameter dimension.
+    pip.set_big_parameter_dimension(3);
+  }
+  catch (std::invalid_argument& e) {
+    nout << "invalid_argument: " << e.what() << endl << endl;
+    return true;
+  }
+  catch (...) {
+  }
+  return false;
+}
+
 } // namespace
 
 BEGIN_MAIN
@@ -129,4 +266,10 @@ BEGIN_MAIN
   DO_TEST(test03);
   DO_TEST(test04);
   DO_TEST(test05);
+  DO_TEST(test06);
+  DO_TEST(test07);
+  DO_TEST(test08);
+  DO_TEST(test09);
+  DO_TEST(test10);
+  DO_TEST(test11);
 END_MAIN
diff --git a/tests/PIP_Problem/pipproblem1.cc b/tests/PIP_Problem/pipproblem1.cc
index a90ab9d..113ac3e 100644
--- a/tests/PIP_Problem/pipproblem1.cc
+++ b/tests/PIP_Problem/pipproblem1.cc
@@ -277,6 +277,39 @@ test07() {
   return ok;
 }
 
+bool
+test08() {
+  Variable i(0);
+  Variable j(1);
+  Variable m(2);
+  Variable n(3);
+  Variables_Set params(m, n);
+
+  PIP_Problem pip(4);
+  pip.add_to_parameter_space_dimensions(params);
+
+  Constraint_System cs;
+  cs.insert(3*j >= -2*i+8);
+  cs.insert(j <= 4*i - 4);
+  cs.insert(i <= n);
+  cs.insert(n >= 3);
+  cs.insert(j <= m);
+
+  pip.add_constraints(cs);
+
+  pip.set_control_parameter(PIP_Problem::PIVOT_ROW_STRATEGY_MAX_COLUMN);
+
+  bool ok = pip.is_satisfiable();
+  if (ok) {
+    const PIP_Tree solution = pip.optimizing_solution();
+    display_solution(solution, params, Variables_Set(i, j),
+                     pip.space_dimension());
+    pip.clear();
+  }
+
+  return ok;
+}
+
 } // namespace
 
 BEGIN_MAIN
@@ -287,4 +320,5 @@ BEGIN_MAIN
   DO_TEST(test05);
   DO_TEST(test06);
   DO_TEST(test07);
+  DO_TEST(test08);
 END_MAIN




More information about the PPL-devel mailing list