[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 340ae3c 4/8: Test mixed-mode date arithmetic
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 340ae3c 4/8: Test mixed-mode date arithmetic |
Date: |
Sun, 25 Feb 2018 17:15:14 -0500 (EST) |
branch: master
commit 340ae3cfb53961b530ae0e8d392e8282fe65f5de
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Test mixed-mode date arithmetic
---
calendar_date_test.cpp | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/calendar_date_test.cpp b/calendar_date_test.cpp
index 1cdce60..b2ecb03 100644
--- a/calendar_date_test.cpp
+++ b/calendar_date_test.cpp
@@ -43,6 +43,7 @@ struct CalendarDateTest
TestYMDBounds();
TestYmdToJdnAndJdnToYmd();
TestLeapYear();
+ TestMixedModeArithmetic();
TestIncrementing();
TestAgeCalculations();
TestIntegralDuration();
@@ -60,6 +61,7 @@ struct CalendarDateTest
static void TestYMDBounds();
static void TestYmdToJdnAndJdnToYmd();
static void TestLeapYear();
+ static void TestMixedModeArithmetic();
static void TestIncrementing();
static void TestAgeCalculations();
static void TestIntegralDuration();
@@ -230,6 +232,31 @@ void CalendarDateTest::TestLeapYear()
BOOST_TEST( calendar_date(4000, 1, 1).is_leap_year());
}
+void CalendarDateTest::TestMixedModeArithmetic()
+{
+ calendar_date const d = calendar_date(2003, 12, 31);
+
+ BOOST_TEST_EQUAL( 1 + d, calendar_date(2004, 1, 1));
+ BOOST_TEST_EQUAL( d + 1, calendar_date(2004, 1, 1));
+ BOOST_TEST_EQUAL( d - 1, calendar_date(2003, 12, 30));
+// BOOST_TEST_EQUAL( 1 - d, calendar_date(2004, 12, 30)); // forbidden
+ BOOST_TEST_EQUAL(1 + d - 1, calendar_date(2003, 12, 31));
+
+ BOOST_TEST_EQUAL( 3 + d, calendar_date(2004, 1, 3));
+ BOOST_TEST_EQUAL( d + 3, calendar_date(2004, 1, 3));
+ BOOST_TEST_EQUAL( d - 3, calendar_date(2003, 12, 28));
+ BOOST_TEST_EQUAL(3 + d - 3, calendar_date(2003, 12, 31));
+ BOOST_TEST_EQUAL(7 + d - 5, calendar_date(2004, 1, 2));
+
+ calendar_date e = calendar_date(2000, 2, 28);
+
+// BOOST_TEST_EQUAL( 3 += e, calendar_date(2000, 3, 3)); // forbidden
+ BOOST_TEST_EQUAL( e += 3, calendar_date(2000, 3, 2));
+ BOOST_TEST_EQUAL( e -= 3, calendar_date(2000, 2, 28));
+ BOOST_TEST_EQUAL(3 + e -= 3, calendar_date(2000, 2, 28));
+ BOOST_TEST_EQUAL(7 + e -= 5, calendar_date(2000, 3, 1));
+}
+
void CalendarDateTest::TestIncrementing()
{
// Test incrementing by a whole number of years. If a policy
- [lmi-commits] [lmi] master updated (0c16a43 -> 5d71aea), Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master f15d7c0 2/8: Remove unwanted postincrement operator, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master f481f1e 1/8: Expunge commentary that has become irrelevant, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master db53742 3/8: Define only the relational operators that have proved useful for dates, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 1c65496 5/8: Dispense with boost/operators for one class, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 340ae3c 4/8: Test mixed-mode date arithmetic,
Greg Chicares <=
- [lmi-commits] [lmi] master 2598df5 6/8: Dispense with boost/operators for one class, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 5d71aea 8/8: Remove obsolete references to boost, Greg Chicares, 2018/02/25
- [lmi-commits] [lmi] master 0819953 7/8: Dispense with boost/operators altogether, Greg Chicares, 2018/02/25