[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5808] Assert and unit-test even more invariants
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5808] Assert and unit-test even more invariants |
Date: |
Sun, 27 Oct 2013 22:00:19 +0000 |
Revision: 5808
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5808
Author: chicares
Date: 2013-10-27 22:00:19 +0000 (Sun, 27 Oct 2013)
Log Message:
-----------
Assert and unit-test even more invariants
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/gpt_commutation_functions.cpp
lmi/trunk/gpt_test.cpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2013-10-27 11:43:40 UTC (rev 5807)
+++ lmi/trunk/ChangeLog 2013-10-27 22:00:19 UTC (rev 5808)
@@ -32756,3 +32756,34 @@
version.hpp
Designate release candidate 5803.
+20131025T2217Z <address@hidden> [542]
+
+ ihs_irc7702a.cpp
+ input_realization.cpp
+ ledger_base.cpp
+ stratified_algorithms.hpp
+ stratified_charges.cpp
+Improve documentation.
+
+20131025T2315Z <address@hidden> [542]
+
+ miscellany.hpp
+Add relational operators for class minmax.
+
+20131027T1132Z <address@hidden> [542]
+
+ miscellany_test.cpp
+Test relational operators for class minmax.
+
+20131027T1143Z <address@hidden> [542]
+
+ gpt_commutation_functions.cpp
+ gpt_test.cpp
+Assert and unit-test more invariants.
+
+20131027T2200Z <address@hidden> [542]
+
+ gpt_commutation_functions.cpp
+ gpt_test.cpp
+Assert and unit-test even more invariants.
+
Modified: lmi/trunk/gpt_commutation_functions.cpp
===================================================================
--- lmi/trunk/gpt_commutation_functions.cpp 2013-10-27 11:43:40 UTC (rev
5807)
+++ lmi/trunk/gpt_commutation_functions.cpp 2013-10-27 22:00:19 UTC (rev
5808)
@@ -31,6 +31,7 @@
#include "assert_lmi.hpp"
#include "commutation_functions.hpp"
#include "et_vector.hpp"
+#include "miscellany.hpp" // minmax
#include <algorithm> // std::min_element()
#include <numeric> // std::partial_sum()
@@ -58,13 +59,22 @@
/// Constructor.
///
-/// Asserted preconditions: all argument vectors, including those in
-/// the parameter object, have the same length. It may at first appear
-/// that assertions to this effect belong upstream; however, writing
-/// them in the body of gpt_cf_triad::gpt_cf_triad() would cause them
-/// to be executed after the present ctor is called.
+/// Asserted preconditions: All argument vectors, including those in
+/// the parameter object, have the same length, and that length is a
+/// plausible human age. All these vectors' elements must be within a
+/// plausible range, most often [0.0, 1.0). Upper limits (except on q)
+/// are arbitrary, though liberal; they're intended only to detect
+/// probable errors such as might arise from misplaced decimal point.
+/// Particular bounds might be loosened p.r.n.--if negative loads must
+/// be supported, for example. These range tests impose an overhead of
+/// about twenty percent; it is assumed that a few extra microseconds
+/// are affordable.
///
-/// Asserted postconditions: all Dx+t (thus, implicitly, all Nx+t) are
+/// It may at first seem that precondition assertions belong upstream;
+/// however, writing them in the body of gpt_cf_triad::gpt_cf_triad()
+/// would cause them to be executed after the present ctor is called.
+///
+/// Asserted postconditions: All Dx+t (thus, implicitly, all Nx+t) are
/// greater than zero, including those multiplied by the complement of
/// premium loads, so that they may safely be used as denominators in
/// premium formulas.
@@ -112,6 +122,27 @@
LMI_ASSERT(length_ == charges.qab_child_rate .size());
LMI_ASSERT(length_ == charges.qab_waiver_rate .size());
+ typedef minmax<double> mm;
+ mm a( qc ); LMI_ASSERT(0.0 <= a && a <= 1.0);
+ mm b( ic ); LMI_ASSERT(0.0 <= b && b < 1.0);
+ mm c( ig ); LMI_ASSERT(0.0 <= c && c < 1.0);
+ // Assertions on the next line are required by section B.8 here:
+ // http://www.nongnu.org/lmi/7702.html
+ // and therefore must not blithely be weakened, even if there's
+ // a good reason for loosening the assertions above.
+ LMI_ASSERT(0.0 <= a && 0.0 <= b && -1.0 < c);
+ mm d(charges.prem_load_target ); LMI_ASSERT(0.0 <= d && d < 1.0);
+ mm e(charges.prem_load_excess ); LMI_ASSERT(0.0 <= e && e < 1.0);
+ mm f(charges.policy_fee_monthly ); LMI_ASSERT(0.0 <= f );
+ mm g(charges.policy_fee_annual ); LMI_ASSERT(0.0 <= g );
+ mm h(charges.specamt_load_monthly); LMI_ASSERT(0.0 <= h && h < 1.0);
+ mm i(charges.qab_gio_rate ); LMI_ASSERT(0.0 <= i && i < 1.0);
+ mm j(charges.qab_adb_rate ); LMI_ASSERT(0.0 <= j && j < 1.0);
+ mm k(charges.qab_term_rate ); LMI_ASSERT(0.0 <= k && k < 1.0);
+ mm l(charges.qab_spouse_rate ); LMI_ASSERT(0.0 <= l && l < 1.0);
+ mm m(charges.qab_child_rate ); LMI_ASSERT(0.0 <= m && m < 1.0);
+ mm n(charges.qab_waiver_rate ); LMI_ASSERT(0.0 <= n && n < 1.0);
+
ULCommFns const cf(qc, ic, ig, dbo, mce_monthly);
M_ = cf.kM();
Modified: lmi/trunk/gpt_test.cpp
===================================================================
--- lmi/trunk/gpt_test.cpp 2013-10-27 11:43:40 UTC (rev 5807)
+++ lmi/trunk/gpt_test.cpp 2013-10-27 22:00:19 UTC (rev 5808)
@@ -368,6 +368,49 @@
,""
);
parms = s_parms(); // Reset.
+
+ // Monthly q shorter than other vector parameters.
+ q_m.resize(99);
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
+
+ // Monthly q equal to unity: probably a bad idea, but permitted.
+ q_m[q_m.size() - 1] = 1.0;
+ instantiate_cf();
+ initialize(0); // Reset.
+
+ // Monthly q greater than unity.
+ q_m[q_m.size() - 1] = 1.001;
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
+
+ // Negative monthly q.
+ q_m[0] = -0.001;
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
+
+ // Premium load equal to unity.
+ prem_load_target[0] = 1.0;
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
+
+ // Monthly specamt load equal to unity.
+ specamt_load_monthly[0] = 1.0;
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
+
+ // Monthly QAB rate equal to unity.
+ qab_adb_rate[0] = 1.0;
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
+
+ // Negative premium loads are trapped. They are known to have been
+ // used, if rarely, and presumably just reduce guidelines; but
+ // it's not worth the trouble to validate premium calculations
+ // in advance under rare and questionable circumstances.
+ prem_load_excess[0] = -0.01;
+ BOOST_TEST_THROW(instantiate_cf(), std::runtime_error, "");
+ initialize(0); // Reset.
}
/// The obsolescent GPT class more or less requires this ugliness.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5808] Assert and unit-test even more invariants,
Greg Chicares <=