1. dimajix
  2. Untitled project
  3. Magnum

Commits

Kaya Kupferschmidt  committed c1e70d6

Added test for leapyears

  • Participants
  • Parent commits 14499b9
  • Branches default

Comments (0)

Files changed (1)

File source/unittest/util/Test_Date.h

View file
 }
 
 
+void test_epoch()
+{
+    Date date(1972,6,30);
+    TEST_ASSERT( date.isValid() );
+    TEST_ASSERT( date.getYear() == 1972 );
+    TEST_ASSERT( date.getMonth() == 6 );
+    TEST_ASSERT( date.getDayOfMonth() == 30 );
+    TEST_ASSERT( date.getJulianDay() == 2441499 );
+
+    date.setJulianDay(2450083);
+    TEST_ASSERT( date.isValid() );
+    TEST_ASSERT( date.getYear() == 1995 );
+    TEST_ASSERT( date.getMonth() == 12 );
+    TEST_ASSERT( date.getDayOfMonth() == 31 );
+    TEST_ASSERT( date.getJulianDay() == 2450083 );
+}
+
+
 void test_arithmetic()
 {
     Date datetime(2000,1,1);
 }
 
 
-Test_Date() {
+void test_leapyears()
+{
+    Date date(1996,1,1);
+    TEST_ASSERT( date.getDaysInYear() == 366 );
+    TEST_ASSERT( date.getDaysInMonth() == 31 );
+    date.setMonth(Date::Feb);
+    TEST_ASSERT( date.getDaysInMonth() == 29 );
+
+    date.setDate(1997,1,1);
+    TEST_ASSERT( date.getDaysInYear() == 365 );
+    TEST_ASSERT( date.getDaysInMonth() == 31 );
+    date.setMonth(Date::Feb);
+    TEST_ASSERT( date.getDaysInMonth() == 28 );
+
+    date.setDate(2000,1,1);
+    TEST_ASSERT( date.getDaysInYear() == 366 );
+    TEST_ASSERT( date.getDaysInMonth() == 31 );
+    date.setMonth(Date::Feb);
+    TEST_ASSERT( date.getDaysInMonth() == 29 );
+
+    date.setDate(1900,1,1);
+    TEST_ASSERT( date.getDaysInYear() == 365 );
+    TEST_ASSERT( date.getDaysInMonth() == 31 );
+    date.setMonth(Date::Feb);
+    TEST_ASSERT( date.getDaysInMonth() == 28 );
+}
+
+
+Test_Date()
+{
     TEST_ADD(Test_Date::test_basics);
+    TEST_ADD(Test_Date::test_epoch);
     TEST_ADD(Test_Date::test_arithmetic);
     TEST_ADD(Test_Date::test_comparison);
+    TEST_ADD(Test_Date::test_leapyears);
 }
 
 };