[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master b8c106c 2/3: Make design by contract possible

From: Greg Chicares
Subject: [lmi-commits] [lmi] master b8c106c 2/3: Make design by contract possible for class database_index
Date: Mon, 10 Jun 2019 12:34:54 -0400 (EDT)

branch: master
commit b8c106cf8d01030d8a7c81a8fe2703bfc9c062d5
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Make design by contract possible for class database_index
    Motivation: in a function such as
        std::vector<double> LMI_SO irc_7702_q
            (product_data     const& product
            ,product_database const& database
            ,int                     issue_age
            ,int                     years_to_maturity
    the last two parameters are superfluous. Class product_database contains
    an instance of class database_index, which embodies 'issue_age'; and
    'years_to_maturity' is simply
    minus 'issue_age'...as long as the product_database object has been
    instantiated in a way that confers such semantic meaning, and not via
    the (expunged) default database_index ctor.
    To that end, isolated product_database::product_database(int) to its
    sole use case (where it's merely a dummy object); rewrote it to use a
    non-default database_index ctor; and expunged the default database_index
 database.hpp   | 9 +++++++--
 dbindex.hpp    | 4 ----
 loads_test.cpp | 1 -
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/database.hpp b/database.hpp
index c1966d9..c2e6cef 100644
--- a/database.hpp
+++ b/database.hpp
@@ -43,6 +43,7 @@ class yare_input;
 class LMI_SO product_database final
+    friend struct LoadsTest;       // For product_database(int).
     friend class input_test;       // For test_product_database().
     friend class premium_tax_test; // For test_rates().
@@ -57,8 +58,6 @@ class LMI_SO product_database final
         ,mcenum_state       StateOfJurisdiction
     explicit product_database(yare_input const&);
-    // Special ctor implemented only in a unit-test TU.
-    explicit product_database(int length);
     product_database(product_database &&) = default;
     product_database(product_database const&) = default;
     ~product_database() = default;
@@ -85,6 +84,12 @@ class LMI_SO product_database final
     bool varies_by_state(e_database_key) const;
+    // Special ctor used only in the unit-test TU for class Loads.
+    explicit product_database(int length)
+        :index_  {mce_male, mce_rated, mce_smoker, 0, mce_medical, mce_s_XX}
+        ,length_ {length}
+        {}
     product_database& operator=(product_database const&) = delete;
     void initialize(std::string const& product_name);
diff --git a/dbindex.hpp b/dbindex.hpp
index 764f168..4341177 100644
--- a/dbindex.hpp
+++ b/dbindex.hpp
@@ -69,10 +69,6 @@ enum enum_database_dimensions
 class database_index
-    database_index()
-        :idx_(number_of_indices)
-    {}
         (mcenum_gender   gender
         ,mcenum_class    uw_class
diff --git a/loads_test.cpp b/loads_test.cpp
index c63ce44..830df7d 100644
--- a/loads_test.cpp
+++ b/loads_test.cpp
@@ -48,7 +48,6 @@ std::vector<double> BasicValues::GetCurrSpecAmtLoadTable() 
const {return dummy_v
 std::vector<double> BasicValues::GetGuarSpecAmtLoadTable() const {return 
 #include "database.hpp"
-product_database::product_database(int length) :length_(length) {}
 int product_database::length() const {return length_;}
 void product_database::query_into(e_database_key, std::vector<double>& v) 
const {v.resize(length_);}
 double product_database::query(e_database_key, database_index const&) const 
{return 0.0;}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]