[PPL-devel] [GIT] ppl/ppl(master): Added missing code for logic_error exception.
Patricia Hill
p.m.hill at leeds.ac.uk
Sat Mar 20 22:50:46 CET 2010
Module: ppl/ppl
Branch: master
Commit: 8ceb0b7e208be8a99d61372f883c1853ce390952
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=8ceb0b7e208be8a99d61372f883c1853ce390952
Author: Patricia Hill <p.m.hill at leeds.ac.uk>
Date: Sat Mar 20 21:49:18 2010 +0000
Added missing code for logic_error exception.
---
interfaces/Prolog/ppl_prolog_common.defs.hh | 3 +
tests/Grid/frequency1.cc | 64 +++++++++++++++++++++++++++
tests/Octagonal_Shape/frequency1.cc | 31 +++++++++++++
3 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/interfaces/Prolog/ppl_prolog_common.defs.hh b/interfaces/Prolog/ppl_prolog_common.defs.hh
index bb3e245..ce3fb55 100644
--- a/interfaces/Prolog/ppl_prolog_common.defs.hh
+++ b/interfaces/Prolog/ppl_prolog_common.defs.hh
@@ -413,6 +413,9 @@ void
handle_exception(const std::length_error& e);
void
+handle_exception(const std::logic_error& e);
+
+void
handle_exception(const std::bad_alloc&);
void
diff --git a/tests/Grid/frequency1.cc b/tests/Grid/frequency1.cc
index d4727e4..1ee313e 100644
--- a/tests/Grid/frequency1.cc
+++ b/tests/Grid/frequency1.cc
@@ -267,6 +267,67 @@ test11() {
return ok && (gr == known_gr);
}
+bool
+test12() {
+ Variable A(0);
+ Variable B(1);
+
+ Grid gr(2);
+ gr.add_constraint(A == 0);
+ gr.add_congruence(B %= 0);
+
+ Coefficient num;
+ Coefficient den;
+ Coefficient valn;
+ Coefficient vald;
+ bool ok = (gr.frequency(Linear_Expression(A), num, den, valn, vald)
+ && num == 0 && den == 1 && valn == 0 && vald == 1);
+ print_congruences(gr, "*** gr ***");
+
+ return ok;
+}
+
+bool
+test13() {
+ Variable A(0);
+ Variable B(1);
+
+ Grid gr(2);
+ gr.add_constraint(A == 0);
+ gr.add_constraint(B == 0);
+
+ Coefficient num;
+ Coefficient den;
+ Coefficient valn;
+ Coefficient vald;
+ bool ok = (gr.frequency(Linear_Expression(A), num, den, valn, vald)
+ && num == 0 && den == 1 && valn == 0 && vald == 1);
+ print_congruences(gr, "*** gr ***");
+
+ return ok;
+}
+
+bool
+test14() {
+ Variable A(0);
+ Variable B(1);
+
+ Grid gr(2);
+ gr.add_congruence((A %= 0) / 1);
+ gr.add_congruence((2*A - B %= 0) / 2);
+ print_congruences(gr, "*** gr ***");
+
+ Coefficient num;
+ Coefficient den;
+ Coefficient valn;
+ Coefficient vald;
+ bool ok = (gr.frequency(Linear_Expression(B), num, den, valn, vald)
+ && num == 2 && den == 1 && valn == 0 && vald == 1);
+ print_congruences(gr, "*** gr ***");
+ nout << num << den;
+ return ok;
+}
+
} // namespace
BEGIN_MAIN
@@ -281,4 +342,7 @@ BEGIN_MAIN
DO_TEST(test09);
DO_TEST(test10);
DO_TEST(test11);
+ DO_TEST(test12);
+ DO_TEST(test13);
+ DO_TEST(test14);
END_MAIN
diff --git a/tests/Octagonal_Shape/frequency1.cc b/tests/Octagonal_Shape/frequency1.cc
index 8184a0c..652a5e0 100644
--- a/tests/Octagonal_Shape/frequency1.cc
+++ b/tests/Octagonal_Shape/frequency1.cc
@@ -291,6 +291,36 @@ test12() {
return ok;
}
+bool
+test13() {
+ Variable A(0);
+ Variable B(1);
+ Variable C(2);
+
+ TOctagonal_Shape os(3);
+ os.add_constraint(4*A - 4*B == 1);
+ o.add_constraint(3*C == 1);
+ o.add_constraint(B <= 2);
+
+ Coefficient num;
+ Coefficient den;
+ Coefficient valn;
+ Coefficient vald;
+ bool discrete = os.frequency(Linear_Expression(A - B),
+ num, den, valn, vald);
+ // If the shape is based on an integral coefficient type, then
+ // approximations will induce non discreteness of the linear expression.
+ bool ok
+ = std::numeric_limits<TOctagonal_Shape::coefficient_type_base>::is_integer
+ ? (!discrete && num == 0 && den == 0 && valn == 0 && vald == 0)
+ : (discrete && num == 0 && den == 1 && valn == 1 && vald == 4);
+ print_constraints(os, "*** os ***");
+ nout << "num " << num << ", den " << den << endl;
+ nout << "valn " << valn << ", vald " << vald << endl;
+
+ return ok;
+}
+
} // namespace
BEGIN_MAIN
@@ -306,4 +336,5 @@ BEGIN_MAIN
DO_TEST(test10);
DO_TEST(test11);
DO_TEST(test12);
+ DO_TEST(test13);
END_MAIN
More information about the PPL-devel
mailing list