[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] odd/gpt 3f6a917 3/5: Factor out and strengthen asser
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] odd/gpt 3f6a917 3/5: Factor out and strengthen assertions |
Date: |
Tue, 27 Apr 2021 12:13:46 -0400 (EDT) |
branch: odd/gpt
commit 3f6a9173239261115ae93efe50d1a5ae76c9b2ea
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Factor out and strengthen assertions
---
gpt_cf_triad_test.cpp | 1 +
gpt_commutation_functions.cpp | 69 +++++++++++++++++++++++++++++++------------
gpt_commutation_functions.hpp | 2 ++
3 files changed, 53 insertions(+), 19 deletions(-)
diff --git a/gpt_cf_triad_test.cpp b/gpt_cf_triad_test.cpp
index 40acdc1..0a1b89f 100644
--- a/gpt_cf_triad_test.cpp
+++ b/gpt_cf_triad_test.cpp
@@ -319,6 +319,7 @@ gpt_scalar_parms gpt_cf_triad_test::s_parms()
,.qab_child_amt = 5000.0
,.qab_waiver_amt = 50000.0
};
+ assert_sanity(z);
return z;
}
diff --git a/gpt_commutation_functions.cpp b/gpt_commutation_functions.cpp
index 46bd140..67ee091 100644
--- a/gpt_commutation_functions.cpp
+++ b/gpt_commutation_functions.cpp
@@ -52,6 +52,52 @@ std::vector<T>& back_sum(std::vector<T>& v, E e)
}
} // Unnamed namespace.
+/// Assert sanity of a 'gpt_scalar_parms' object.
+///
+/// Asserted invariants:
+/// - all members not named /inforce_.*/ are nonnegative
+/// (inforce amounts are unrestricted)
+/// - the endowment benefit does not exceed the (f)(3) benefit
+/// - 'issued_today' and 'duration' are mutually consistent:
+/// - if the policy was issued today, its duration must be zero
+/// - if duration != 0, the policy cannot have been issued today
+/// thus: NOT ('true == issued_today' AND '0 != duration')
+/// - a 1035 exchange can occur only on the issue date
+///
+/// 7702 !! Reconsider this:
+/// Both 'gpt_scalar_parms' and 'gpt_vector_parms' were designed as
+/// simple parameter objects, and each was originally intended to be
+/// passed to one function only, so it was okay to assert invariants
+/// only where they were passed in. For 'gpt_vector_parms', that's
+/// still true. But 'gpt_scalar_parms' has acquired more members and
+/// more uses, and more invariants, so arguably it is no longer a
+/// "behaviorless aggregate".
+
+void assert_sanity(gpt_scalar_parms const& args)
+{
+ LMI_ASSERT(0 <= args.duration );
+ LMI_ASSERT(0.0 <= args.f3_bft );
+ LMI_ASSERT(0.0 <= args.endt_bft );
+ LMI_ASSERT(0.0 <= args.target_prem );
+ LMI_ASSERT(0.0 <= args.chg_sa_base );
+ LMI_ASSERT(0.0 <= args.gross_1035 );
+ // inforce_glp unrestricted
+ // inforce_cum_glp unrestricted
+ // inforce_gsp unrestricted
+ // inforce_cum_pmt unrestricted
+ LMI_ASSERT(0.0 <= args.qab_gio_amt );
+ LMI_ASSERT(0.0 <= args.qab_adb_amt );
+ LMI_ASSERT(0.0 <= args.qab_term_amt );
+ LMI_ASSERT(0.0 <= args.qab_spouse_amt);
+ LMI_ASSERT(0.0 <= args.qab_child_amt );
+ LMI_ASSERT(0.0 <= args.qab_waiver_amt);
+
+ LMI_ASSERT(args.endt_bft <= args.f3_bft);
+
+ LMI_ASSERT(!(args.issued_today && 0 != args.duration));
+ LMI_ASSERT( args.issued_today || 0.0 == args.gross_1035);
+}
+
/// Constructor.
///
/// Asserted preconditions: All argument vectors, including those in
@@ -221,11 +267,8 @@ gpt_cf_triad::gpt_cf_triad
/// but then sometimes one would need to be thrown away (as when
/// specified amount is determined by a GLP or GSP strategy).
///
-/// Asserted preconditions: 'duration' is within its natural bounds;
-/// other members of 'args' are nonnegative, including 'gross_1035'
-/// even though it isn't used here (because it's so easy to test),
-/// but excluding inforce amounts (which can be negative); and the
-/// endowment benefit does not exceed the (f)(3) benefit.
+/// Asserted preconditions: Parameter object 'args' is sane, and
+/// 'args.duration' is a valid index.
///
/// Asserted postcondition: Returned GLP or GSP is nonnegative; thus,
/// while adjusted premium 'A+B-C' may be negative, {A,B,C} are all
@@ -241,20 +284,8 @@ double gpt_cf_triad::calculate_premium
,mcenum_dbopt_7702 dbo
) const
{
- LMI_ASSERT(0 <= args.duration );
- LMI_ASSERT(args.duration < length_ );
- LMI_ASSERT(0.0 <= args.f3_bft );
- LMI_ASSERT(0.0 <= args.endt_bft );
- LMI_ASSERT(0.0 <= args.target_prem );
- LMI_ASSERT(0.0 <= args.chg_sa_base );
- LMI_ASSERT(0.0 <= args.gross_1035 );
- LMI_ASSERT(0.0 <= args.qab_gio_amt );
- LMI_ASSERT(0.0 <= args.qab_adb_amt );
- LMI_ASSERT(0.0 <= args.qab_term_amt );
- LMI_ASSERT(0.0 <= args.qab_spouse_amt);
- LMI_ASSERT(0.0 <= args.qab_child_amt );
- LMI_ASSERT(0.0 <= args.qab_waiver_amt);
- LMI_ASSERT(args.endt_bft <= args.f3_bft);
+ assert_sanity(args);
+ LMI_ASSERT(args.duration < length_);
gpt_commfns const& cf =
(oe_glp == glp_or_gsp && mce_option1_for_7702 == dbo) ? cf_glp_dbo_1
diff --git a/gpt_commutation_functions.hpp b/gpt_commutation_functions.hpp
index 60ef177..7d65d7f 100644
--- a/gpt_commutation_functions.hpp
+++ b/gpt_commutation_functions.hpp
@@ -144,6 +144,8 @@ struct gpt_scalar_parms
#endif // no operator<=>
};
+void assert_sanity(gpt_scalar_parms const&);
+
/// Commutation functions specialized for GPT calculations.
///
/// All members are private: only its one friend can use this class.