[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5779] Add GPT unit tests
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5779] Add GPT unit tests |
Date: |
Thu, 03 Oct 2013 21:05:37 +0000 |
Revision: 5779
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5779
Author: chicares
Date: 2013-10-03 21:05:36 +0000 (Thu, 03 Oct 2013)
Log Message:
-----------
Add GPT unit tests
Modified Paths:
--------------
lmi/trunk/objects.make
Added Paths:
-----------
lmi/trunk/gpt_test.cpp
Added: lmi/trunk/gpt_test.cpp
===================================================================
--- lmi/trunk/gpt_test.cpp (rev 0)
+++ lmi/trunk/gpt_test.cpp 2013-10-03 21:05:36 UTC (rev 5779)
@@ -0,0 +1,147 @@
+// Internal Revenue Code section 7702 guideline premium--unit test.
+//
+// Copyright (C) 2013 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// http://savannah.nongnu.org/projects/lmi
+// email: <address@hidden>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+// $Id$
+
+#ifdef __BORLANDC__
+# include "pchfile.hpp"
+# pragma hdrstop
+#endif // __BORLANDC__
+
+#include "gpt_commutation_functions.hpp"
+
+#include "math_functors.hpp"
+#include "miscellany.hpp" // stifle_warning_for_unused_value()
+#include "test_tools.hpp"
+#include "timer.hpp"
+
+namespace
+{
+/// Convert annual mortality rates to monthly.
+
+std::vector<double> a_to_m(std::vector<double> const& q_a)
+{
+ std::vector<double> q_m(q_a.size());
+ assign(q_m, apply_binary(coi_rate_from_q<double>(), q_a, 1.0 / 11.0));
+ return q_m;
+}
+
+/// SOA database table 42: "1980 US CSO Male Age nearest".
+
+std::vector<double> const& sample_q(int age)
+{
+ static int const n = 100;
+ static double const q[n] =
+ // 0 1 2 3 4 5 6
7 8 9
+ {0.00418, 0.00107, 0.00099, 0.00098, 0.00095, 0.00090, 0.00086,
0.00080, 0.00076, 0.00074 // 00
+ ,0.00073, 0.00077, 0.00085, 0.00099, 0.00115, 0.00133, 0.00151,
0.00167, 0.00178, 0.00186 // 10
+ ,0.00190, 0.00191, 0.00189, 0.00186, 0.00182, 0.00177, 0.00173,
0.00171, 0.00170, 0.00171 // 20
+ ,0.00173, 0.00178, 0.00183, 0.00191, 0.00200, 0.00211, 0.00224,
0.00240, 0.00258, 0.00279 // 30
+ ,0.00302, 0.00329, 0.00356, 0.00387, 0.00419, 0.00455, 0.00492,
0.00532, 0.00574, 0.00621 // 40
+ ,0.00671, 0.00730, 0.00796, 0.00871, 0.00956, 0.01047, 0.01146,
0.01249, 0.01359, 0.01477 // 50
+ ,0.01608, 0.01754, 0.01919, 0.02106, 0.02314, 0.02542, 0.02785,
0.03044, 0.03319, 0.03617 // 60
+ ,0.03951, 0.04330, 0.04765, 0.05264, 0.05819, 0.06419, 0.07053,
0.07712, 0.08390, 0.09105 // 70
+ ,0.09884, 0.10748, 0.11725, 0.12826, 0.14025, 0.15295, 0.16609,
0.17955, 0.19327, 0.20729 // 80
+ ,0.22177, 0.23698, 0.25345, 0.27211, 0.29590, 0.32996, 0.38455,
0.48020, 0.65798, 1.00000 // 90
+ };
+ static std::vector<double> const q_a(q + age, q + n);
+ static std::vector<double> const q_m(a_to_m(q_a));
+ return q_m;
+}
+} // Unnamed namespace.
+
+class gpt_test
+{
+ public:
+ static void test()
+ {
+ test_premium_calculations();
+ assay_speed();
+ }
+
+ private:
+ static void test_premium_calculations();
+ static void assay_speed();
+};
+
+void gpt_test::test_premium_calculations()
+{
+}
+
+void mete_gpt_cf_triad()
+{
+ static std::vector<double> zero(sample_q(0).size(), 0.0);
+ static gpt_vector_parms parms =
+ {zero // prem_load_target
+ ,zero // prem_load_excess
+ ,zero // policy_fee_monthly
+ ,zero // policy_fee_annual
+ ,zero // specamt_load_monthly
+ ,zero // qab_gio_rate
+ ,zero // qab_adb_rate
+ ,zero // qab_term_rate
+ ,zero // qab_spouse_rate
+ ,zero // qab_child_rate
+ ,zero // qab_waiver_rate
+ };
+ static unsigned int length = sample_q(0).size();
+ static std::vector<double> ic(length,
i_upper_12_over_12_from_i<double>()(0.07));
+ static std::vector<double> ig(length,
i_upper_12_over_12_from_i<double>()(0.07));
+ volatile gpt_cf_triad z(sample_q(0), ic, ig, ic, ig, parms);
+ stifle_warning_for_unused_value(z);
+}
+
+void mete_gpt_vector_parms()
+{
+ static std::vector<double> zero(sample_q(0).size(), 0.0);
+ // This is not static: its construction speed is being measured.
+ volatile gpt_vector_parms z =
+ {zero // prem_load_target
+ ,zero // prem_load_excess
+ ,zero // policy_fee_monthly
+ ,zero // policy_fee_annual
+ ,zero // specamt_load_monthly
+ ,zero // qab_gio_rate
+ ,zero // qab_adb_rate
+ ,zero // qab_term_rate
+ ,zero // qab_spouse_rate
+ ,zero // qab_child_rate
+ ,zero // qab_waiver_rate
+ };
+ stifle_warning_for_unused_value(z);
+}
+
+void gpt_test::assay_speed()
+{
+ std::cout
+ << "\n Speed tests..."
+ << "\n Commfns : " << TimeAnAliquot(mete_gpt_cf_triad )
+ << "\n Init parms: " << TimeAnAliquot(mete_gpt_vector_parms)
+ << std::endl
+ ;
+}
+
+int test_main(int, char*[])
+{
+ gpt_test::test();
+ return EXIT_SUCCESS;
+}
+
Property changes on: lmi/trunk/gpt_test.cpp
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: lmi/trunk/objects.make
===================================================================
--- lmi/trunk/objects.make 2013-10-03 08:07:20 UTC (rev 5778)
+++ lmi/trunk/objects.make 2013-10-03 21:05:36 UTC (rev 5779)
@@ -467,6 +467,7 @@
financial_test \
getopt_test \
global_settings_test \
+ gpt_test \
handle_exceptions_test \
ieee754_test \
input_seq_test \
@@ -654,6 +655,14 @@
miscellany.o \
path_utility.o \
+gpt_test$(EXEEXT): \
+ $(common_test_objects) \
+ commutation_functions.o \
+ expm1.o \
+ gpt_commutation_functions.o \
+ gpt_test.o \
+ timer.o \
+
handle_exceptions_test$(EXEEXT): \
$(common_test_objects) \
handle_exceptions_test.o \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5779] Add GPT unit tests,
Greg Chicares <=