[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5788] Augment unit tests
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5788] Augment unit tests |
Date: |
Thu, 10 Oct 2013 22:57:37 +0000 |
Revision: 5788
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5788
Author: chicares
Date: 2013-10-10 22:57:35 +0000 (Thu, 10 Oct 2013)
Log Message:
-----------
Augment unit tests
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/Makefile.am
lmi/trunk/gpt_test.cpp
lmi/trunk/objects.make
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2013-10-10 12:11:44 UTC (rev 5787)
+++ lmi/trunk/ChangeLog 2013-10-10 22:57:35 UTC (rev 5788)
@@ -32616,3 +32616,56 @@
gpt_commutation_functions.hpp
Improve documentation.
+20131003T2105Z <address@hidden> [542]
+
+ gpt_test.cpp [new file]
+ objects.make
+Add GPT unit tests.
+
+20131003T2302Z <address@hidden> [542]
+
+ gpt_commutation_functions.hpp
+Improve documentation.
+
+20131008T2211Z <address@hidden> [542]
+
+ gpt_test.cpp
+Rearrange.
+
+20131008T2224Z <address@hidden> [542]
+
+ gpt_test.cpp
+Refactor to facilitate reuse.
+
+20131009T2229Z <address@hidden> [542]
+
+ gpt_test.cpp
+Rearrange.
+
+20131010T0017Z <address@hidden> [542]
+
+ gpt_test.cpp
+Refactor for flexibility.
+
+20131010T1042Z <address@hidden> [542]
+
+ Makefile.am
+List all "headers".
+
+20131010T1121Z <address@hidden> [542]
+
+ Makefile.am
+Refactor for concinnity with 'objects.make'.
+
+20131010T1211Z <address@hidden> [542]
+
+ Makefile.am
+Add numerous missing pieces.
+
+20131010T2257Z <address@hidden> [542]
+
+ Makefile.am
+ gpt_test.cpp
+ objects.make
+Augment unit tests.
+
Modified: lmi/trunk/Makefile.am
===================================================================
--- lmi/trunk/Makefile.am 2013-10-10 12:11:44 UTC (rev 5787)
+++ lmi/trunk/Makefile.am 2013-10-10 22:57:35 UTC (rev 5788)
@@ -628,6 +628,7 @@
expm1.c \
gpt_commutation_functions.cpp \
gpt_test.cpp \
+ ihs_irc7702.cpp \
timer.cpp
test_gpt_CXXFLAGS = $(AM_CXXFLAGS)
Modified: lmi/trunk/gpt_test.cpp
===================================================================
--- lmi/trunk/gpt_test.cpp 2013-10-10 12:11:44 UTC (rev 5787)
+++ lmi/trunk/gpt_test.cpp 2013-10-10 22:57:35 UTC (rev 5788)
@@ -27,8 +27,10 @@
#endif // __BORLANDC__
#include "gpt_commutation_functions.hpp"
+#include "ihs_irc7702.hpp"
#include "assert_lmi.hpp"
+#include "materially_equal.hpp"
#include "math_functors.hpp"
#include "test_tools.hpp"
#include "timer.hpp"
@@ -110,6 +112,9 @@
static void initialize(int issue_age);
static gpt_vector_parms v_parms();
static gpt_cf_triad instantiate_cf();
+ static Irc7702& instantiate_old(int issue_age);
+ static void compare_premiums(int issue_age, double target);
+ static void mete_instantiate_old();
};
/// Initialize GPT vector parameters.
@@ -187,10 +192,157 @@
return gpt_cf_triad(q_m, glp_ic, glp_ig, gsp_ic, gsp_ig, v_parms());
}
+/// The obsolescent GPT class more or less requires this ugliness.
+
+Irc7702* ugliness = 0;
+
+/// Instantiate obsolescent GPT class.
+
+Irc7702& gpt_test::instantiate_old(int issue_age)
+{
+#if defined LMI_COMO_WITH_MINGW
+ throw "Code that uses this obsolescent class segfaults with como.";
+#else // !defined LMI_COMO_WITH_MINGW
+ int const length = q_m.size();
+ std::vector<double> const zero(length, 0.0);
+ delete ugliness;
+ ugliness =
+ (new Irc7702
+ (mce_gpt // a_Test7702
+ ,issue_age // a_IssueAge
+ ,issue_age + length // a_EndtAge
+ ,q_m // a_Qc
+ ,glp_ic // a_GLPic
+ ,gsp_ic // a_GSPic
+ ,glp_ic // a_Ig [ignored here, in effect]
+ ,zero // a_IntDed
+ ,0.0 // a_PresentBftAmt
+ ,0.0 // a_PresentSpecAmt
+ ,0.0 // a_LeastBftAmtEver
+ ,mce_option1_for_7702 // a_PresentDBOpt
+ ,policy_fee_annual // a_AnnChgPol
+ ,policy_fee_monthly // a_MlyChgPol
+ ,specamt_load_monthly // a_MlyChgSpecAmt
+ ,1000000000.0 // a_SpecAmtLoadLimit [in effect,
no limit]
+ ,qab_adb_rate // a_MlyChgADD
+ ,1000000000.0 // a_ADDLimit [in effect, no
limit]
+ ,prem_load_target // a_LoadTgt
+ ,prem_load_excess // a_LoadExc
+ ,0.0 // a_TargetPremium [ignored here]
+ ,round_to<double>(2, r_upward) // a_round_min_premium
+ ,round_to<double>(2, r_downward) // a_round_max_premium
+ ,round_to<double>(0, r_upward) // a_round_min_specamt
+ ,round_to<double>(0, r_downward) // a_round_max_specamt
+ ,0 // a_InforceYear
+ // Kludge to prevent Initialize7702() from calculating premiums:
+ ,1 // a_InforceMonth
+ ,0.0 // a_InforceGLP
+ ,0.0 // a_InforceCumGLP
+ ,0.0 // a_InforceGSP
+ ,0.0 // a_InforceCumPremsPaid
+ )
+ );
+ return *ugliness;
+#endif // !defined LMI_COMO_WITH_MINGW
+}
+
+/// Compare {GSP, GLP opt 1, GLP opt 2} for old and new GPT classes.
+///
+/// For the standard table provided by sample_q(), test all issue ages
+/// and durations, with both a high and a low target because target
+/// affects the algorithm significantly. Counting each premium triplet
+/// as a single test, the number of tests should be (and is) the 100th
+/// triangular number times two (targets): twice 101 choose two, which
+/// is 2*(100*101)/2 = 10100.
+
+void gpt_test::compare_premiums(int issue_age, double target)
+{
+ double const f3bft = 120000.0;
+ double const endt_bft = 100000.0;
+ double const chg_sa_amt = 100000.0;
+ double const qab_gio_amt = 0.0;
+ double const qab_adb_amt = 100000.0;
+ double const qab_term_amt = 0.0;
+ double const qab_spouse_amt = 0.0;
+ double const qab_child_amt = 0.0;
+ double const qab_waiver_amt = 0.0;
+
+ gpt_scalar_parms parms =
+ {0 // duration: reset below
+ ,target
+ ,f3bft
+ ,endt_bft
+ ,chg_sa_amt
+ ,qab_gio_amt
+ ,qab_adb_amt
+ ,qab_term_amt
+ ,qab_spouse_amt
+ ,qab_child_amt
+ ,qab_waiver_amt
+ };
+
+ initialize(issue_age);
+
+ gpt_cf_triad const z = instantiate_cf();
+
+#if !defined LMI_COMO_WITH_MINGW
+ // This test of the obsolescent class segfaults with como.
+ Irc7702& z_old = instantiate_old(issue_age);
+ // Set target (the other arguments don't matter here).
+ z_old.Initialize7702(f3bft, endt_bft, mce_option1_for_7702, target);
+#endif // !defined LMI_COMO_WITH_MINGW
+
+ int const omega = sample_q(0).size();
+ for(int duration = 0; duration < omega - issue_age; ++duration)
+ {
+ parms.duration = duration;
+ double const r0 = z.calculate_premium(oe_gsp, mce_option1_for_7702,
parms);
+ double const r1 = z.calculate_premium(oe_glp, mce_option1_for_7702,
parms);
+ double const r2 = z.calculate_premium(oe_glp, mce_option2_for_7702,
parms);
+#if !defined LMI_COMO_WITH_MINGW
+ double const r0_old = z_old.CalculateGSP(duration, f3bft, endt_bft,
endt_bft );
+ double const r1_old = z_old.CalculateGLP(duration, f3bft, endt_bft,
endt_bft, mce_option1_for_7702);
+ double const r2_old = z_old.CalculateGLP(duration, f3bft, endt_bft,
endt_bft, mce_option2_for_7702);
+ bool const all_materially_equal =
+ materially_equal(r0, r0_old)
+ && materially_equal(r1, r1_old)
+ && materially_equal(r2, r2_old)
+ ;
+ BOOST_TEST(all_materially_equal);
+ if(!all_materially_equal)
+ {
+ std::cout
+ << "Discrepancy: issue_age = " << issue_age
+ << " ; duration = " << duration
+ << "\n new: " << r0 << ' ' << r1 << ' ' << r2
+ << "\n old: " << r0_old << ' ' << r1_old << ' ' << r2_old
+ << std::endl
+ ;
+ }
+#endif // !defined LMI_COMO_WITH_MINGW
+ }
+}
+
void gpt_test::test_premium_calculations()
{
+ int const omega = sample_q(0).size();
+ for(int issue_age = 0; issue_age < omega; ++issue_age)
+ {
+ compare_premiums(issue_age, 1000.0);
+ compare_premiums(issue_age, 1000000.0);
+ }
}
+/// Measure instantiation speed of old GPT class.
+///
+/// This simple pass-through function could have been written inline
+/// with boost::bind, but it's preferable not to drag that in.
+
+void gpt_test::mete_instantiate_old()
+{
+ instantiate_old(0);
+}
+
void gpt_test::assay_speed()
{
initialize(0);
@@ -198,6 +350,9 @@
<< "\n Speed tests..."
<< "\n Init parms: " << TimeAnAliquot(v_parms )
<< "\n Triad : " << TimeAnAliquot(instantiate_cf )
+#if !defined LMI_COMO_WITH_MINGW
+ << "\n Triad old : " << TimeAnAliquot(mete_instantiate_old)
+#endif // !defined LMI_COMO_WITH_MINGW
<< std::endl
;
}
Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make 2013-10-10 12:11:44 UTC (rev 5787)
+++ lmi/trunk/objects.make 2013-10-10 22:57:35 UTC (rev 5788)
@@ -661,6 +661,7 @@
expm1.o \
gpt_commutation_functions.o \
gpt_test.o \
+ ihs_irc7702.o \
timer.o \
handle_exceptions_test$(EXEEXT): \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5788] Augment unit tests,
Greg Chicares <=