[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master ba624fe 4/9: Refactor
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master ba624fe 4/9: Refactor |
Date: |
Tue, 18 Jun 2019 16:43:55 -0400 (EDT) |
branch: master
commit ba624fe2682eb4bc3dd2308e903add173dc16a06
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Refactor
Replaced a large and growing free function with a class that has an
extensible set of short member functions and only const data members.
---
verify_products.cpp | 167 +++++++++++++++++++++++++++++++---------------------
1 file changed, 101 insertions(+), 66 deletions(-)
diff --git a/verify_products.cpp b/verify_products.cpp
index b566464..94c72e2 100644
--- a/verify_products.cpp
+++ b/verify_products.cpp
@@ -39,62 +39,97 @@
namespace
{
-void verify_one_cell
+class product_verifier
+{
+ public:
+ product_verifier
+ (std::string const& product_name
+ ,std::string const& gender_str
+ ,std::string const& smoking_str
+ );
+ void verify();
+
+ private:
+ void verify_7702q();
+
+ std::string const product_name_;
+ std::string const gender_str_ ;
+ std::string const smoking_str_ ;
+ product_data const p_ ;
+ mcenum_gender const gender_ ;
+ mcenum_smoking const smoking_ ;
+ product_database const db0_ ;
+ int const min_age_ ;
+ product_database const db_ ;
+ oenum_cso_era const era_ ;
+ oenum_alb_or_anb const a_b_ ;
+ int const t_ ;
+ bool const axis_g_ ;
+ bool const axis_s_ ;
+ int const omega_ ;
+};
+
+product_verifier::product_verifier
(std::string const& product_name
,std::string const& gender_str
,std::string const& smoking_str
)
-{
- mcenum_gender const gender = mce_gender (gender_str ).value();
- mcenum_smoking const smoking = mce_smoking(smoking_str).value();
-
- product_database const db0
+ :product_name_ {product_name}
+ ,gender_str_ {gender_str}
+ ,smoking_str_ {smoking_str}
+ ,p_ (product_name)
+ ,gender_ {mce_gender (gender_str ).value()}
+ ,smoking_ {mce_smoking(smoking_str).value()}
+ ,db0_
(product_name
- ,gender
+ ,gender_
,mce_standard
- ,smoking
+ ,smoking_
,45
,mce_medical
,mce_s_XX
- );
- int const min_age = db0.query<int>(DB_MinIssAge);
-
- product_database const db
+ )
+ ,min_age_ {db0_.query<int>(DB_MinIssAge)}
+ ,db_
(product_name
- ,gender
+ ,gender_
,mce_standard
- ,smoking
- ,min_age
+ ,smoking_
+ ,min_age_
,mce_medical
,mce_s_XX
- );
-
- auto const era = db.query<oenum_cso_era >(DB_CsoEra);
- auto const a_b = db.query<oenum_alb_or_anb>(DB_AgeLastOrNearest);
- auto const t = db.query<int >(DB_Irc7702QTable);
- auto const axis_g = db.query<bool >(DB_Irc7702QAxisGender);
- auto const axis_s = db.query<bool >(DB_Irc7702QAxisSmoking);
- auto const omega = db.query<int >(DB_MaturityAge);
-
- int const years_to_maturity = omega - min_age;
-
- product_data const p(product_name);
+ )
+ ,era_ {db_.query<oenum_cso_era >(DB_CsoEra)}
+ ,a_b_ {db_.query<oenum_alb_or_anb>(DB_AgeLastOrNearest)}
+ ,t_ {db_.query<int >(DB_Irc7702QTable)}
+ ,axis_g_ {db_.query<bool >(DB_Irc7702QAxisGender)}
+ ,axis_s_ {db_.query<bool >(DB_Irc7702QAxisSmoking)}
+ ,omega_ {db_.query<int >(DB_MaturityAge)}
+{
+}
+void product_verifier::verify()
+{
if
- ( (!axis_g && "Unisex" != gender_str )
- || (!axis_s && "Unismoke" != smoking_str)
+ ( (!axis_g_ && mce_unisex != gender_ )
+ || (!axis_s_ && mce_unismoke != smoking_)
)
{
std::cout
<< " skipping"
- << ' ' << gender_str
- << ' ' << smoking_str
+ << ' ' << gender_str_
+ << ' ' << smoking_str_
<< std::endl
;
return;
}
- switch(db.query<oenum_7702_q_whence>(DB_Irc7702QWhence))
+ verify_7702q();
+}
+
+void product_verifier::verify_7702q()
+{
+ switch(db_.query<oenum_7702_q_whence>(DB_Irc7702QWhence))
{
// Validate irc_7702_q_builtin(), which is implemented in
// terms of cso_table(). The interface of irc_7702_q()
@@ -110,25 +145,25 @@ void verify_one_cell
case oe_7702_q_builtin:
{
std::vector<double> const v0 = cso_table
- (era
+ (era_
,oe_orthodox // No other option currently supported for 7702.
- ,a_b
- ,mce_gender (gender_str).value()
- ,mce_smoking(smoking_str).value()
- ,min_age
- ,omega
+ ,a_b_
+ ,gender_
+ ,smoking_
+ ,min_age_
+ ,omega_
);
std::vector<double> const v1 = irc_7702_q
- (p
- ,db
- ,min_age
- ,years_to_maturity
+ (p_
+ ,db_
+ ,min_age_
+ ,omega_ - min_age_
);
std::cout
<< "7702 q okay: builtin "
<< std::string((v0 == v1) ? "validated" : "PROBLEM")
- << ' ' << gender_str
- << ' ' << smoking_str
+ << ' ' << gender_str_
+ << ' ' << smoking_str_
<< std::endl
;
}
@@ -144,27 +179,27 @@ void verify_one_cell
// known to occur in fabrication.
case oe_7702_q_external_table:
{
- if(0 == t)
+ if(0 == t_)
{
std::cout
- << "7702 q PROBLEM: " << product_name
+ << "7702 q PROBLEM: " << product_name_
<< " nonexistent table zero"
- << ' ' << gender_str
- << ' ' << smoking_str
+ << ' ' << gender_str_
+ << ' ' << smoking_str_
<< std::endl
;
return;
}
std::vector<double> const v0 = cso_table
- (era
+ (era_
,oe_orthodox // No other option currently supported for 7702.
- ,a_b
- ,mce_gender (gender_str).value()
- ,mce_smoking(smoking_str).value()
+ ,a_b_
+ ,gender_
+ ,smoking_
);
- std::string const f = AddDataDir(p.datum("Irc7702QFilename"));
- actuarial_table const a(f, t);
+ std::string const f = AddDataDir(p_.datum("Irc7702QFilename"));
+ actuarial_table const a(f, t_);
std::vector<double> const v1 = a.values
(a.min_age()
,1 + a.max_age() - a.min_age()
@@ -173,25 +208,25 @@ void verify_one_cell
if(v0 == v1)
{
std::cout
- << "7702 q okay: table " << t
- << ' ' << gender_str
- << ' ' << smoking_str
+ << "7702 q okay: table " << t_
+ << ' ' << gender_str_
+ << ' ' << smoking_str_
<< std::endl
;
}
else
{
std::cout
- << "7702 q PROBLEM: " << product_name
- << ' ' << gender_str
- << ' ' << smoking_str
+ << "7702 q PROBLEM: " << product_name_
+ << ' ' << gender_str_
+ << ' ' << smoking_str_
<< std::endl
;
std::cout
- << "\n CSO era: " << era
- << "\n ALB or ANB: " << a_b
+ << "\n CSO era: " << era_
+ << "\n ALB or ANB: " << a_b_
<< "\n table file: " << f
- << "\n table number: " << t
+ << "\n table number: " << t_
<< "\n min age: " << a.min_age()
<< "\n max age: " << a.max_age()
<< "\n cso length: " << lmi::ssize(v0)
@@ -251,14 +286,14 @@ void verify_one_cell
void verify_products()
{
std::vector<std::string> const& products = ce_product_name().all_strings();
- for(auto const& z : products)
+ for(auto const& p : products)
{
- std::cout << "Testing product " << z << '\n';
+ std::cout << "Testing product " << p << '\n';
for(auto const& g : all_strings<mcenum_gender>())
{
for(auto const& s : all_strings<mcenum_smoking>())
{
- verify_one_cell(z, g, s);
+ product_verifier(p, g, s).verify();
}
}
}
- [lmi-commits] [lmi] master updated (e019e5b -> 246081b), Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master f5bb23f 1/9: Improve product-verifier control flow, Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master d89b244 6/9: Make cover page the same for all formats but one, Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master ba624fe 4/9: Refactor,
Greg Chicares <=
- [lmi-commits] [lmi] master e90a3d1 2/9: Rename arguments, Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master 8af7bed 5/9: Apply a recent FINRA header change to Reg D formats, Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master 57bee69 3/9: Remove an ugly expedient, Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master b4f5c34 8/9: Present 'AgentPhone' and 'AgentId' on all GUI skins, Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master 246081b 9/9: Use <border> to improve layout of 'skin.xrc', Greg Chicares, 2019/06/18
- [lmi-commits] [lmi] master e030aaa 7/9: Consolidate lower footer templates, Greg Chicares, 2019/06/18