[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5801] Augment unit tests
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5801] Augment unit tests |
Date: |
Fri, 18 Oct 2013 23:58:14 +0000 |
Revision: 5801
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5801
Author: chicares
Date: 2013-10-18 23:58:13 +0000 (Fri, 18 Oct 2013)
Log Message:
-----------
Augment unit tests
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/gpt_test.cpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2013-10-18 12:08:12 UTC (rev 5800)
+++ lmi/trunk/ChangeLog 2013-10-18 23:58:13 UTC (rev 5801)
@@ -32723,3 +32723,19 @@
Fix defect introduced 20131003T2105Z: misplaced 'static' caused an
argument to be ignored, weakening downstream tests.
+20131018T1152Z <address@hidden> [542]
+
+ gpt_test.cpp
+Reduce QAB rates and specamt load to more plausible values.
+
+20131018T1208Z <address@hidden> [542]
+
+ gpt_test.cpp
+ stl_extensions.hpp
+Introduce a valuable invariant.
+
+20131018T2358Z <address@hidden> [542]
+
+ gpt_test.cpp
+Augment unit tests.
+
Modified: lmi/trunk/gpt_test.cpp
===================================================================
--- lmi/trunk/gpt_test.cpp 2013-10-18 12:08:12 UTC (rev 5800)
+++ lmi/trunk/gpt_test.cpp 2013-10-18 23:58:13 UTC (rev 5801)
@@ -73,6 +73,119 @@
return std::vector<double>(q_m.begin() + age, q_m.end());
}
+/// This target premium is chosen to lie between the column minimums
+/// and maximums of 'touchstone', so that all paths through the
+/// premium-calculation code are exercised.
+
+double const touchstone_target = 10000.0;
+
+/// Guideline premiums for ages [0, 100), using this module's default
+/// assumptions and 'touchstone_target'.
+
+double const touchstone[100][3] =
+ { // GSP GLP, DBO 1 GLP, DBO2 age
+ { 7038.68351698240, 585.526862159977, 1423.177437435097} // 0
+ ,{ 6798.19554639087, 582.279184423523, 1454.983214917078} // 1
+ ,{ 6917.55938814647, 595.654331516075, 1503.925334003016} // 2
+ ,{ 7054.08836427570, 610.098531559143, 1555.393346766061} // 3
+ ,{ 7200.42959441599, 625.289620498655, 1609.147412434138} // 4
+ ,{ 7359.59499719102, 641.377482638437, 1665.394363517762} // 5
+ ,{ 7534.77264967186, 658.521212308809, 1724.351061338387} // 6
+ ,{ 7725.75253256339, 676.725078857967, 1786.091846010552} // 7
+ ,{ 7935.89559393773, 696.159622871104, 1850.848292115368} // 8
+ ,{ 8163.99574210983, 716.784860802655, 1918.658536904343} // 9
+ ,{ 8408.78751694222, 738.558854641057, 1989.562952864434} // 10
+ ,{ 8670.12948570098, 761.493429259317, 2063.655691084516} // 11
+ ,{ 8943.15168307475, 785.376698055932, 2140.829866947342} // 12
+ ,{ 9223.90802461156, 810.039562357985, 2221.025457355350} // 13
+ ,{ 9505.89053285976, 835.188054645305, 2304.076471840259} // 14
+ ,{ 9786.93746033387, 860.736839659286, 2390.016550335725} // 15
+ ,{ 10064.09674883057, 886.594731233553, 2478.881457455330} // 16
+ ,{ 10335.79183986005, 912.779767479432, 2570.813425707223} // 17
+ ,{ 10606.46561801551, 939.427367607391, 2666.066827908476} // 18
+ ,{ 10881.93560436608, 966.857566950968, 2765.066561632714} // 19
+ ,{ 11166.04774456913, 995.295455608219, 2868.154802925353} // 20
+ ,{ 11464.01637080176, 1025.041342657894, 2975.744576543945} // 21
+ ,{ 11780.21027563471, 1056.358083620659, 3088.218208975990} // 22
+ ,{ 12119.25033135827, 1089.528374470945, 3205.978738573638} // 23
+ ,{ 12483.74838399238, 1124.736519495792, 3329.345194701353} // 24
+ ,{ 12876.47313540750, 1162.182018861173, 3458.654561239592} // 25
+ ,{ 13300.35865601369, 1202.081288458987, 3594.262976739506} // 26
+ ,{ 13756.26463939956, 1244.546633061123, 3736.440115687674} // 27
+ ,{ 14244.00139621636, 1289.639330123234, 3885.418226907989} // 28
+ ,{ 14764.51444284111, 1337.490074314652, 4041.497806206768} // 29
+ ,{ 15317.72104376862, 1388.179505203846, 4204.943822021073} // 30
+ ,{ 15904.67615879494, 1441.860768068979, 4376.092191478663} // 31
+ ,{ 16524.33383892391, 1498.574118828346, 4555.19126684717 } // 32
+ ,{ 17178.91923180180, 1558.559910057550, 4742.66949911027 } // 33
+ ,{ 17867.56028901856, 1621.886308664094, 4938.81829564135 } // 34
+ ,{ 18591.55843367445, 1688.762387605737, 5144.05870554551 } // 35
+ ,{ 19351.26721643064, 1759.352690245432, 5358.78435177983 } // 36
+ ,{ 20147.12673213025, 1833.840248511528, 5583.41556319251 } // 37
+ ,{ 20978.62057777484, 1912.360234827265, 5818.34595858885 } // 38
+ ,{ 21846.34193266791, 1995.133368677091, 6064.05294668874 } // 39
+ ,{ 22749.96476442091, 2082.335591042036, 6320.99151825042 } // 40
+ ,{ 23690.27901372488, 2174.235376765823, 6589.70614937677 } // 41
+ ,{ 24666.18011714967, 2270.988479559321, 6870.66752222614 } // 42
+ ,{ 25680.67346367356, 2373.064175530010, 7164.60994754848 } // 43
+ ,{ 26733.01333128616, 2480.691139489740, 7472.09234094005 } // 44
+ ,{ 27825.53320587390, 2594.354982641396, 7793.89002818164 } // 45
+ ,{ 28957.87517174733, 2714.372960009581, 8130.66370509233 } // 46
+ ,{ 30132.73718519145, 2841.340030468526, 8483.30199083677 } // 47
+ ,{ 31351.18686378591, 2975.772554671284, 8852.64633067760 } // 48
+ ,{ 32615.47640454942, 3118.340626160647, 9239.66612712437 } // 49
+ ,{ 33925.37360974723, 3269.561842386675, 9645.23247070155 } // 50
+ ,{ 35282.72955074919, 3430.199227135144, 10069.64394976404 } // 51
+ ,{ 36684.32232853716, 3600.612419051228, 10510.36974551134 } // 52
+ ,{ 38128.94087403525, 3781.391207568697, 10972.25718541429 } // 53
+ ,{ 39613.93885174853, 3973.035706974506, 11456.25858694856 } // 54
+ ,{ 41136.11931963878, 4176.030195457377, 11963.35754058970 } // 55
+ ,{ 42695.98388934036, 4391.312735019566, 12494.88289937905 } // 56
+ ,{ 44292.80919530735, 4619.78365830111 , 13052.16853061377 } // 57
+ ,{ 45929.5718921291 , 4862.89582994844 , 13636.93530368279 } // 58
+ ,{ 47607.4216271391 , 5122.05692743359 , 14250.88599353768 } // 59
+ ,{ 49327.3204391780 , 5398.82901312474 , 14895.83704266039 } // 60
+ ,{ 51087.0675327450 , 5694.52747069843 , 15573.47429994832 } // 61
+ ,{ 52883.6498834271 , 6010.49270177416 , 16285.54274598828 } // 62
+ ,{ 54711.8755883987 , 6347.85877060754 , 17033.72432934544 } // 63
+ ,{ 56565.1938672560 , 6707.61038666661 , 17819.70417095833 } // 64
+ ,{ 58438.5603842135 , 7091.02873646156 , 18645.45168807685 } // 65
+ ,{ 60328.4826730125 , 7499.76716701808 , 19513.26040865944 } // 66
+ ,{ 62235.7122880404 , 7936.48566273830 , 20426.07981227157 } // 67
+ ,{ 64161.4476182190 , 8404.31827131655 , 21387.17409476018 } // 68
+ ,{ 66108.1111518329 , 8907.15411732119 , 22400.24884101083 } // 69
+ ,{ 68075.2968655369 , 9448.81780751370 , 23468.99783484597 } // 70
+ ,{ 70056.5435719881 , 10031.72536519677 , 24596.65312417418 } // 71
+ ,{ 72041.9336211511 , 10651.63206077490 , 25786.24096652694 } // 72
+ ,{ 74017.1917991849 , 11315.03532154118 , 27040.39635816422 } // 73
+ ,{ 75965.3671901283 , 12020.79055649973 , 28361.55036911865 } // 74
+ ,{ 77874.9283195687 , 12768.50924453628 , 29753.25818586441 } // 75
+ ,{ 79740.9467500571 , 13559.48673681164 , 31220.67845789502 } // 76
+ ,{ 81564.9188631318 , 14397.45383224088 , 32770.90259122696 } // 77
+ ,{ 83353.8927677665 , 15289.23021935768 , 34413.18965221712 } // 78
+ ,{ 85119.4534825334 , 16245.42797729094 , 36159.17795669160 } // 79
+ ,{ 86867.9022927022 , 17276.34224247499 , 38021.03919611617 } // 80
+ ,{ 88597.0645980752 , 18389.30243866668 , 40010.68845409491 } // 81
+ ,{ 90299.0078252165 , 19588.56033848707 , 42140.39788964697 } // 82
+ ,{ 91957.2671095038 , 20871.36395800513 , 44422.07949981734 } // 83
+ ,{ 93552.4553979591 , 22229.02331799561 , 46869.2271839139 } // 84
+ ,{ 95074.4281098265 , 23655.68252683349 , 49502.2183174530 } // 85
+ ,{ 96522.0685347940 , 25150.86248432227 , 52350.8908700057 } // 86
+ ,{ 97903.4505017087 , 26723.33948060062 , 55458.2004177460 } // 87
+ ,{ 99232.0338500975 , 28391.52743840341 , 58883.2994927711 } // 88
+ ,{100526.4169722035 , 30187.58145327271 , 62707.8680603863 } // 89
+ ,{101809.7855145883 , 32162.72117506931 , 67045.4528454541 } // 90
+ ,{103109.8559654121 , 34396.12222752874 , 72056.5609689122 } // 91
+ ,{104460.6581669420 , 37013.30252275156 , 77975.2369131742 } // 92
+ ,{105902.8500872039 , 40216.83342704028 , 85154.0907265174 } // 93
+ ,{107484.6433387535 , 44350.39801579426 , 94149.210398289 } // 94
+ ,{109230.5635533567 , 49945.9025675526 , 105840.9285717971 } // 95
+ ,{111114.2974785539 , 57867.8963646683 , 121708.1682942241 } // 96
+ ,{112969.7125568349 , 69513.6146174326 , 144360.4558901023 } // 97
+ ,{114149.2609045463 , 86890.3134223641 , 178406.5103343175 } // 98
+ ,{111221.7271446342 , 112671.1356520957 , 228328.2710683905 } // 99
+ };
+
// These could be made static members of class gpt_test, but this way
// is more convenient; see also:
//
https://www.securecoding.cert.org/confluence/display/cplusplus/MSC22-CPP.+Do+not+define+static+private+members
@@ -316,13 +429,6 @@
}
/// 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)
{
@@ -374,14 +480,53 @@
}
}
+/// Compare {GSP, GLP opt 1, GLP opt 2} to validated stored values.
+///
+/// For the standard table provided by sample_q(), test all issue ages
+/// and durations, with a target premium ('touchstone_target') chosen
+/// to exercise all paths through the premium-calculation code.
+///
+/// The number of premium triplets tested should be, and is, the 100th
+/// triangular number: 101 choose two, which is (100*101)/2 = 5050.
+///
+/// For the nonce, similarly compare new to obsolescent GPT class.
+
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);
+ compare_premiums(issue_age, 100.0); // < min(touchstone)
+ compare_premiums(issue_age, 10000.0); // = touchstone_target
+ compare_premiums(issue_age, 1000000.0); // > max(touchstone)
}
+
+ gpt_scalar_parms parms = s_parms();
+ parms.target = touchstone_target;
+ int count = 0;
+ for(int issue_age = 0; issue_age < omega; ++issue_age)
+ {
+ initialize(issue_age);
+ gpt_cf_triad const z = instantiate_cf();
+ 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);
+ int const x_plus_t = issue_age + duration;
+ LMI_ASSERT(0 <= x_plus_t && x_plus_t < omega);
+ bool const all_materially_equal =
+ materially_equal(r0, touchstone[x_plus_t][0])
+ && materially_equal(r1, touchstone[x_plus_t][1])
+ && materially_equal(r2, touchstone[x_plus_t][2])
+ ;
+ BOOST_TEST(all_materially_equal);
+ ++count;
+ }
+ }
+ BOOST_TEST(5050 == count);
}
void gpt_test::mete_premiums()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5801] Augment unit tests,
Greg Chicares <=