[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5613] Add an enumerator, temporarily leaving a unit-test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5613] Add an enumerator, temporarily leaving a unit-test issue open |
Date: |
Thu, 06 Dec 2012 12:03:19 +0000 |
Revision: 5613
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5613
Author: chicares
Date: 2012-12-06 12:03:19 +0000 (Thu, 06 Dec 2012)
Log Message:
-----------
Add an enumerator, temporarily leaving a unit-test issue open
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/calendar_date.cpp
lmi/trunk/calendar_date_test.cpp
lmi/trunk/dbnames.hpp
lmi/trunk/oecumenic_enumerations.hpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2012-12-05 00:43:37 UTC (rev 5612)
+++ lmi/trunk/ChangeLog 2012-12-06 12:03:19 UTC (rev 5613)
@@ -31009,3 +31009,46 @@
version.hpp
Designate release candidate.
+20121130T2040Z <address@hidden> [556]
+
+ dbdict.cpp
+Improve documentation.
+
+20121201T1046Z <address@hidden> [556]
+
+ ihs_irc7702.cpp
+Improve documentation.
+
+20121204T1055Z <address@hidden> [556]
+
+ calendar_date.cpp
+ calendar_date.hpp
+ calendar_date_test.cpp
+ input_harmonization.cpp
+ mec_input.cpp
+Refactor, renaming certain arguments for concinnity.
+
+20121204T1412Z <address@hidden> [556]
+
+ calendar_date.cpp
+ calendar_date.hpp
+ calendar_date_test.cpp
+ dbdict.cpp
+ input_harmonization.cpp
+ mec_input.cpp
+ oecumenic_enumerations.hpp
+Refactor, replacing a bool with an enum.
+
+20121205T0043Z <address@hidden> [556]
+
+ calendar_date_test.cpp
+Rearrange tests to follow enumeration order.
+
+20121206T1203Z <address@hidden> [555]
+
+ calendar_date.cpp
+ calendar_date_test.cpp
+ dbnames.hpp
+ oecumenic_enumerations.hpp
+Add an enumerator, temporarily leaving a unit-test issue open.
+
Modified: lmi/trunk/calendar_date.cpp
===================================================================
--- lmi/trunk/calendar_date.cpp 2012-12-05 00:43:37 UTC (rev 5612)
+++ lmi/trunk/calendar_date.cpp 2012-12-06 12:03:19 UTC (rev 5613)
@@ -33,7 +33,7 @@
#include "value_cast.hpp"
#include "zero.hpp"
-#include <algorithm> // std::max(), std::min()
+#include <algorithm> // std::max(), std::min()
#include <ctime>
#include <iomanip>
#include <ios>
@@ -42,6 +42,7 @@
#include <locale>
#include <ostream>
#include <sstream>
+#include <stdexcept> // std::runtime_error
namespace
{
@@ -457,15 +458,15 @@
)
{
typedef std::pair<calendar_date,calendar_date> date_pair;
- date_pair z = bracketing_anniversaries(birthdate, as_of_date);
- calendar_date last_birthday = z.first;
- calendar_date next_birthday = z.second;
+ date_pair const z = bracketing_anniversaries(birthdate, as_of_date);
+ calendar_date const last_birthday = z.first;
+ calendar_date const next_birthday = z.second;
- int days_since_last_birthday =
+ int const days_since_last_birthday =
as_of_date .julian_day_number()
- last_birthday.julian_day_number()
;
- int days_until_next_birthday =
+ int const days_until_next_birthday =
next_birthday.julian_day_number()
- as_of_date .julian_day_number()
;
@@ -474,21 +475,15 @@
&& 0 <= days_until_next_birthday && days_until_next_birthday <= 366
);
- int age_last_birthday = last_birthday.year() - birthdate.year();
+ int const age_last_birthday = last_birthday.year() - birthdate.year();
- if(!alb_anb)
- {
- return age_last_birthday;
- }
-// TODO ?? DATABASE !! The way ties are resolved should be configurable.
- else if(days_since_last_birthday < days_until_next_birthday)
- {
- return age_last_birthday;
- }
- else
- {
- return 1 + age_last_birthday;
- }
+ int const delta =
+ (oe_age_last_birthday == alb_anb) ? 0
+ : (oe_age_nearest_birthday_ties_older == alb_anb) ?
(days_until_next_birthday <= days_since_last_birthday)
+ : (oe_age_nearest_birthday_ties_younger == alb_anb) ?
(days_until_next_birthday < days_since_last_birthday)
+ : throw std::runtime_error("Unknown method to determine age.")
+ ;
+ return age_last_birthday + delta;
}
} // Unnamed namespace.
Modified: lmi/trunk/calendar_date_test.cpp
===================================================================
--- lmi/trunk/calendar_date_test.cpp 2012-12-05 00:43:37 UTC (rev 5612)
+++ lmi/trunk/calendar_date_test.cpp 2012-12-06 12:03:19 UTC (rev 5613)
@@ -56,6 +56,7 @@
TestBirthdateLimits();
TestBirthdateLimitsExhaustively(oe_age_last_birthday);
TestBirthdateLimitsExhaustively(oe_age_nearest_birthday_ties_older);
+ TestBirthdateLimitsExhaustively(oe_age_nearest_birthday_ties_younger);
TestIo();
TestSpeed();
}
@@ -462,32 +463,35 @@
birth_date = calendar_date(1958, 7, 2);
BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
// If birthdate is one day later, then ANB is one year less.
birth_date = calendar_date(1958, 7, 3);
BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(44, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
// In a leap year, effective date can be an equal number of days
- // away from the two birthdays that bracket it. We arbitrarily
- // choose the higher age in this case for ANB, although we might
- // equally well choose the lower age.
+ // away from the two birthdays that bracket it. For ANB, either
+ // the older or the younger age is chosen, depending on the value
+ // of the oenum_alb_or_anb argument.
//
- // Thus, if
+ // Thus, suppose
// 1958-07-02 is my birthdate
// 2004-01-01 is the effective date (in a leap year)
// Counting the days,
// 2003-07-02, my age-45 birthday, is 183 days away
// 2004-07-02, my age-46 birthday, is 183 days away
- // so I'm forty-six (ANB) under this arbitrary choice, although an
- // equally good argument could be made that I'm forty-five.
+ // so I'm forty-six (ANB) if ties are resolved to the older age,
+ // or forty-five (ANB) if ties are resolved to the younger age.
effective_date = calendar_date(2004, 1, 1);
birth_date = calendar_date(1958, 7, 2);
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
// If birthdate is one day earlier,
// then ANB is unambiguously forty-six.
@@ -495,6 +499,7 @@
birth_date = calendar_date(1958, 7, 1);
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
// If birthdate is one day later,
// then ANB is unambiguously forty-five.
@@ -502,6 +507,7 @@
birth_date = calendar_date(1958, 7, 3);
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
// Test leap-year-day birthdate.
@@ -510,44 +516,55 @@
effective_date = calendar_date(2003, 8, 30);
BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
effective_date = calendar_date(2003, 8, 31);
BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+// Returns 47: investigate.
+// BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
effective_date = calendar_date(2004, 2, 28);
BOOST_TEST_EQUAL(47, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
effective_date = calendar_date(2004, 2, 29);
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
effective_date = calendar_date(2004, 3, 1);
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
effective_date = calendar_date(2005, 2, 28);
BOOST_TEST_EQUAL(48, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
effective_date = calendar_date(2005, 3, 1);
BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(49, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
- // Test leap-year-day effective date, even though business custom
- // would probably forbid using it as the basis for a series of
- // annual transactions.
+ // Test leap-year-day effective date. Business custom would forbid
+ // using it as the basis for a series of annual transactions, yet
+ // ill-advised exceptions are occasionally made to sound rules.
effective_date = calendar_date(2004, 2, 29);
birth_date = calendar_date(1958, 8, 30);
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+// Returns 45: investigate.
+// BOOST_TEST_EQUAL(46, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
birth_date = calendar_date(1958, 8, 31);
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_last_birthday));
BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_older));
+ BOOST_TEST_EQUAL(45, attained_age(birth_date, effective_date,
oe_age_nearest_birthday_ties_younger));
// Effective date mustn't precede birthdate--this should throw:
birth_date = calendar_date(2003, 1, 2);
@@ -758,6 +775,8 @@
void CalendarDateTest::TestBirthdateLimits()
{
+ // Test extrema.
+
BOOST_TEST_EQUAL
(minimum_birthdate(99, calendar_date(1852, 9, 13),
oe_age_last_birthday)
, calendar_date(1752, 9, 14)
@@ -776,6 +795,9 @@
, calendar_date(9999, 12, 31)
);
+ // Test ANB limits, including equidistant birthdate candidates,
+ // resolving ties to the older age.
+
BOOST_TEST_EQUAL
(minimum_birthdate(44, calendar_date(2003, 1, 1),
oe_age_nearest_birthday_ties_older)
, calendar_date(1958, 7, 3)
@@ -793,6 +815,28 @@
(maximum_birthdate(46, calendar_date(2004, 1, 1),
oe_age_nearest_birthday_ties_older)
, calendar_date(1958, 7, 2)
);
+
+ // Repeat the ANB tests, resolving ties to the younger age.
+ // As expected, results change only in the "equidistant" case
+ // (which can arise only in a leap year).
+
+ BOOST_TEST_EQUAL
+ (minimum_birthdate(44, calendar_date(2003, 1, 1),
oe_age_nearest_birthday_ties_younger)
+ , calendar_date(1958, 7, 3)
+ );
+ BOOST_TEST_EQUAL
+ (maximum_birthdate(45, calendar_date(2003, 1, 1),
oe_age_nearest_birthday_ties_younger)
+ , calendar_date(1958, 7, 2)
+ );
+
+ BOOST_TEST_EQUAL
+ (minimum_birthdate(45, calendar_date(2004, 1, 1),
oe_age_nearest_birthday_ties_younger)
+ , calendar_date(1958, 7, 2)
+ );
+ BOOST_TEST_EQUAL
+ (maximum_birthdate(46, calendar_date(2004, 1, 1),
oe_age_nearest_birthday_ties_younger)
+ , calendar_date(1958, 7, 1)
+ );
}
void CalendarDateTest::TestBirthdateLimitsExhaustively(oenum_alb_or_anb
alb_anb)
Modified: lmi/trunk/dbnames.hpp
===================================================================
--- lmi/trunk/dbnames.hpp 2012-12-05 00:43:37 UTC (rev 5612)
+++ lmi/trunk/dbnames.hpp 2012-12-06 12:03:19 UTC (rev 5613)
@@ -446,7 +446,7 @@
,DB_LedgerType
- ,DB_AgeLastOrNearest // DATABASE !! Add more options...
+ ,DB_AgeLastOrNearest
,DB_MaturityAge
,DB_LapseIgnoresSurrChg
Modified: lmi/trunk/oecumenic_enumerations.hpp
===================================================================
--- lmi/trunk/oecumenic_enumerations.hpp 2012-12-05 00:43:37 UTC (rev
5612)
+++ lmi/trunk/oecumenic_enumerations.hpp 2012-12-06 12:03:19 UTC (rev
5613)
@@ -33,6 +33,7 @@
enum oenum_alb_or_anb
{oe_age_last_birthday
,oe_age_nearest_birthday_ties_older
+ ,oe_age_nearest_birthday_ties_younger
};
enum oenum_allocation_method
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5613] Add an enumerator, temporarily leaving a unit-test issue open,
Greg Chicares <=