[PPL-devel] [GIT] ppl/ppl(master): Added unit tests for inner class PIP_Tree_Node:: Artificial_Parameter.
Enea Zaffanella
zaffanella at cs.unipr.it
Tue Feb 16 14:40:05 CET 2010
Module: ppl/ppl
Branch: master
Commit: b89a40da063ca44e5e28e0fad8a1001361cc131c
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=b89a40da063ca44e5e28e0fad8a1001361cc131c
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Tue Feb 16 14:38:15 2010 +0100
Added unit tests for inner class PIP_Tree_Node::Artificial_Parameter.
Added operator!=() and swap() methods: the last was necessary as we were
inheriting it from Linear_Expression.
---
src/PIP_Tree.cc | 13 ++++++++--
src/PIP_Tree.defs.hh | 14 +++++++++--
src/PIP_Tree.inlines.hh | 6 +++++
tests/PIP_Problem/ascii_dump_load1.cc | 22 ++++++++++++++++++
tests/PIP_Problem/exceptions1.cc | 19 +++++++++++++++
tests/PIP_Problem/pipproblem2.cc | 40 +++++++++++++++++++++++++++++++++
6 files changed, 108 insertions(+), 6 deletions(-)
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc
index 8a38aca..e92664f 100644
--- a/src/PIP_Tree.cc
+++ b/src/PIP_Tree.cc
@@ -291,8 +291,9 @@ PIP_Tree_Node::PIP_Tree_Node(const PIP_Tree_Node& y)
}
bool
-operator==(const PIP_Tree_Node::Artificial_Parameter& x,
- const PIP_Tree_Node::Artificial_Parameter& y) {
+PIP_Tree_Node::Artificial_Parameter
+::operator==(const PIP_Tree_Node::Artificial_Parameter& y) const {
+ const Artificial_Parameter& x = *this;
if (x.space_dimension() != y.space_dimension())
return false;
if (x.denominator != y.denominator)
@@ -305,6 +306,12 @@ operator==(const PIP_Tree_Node::Artificial_Parameter& x,
return true;
}
+bool
+PIP_Tree_Node::Artificial_Parameter
+::operator!=(const PIP_Tree_Node::Artificial_Parameter& y) const {
+ return !operator==(y);
+}
+
void
PIP_Tree_Node::Artificial_Parameter::ascii_dump(std::ostream& s) const {
s << "artificial_parameter ";
@@ -1809,7 +1816,7 @@ PIP_Solution_Node::solve(const PIP_Problem& problem,
// Do nothing if the j-th pivot element is zero.
if (s_pivot_j == 0)
continue;
- // ENEA: FIXME: why iterating downwards makes a difference?
+ // FIXME: why iterating downwards makes a difference?
// for (dimension_type i = num_rows; i-- > 0; ) {
for (dimension_type i = 0; i < num_rows; ++i) {
Row& s_i = tableau.s[i];
diff --git a/src/PIP_Tree.defs.hh b/src/PIP_Tree.defs.hh
index b7b8577..cfaed23 100644
--- a/src/PIP_Tree.defs.hh
+++ b/src/PIP_Tree.defs.hh
@@ -243,9 +243,17 @@ public:
//! Returns the normalized (i.e., positive) denominator.
Coefficient_traits::const_reference get_denominator() const;
- //! Returns \b true if \p x and \p y are equal.
- friend bool operator==(const Artificial_Parameter& x,
- const Artificial_Parameter& y);
+ //! Swaps \p *this with \p y.
+ void swap(Artificial_Parameter& y);
+
+ //! Returns \c true if and only if \p *this and \p y are equal.
+ /*!
+ Note that two artificial parameters having different space dimensions
+ are considered to be different.
+ */
+ bool operator==(const Artificial_Parameter& y) const;
+ //! Returns \c true if and only if \p *this and \p y are different.
+ bool operator!=(const Artificial_Parameter& y) const;
PPL_OUTPUT_DECLARATIONS
diff --git a/src/PIP_Tree.inlines.hh b/src/PIP_Tree.inlines.hh
index 6544e59..9c86647 100644
--- a/src/PIP_Tree.inlines.hh
+++ b/src/PIP_Tree.inlines.hh
@@ -145,6 +145,12 @@ PIP_Tree_Node::Artificial_Parameter::get_denominator() const {
return denominator;
}
+inline void
+PIP_Tree_Node::Artificial_Parameter::swap(Artificial_Parameter& y) {
+ Linear_Expression::swap(y);
+ std::swap(denominator, y.denominator);
+}
+
} // namespace Parma_Polyhedra_Library
#endif // !defined(PPL_PIP_Tree_inlines_hh)
diff --git a/tests/PIP_Problem/ascii_dump_load1.cc b/tests/PIP_Problem/ascii_dump_load1.cc
index d4c814e..d0cbceb 100644
--- a/tests/PIP_Problem/ascii_dump_load1.cc
+++ b/tests/PIP_Problem/ascii_dump_load1.cc
@@ -224,6 +224,27 @@ test07() {
return ok;
}
+bool
+test08() {
+ typedef PIP_Tree_Node::Artificial_Parameter Art_Param;
+
+ Variable A(0);
+
+ Art_Param ap1(3*A + 8, -5);
+ std::stringstream ss1;
+ ap1.ascii_dump(ss1);
+
+ Art_Param ap2;
+ bool ok = ap2.ascii_load(ss1);
+
+ std::stringstream ss2;
+ ap2.ascii_dump(ss2);
+
+ ok &= (ap1 == ap2) && (ss1.str() == ss2.str());
+
+ return ok;
+}
+
} // namespace
BEGIN_MAIN
@@ -234,4 +255,5 @@ BEGIN_MAIN
DO_TEST(test05);
DO_TEST(test06);
DO_TEST(test07);
+ DO_TEST(test08);
END_MAIN
diff --git a/tests/PIP_Problem/exceptions1.cc b/tests/PIP_Problem/exceptions1.cc
index 5b27b09..3f01ab1 100644
--- a/tests/PIP_Problem/exceptions1.cc
+++ b/tests/PIP_Problem/exceptions1.cc
@@ -258,6 +258,24 @@ test11() {
return false;
}
+bool
+test12() {
+ typedef PIP_Tree_Node::Artificial_Parameter Art_Param;
+ Variable A(0);
+
+ try {
+ // Trying to set an invalid (zero) denominator.
+ Art_Param ap(3*A + 8, 0);
+ }
+ catch (std::invalid_argument& e) {
+ nout << "invalid_argument: " << e.what() << endl << endl;
+ return true;
+ }
+ catch (...) {
+ }
+ return false;
+}
+
} // namespace
BEGIN_MAIN
@@ -272,4 +290,5 @@ BEGIN_MAIN
DO_TEST(test09);
DO_TEST(test10);
DO_TEST(test11);
+ DO_TEST(test12);
END_MAIN
diff --git a/tests/PIP_Problem/pipproblem2.cc b/tests/PIP_Problem/pipproblem2.cc
index 06ae7f7..8f476e4 100644
--- a/tests/PIP_Problem/pipproblem2.cc
+++ b/tests/PIP_Problem/pipproblem2.cc
@@ -244,6 +244,45 @@ test13() {
return ok;
}
+bool
+test14() {
+ // Some unit testing on inner class Artificial_Parameter.
+ typedef PIP_Tree_Node::Artificial_Parameter Art_Param;
+
+ Variable A(0);
+
+ Art_Param ap0;
+ Art_Param ap1(3*A + 8, -5);
+ Art_Param ap2(ap1);
+
+ bool ok = ap0.OK() && ap1.OK() && ap2.OK();
+
+ ok &= (ap0 != ap1) && (ap1 == ap2);
+ ok &= (ap0.get_denominator() == 1) && (ap1.get_denominator() == 5);
+
+ ap0.swap(ap2);
+ ok &= (ap0 == ap1) && (ap2.get_denominator() == 1);
+
+ using namespace IO_Operators;
+ nout << ap1;
+
+ ok &= (ap1.external_memory_in_bytes() < ap1.total_memory_in_bytes());
+
+ // Difference found in space dimension.
+ ok &= (ap1 != ap2);
+ // Difference found in denominator.
+ Art_Param ap3(3*A + 8, -6);
+ ok &= (ap1 != ap3);
+ // Difference found in inhomogeneous term.
+ Art_Param ap4(3*A + 7, -5);
+ ok &= (ap1 != ap4);
+ // Difference found in A's coefficient.
+ Art_Param ap5(2*A + 8, -5);
+ ok &= (ap1 != ap5);
+
+ return ok;
+}
+
} // namespace
BEGIN_MAIN
@@ -260,4 +299,5 @@ BEGIN_MAIN
DO_TEST(test11);
DO_TEST(test12);
DO_TEST(test13);
+ DO_TEST(test14);
END_MAIN
More information about the PPL-devel
mailing list