[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d12c732 2/3: Avoid insane dates in unit test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d12c732 2/3: Avoid insane dates in unit test |
Date: |
Sun, 4 Mar 2018 12:42:37 -0500 (EST) |
branch: master
commit d12c7329789f3b4774ea0e38ab7dd20302735c8a
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Avoid insane dates in unit test
Prevented unexpected exceptions observed with gcc-7 by fixing two
separate issues:
- one date used in a speed test was uninitialized;
- a speed test may perform the same calculation tens of thousands of
times, and incrementing a quasi-global value by tens of thousands
of years readily causes it to assume values past the Y10K-1 limit.
---
calendar_date_test.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/calendar_date_test.cpp b/calendar_date_test.cpp
index b2ecb03..f332fcc 100644
--- a/calendar_date_test.cpp
+++ b/calendar_date_test.cpp
@@ -1074,7 +1074,7 @@ void CalendarDateTest::TestIo()
namespace
{
- calendar_date x;
+ calendar_date x(1776, 7, 4);
calendar_date y(1899, 12, 31);
void mete()
@@ -1100,9 +1100,10 @@ namespace
x = y;
}
- void mete_increment()
+ void mete_stepping()
{
++x;
+ --x;
}
void mete_get_y_m_d()
@@ -1119,8 +1120,8 @@ namespace
void mete_attained_age()
{
- x = add_years_and_months(x, 1, 1, true);
- attained_age(y, x, oe_age_last_birthday);
+ calendar_date t = add_years_and_months(x, 1, 1, true);
+ attained_age(y, t, oe_age_last_birthday);
}
void mete_dob_limit()
@@ -1136,7 +1137,7 @@ void CalendarDateTest::TestSpeed()
<< " Aggregate : " << TimeAnAliquot(mete ) << '\n'
<< " Construct : " << TimeAnAliquot(mete_construct ) << '\n'
<< " Assign : " << TimeAnAliquot(mete_assign ) << '\n'
- << " Increment : " << TimeAnAliquot(mete_increment ) << '\n'
+ << " Stepping : " << TimeAnAliquot(mete_stepping ) << '\n'
<< " Get y, m, d : " << TimeAnAliquot(mete_get_y_m_d ) << '\n'
<< " Format : " << TimeAnAliquot(mete_format ) << '\n'
<< " Calculate age: " << TimeAnAliquot(mete_attained_age) << '\n'