lmi-commits
[Top][All Lists]
Advanced

[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



reply via email to

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