[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5792] Assert more preconditions
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5792] Assert more preconditions |
Date: |
Tue, 15 Oct 2013 11:13:48 +0000 |
Revision: 5792
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5792
Author: chicares
Date: 2013-10-15 11:13:45 +0000 (Tue, 15 Oct 2013)
Log Message:
-----------
Assert more preconditions
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-15 09:16:27 UTC (rev 5791)
+++ lmi/trunk/ChangeLog 2013-10-15 11:13:45 UTC (rev 5792)
@@ -32675,3 +32675,19 @@
Measure speed of guideline premium calculations. Clearly the new
implementation takes far too much longer than the old.
+20131013T1537Z <address@hidden> [542]
+
+ gpt_commutation_functions.cpp
+Resolve issue noted 20131011T1213Z.
+
+20131015T0916Z <address@hidden> [542]
+
+ gpt_test.cpp
+Test untrapped precondition failures.
+
+20131015T1113Z <address@hidden> [542]
+
+ gpt_test.cpp
+ gpt_commutation_functions.cpp
+Assert more preconditions.
+
Modified: lmi/trunk/gpt_commutation_functions.cpp
===================================================================
--- lmi/trunk/gpt_commutation_functions.cpp 2013-10-15 09:16:27 UTC (rev
5791)
+++ lmi/trunk/gpt_commutation_functions.cpp 2013-10-15 11:13:45 UTC (rev
5792)
@@ -32,6 +32,7 @@
#include "commutation_functions.hpp"
#include "et_vector.hpp"
+#include <algorithm> // std::min_element()
#include <numeric> // std::partial_sum()
#include <stdexcept>
@@ -57,12 +58,17 @@
/// Constructor.
///
-/// All vectors, including those in the parameter object, must 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. 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 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.
+///
/// We are aware of one old UL policy form that accumulates values
/// quarterly instead of monthly. This could be accommodated by adding
/// an extra parameter, but doesn't seem worth the trouble.
@@ -90,6 +96,7 @@
,N_qab_child_ (length_)
,N_qab_waiver_ (length_)
{
+ LMI_ASSERT(0 < length_ && length_ < methuselah);
LMI_ASSERT(length_ == qc .size());
LMI_ASSERT(length_ == ic .size());
LMI_ASSERT(length_ == ig .size());
@@ -122,18 +129,33 @@
back_sum(N_qab_spouse_, cf.kD() * charges.qab_spouse_rate);
back_sum(N_qab_child_ , cf.kD() * charges.qab_child_rate);
back_sum(N_qab_waiver_, cf.kD() * charges.qab_waiver_rate);
+
+ LMI_ASSERT(0.0 < D_endt_);
+ LMI_ASSERT(0.0 < *std::min_element(D_net_tgt_.begin(), D_net_tgt_.end()));
+ LMI_ASSERT(0.0 < *std::min_element(D_net_exc_.begin(), D_net_exc_.end()));
}
gpt_commfns::~gpt_commfns()
{}
/// Calculate GLP or GSP.
+///
+/// With both gcc-3.4.5 and como-4.3.10.1, writing any assertion(s)
+/// here makes this function about twenty percent slower. However,
+/// the difference is only about a hundred machine cycles, presumably
+/// due to the overhead of exception handling; that's no reason to
+/// avoid asserting preconditions.
+///
+/// Divisions are safe because denominators are asserted upstream to
+/// be greater than zero.
double gpt_commfns::calculate_premium
(oenum_glp_or_gsp glp_or_gsp
,gpt_scalar_parms const& args
) const
{
+ LMI_ASSERT(0 <= args.duration);
+ LMI_ASSERT(static_cast<unsigned int>(args.duration) < length_);
double endowment = D_endt_ * args.endt_bft;
double charges =
M_ [args.duration] * args.f3bft
Modified: lmi/trunk/gpt_test.cpp
===================================================================
--- lmi/trunk/gpt_test.cpp 2013-10-15 09:16:27 UTC (rev 5791)
+++ lmi/trunk/gpt_test.cpp 2013-10-15 11:13:45 UTC (rev 5792)
@@ -216,13 +216,18 @@
gpt_cf_triad const z = instantiate_cf();
parms.duration = -1;
- double const x0 = z.calculate_premium(oe_gsp, mce_option1_for_7702, parms);
+ BOOST_TEST_THROW
+ (z.calculate_premium(oe_gsp, mce_option1_for_7702, parms)
+ ,std::runtime_error
+ ,""
+ );
parms.duration = q_m.size();
- double const x1 = z.calculate_premium(oe_gsp, mce_option1_for_7702, parms);
-
- // Values are bogus, if this line is even reached:
- std::cout << x0 << ' ' << x1 << std::endl;
+ BOOST_TEST_THROW
+ (z.calculate_premium(oe_gsp, mce_option1_for_7702, parms)
+ ,std::runtime_error
+ ,""
+ );
}
/// The obsolescent GPT class more or less requires this ugliness.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5792] Assert more preconditions,
Greg Chicares <=