#include #include #include #include "Date.hpp" // Function declaration int main(); // Function definition int main() { // Test construction and the component queries. Date date{ 2026, 10, 2 }; assert( date.year() == 2026 ); assert( date.month() == 10 ); assert( date.day() == 2 ); assert( date.to_string() == "2026-10-02" ); // Test an ordinary increment and decrement. ++date; assert( date.to_string() == "2026-10-03" ); --date; assert( date.to_string() == "2026-10-02" ); // Test the end and beginning of a 31-day month. Date january{ 2026, 1, 31 }; ++january; assert( january.to_string() == "2026-02-01" ); --january; assert( january.to_string() == "2026-01-31" ); // Test the end and beginning of a 30-day month. Date april{ 2026, 4, 30 }; ++april; assert( april.to_string() == "2026-05-01" ); --april; assert( april.to_string() == "2026-04-30" ); // Test crossing a year boundary. Date new_year{ 2026, 12, 31 }; ++new_year; assert( new_year.to_string() == "2027-01-01" ); --new_year; assert( new_year.to_string() == "2026-12-31" ); // Test February during an ordinary Gregorian year. Date ordinary_year{ 2026, 2, 28 }; ++ordinary_year; assert( ordinary_year.to_string() == "2026-03-01" ); --ordinary_year; assert( ordinary_year.to_string() == "2026-02-28" ); // Test February during a Gregorian leap year. Date leap_year{ 2024, 2, 28 }; ++leap_year; assert( leap_year.to_string() == "2024-02-29" ); ++leap_year; assert( leap_year.to_string() == "2024-03-01" ); --leap_year; assert( leap_year.to_string() == "2024-02-29" ); --leap_year; assert( leap_year.to_string() == "2024-02-28" ); // A Gregorian century year is not a leap year unless // it is divisible by 400. Date year_1900{ 1900, 2, 28 }; ++year_1900; assert( year_1900.to_string() == "1900-03-01" ); Date year_2000{ 2000, 2, 28 }; ++year_2000; assert( year_2000.to_string() == "2000-02-29" ); ++year_2000; assert( year_2000.to_string() == "2000-03-01" ); // Before the Gregorian transition, the Julian leap-year // rule applies. Every year divisible by 4 is a leap year. Date year_1500{ 1500, 2, 28 }; ++year_1500; assert( year_1500.to_string() == "1500-02-29" ); ++year_1500; assert( year_1500.to_string() == "1500-03-01" ); // Test the Julian-to-Gregorian transition. Date transition{ 1582, 10, 4 }; ++transition; assert( transition.to_string() == "1582-10-15" ); --transition; assert( transition.to_string() == "1582-10-04" ); // Test prefix increment and decrement return values. Date prefix{ 2026, 6, 15 }; Date &incremented{ ++prefix }; assert( prefix.to_string() == "2026-06-16" ); assert( &incremented == &prefix ); Date &decremented{ --prefix }; assert( prefix.to_string() == "2026-06-15" ); assert( &decremented == &prefix ); // Test postfix increment and decrement return values. Date postfix{ 2026, 6, 15 }; Date old_increment{ postfix++ }; assert( old_increment.to_string() == "2026-06-15" ); assert( postfix.to_string() == "2026-06-16" ); Date old_decrement{ postfix-- }; assert( old_decrement.to_string() == "2026-06-16" ); assert( postfix.to_string() == "2026-06-15" ); // January 1, 1 is the earliest supported date. Date first_date{ 1, 1, 1 }; assert( first_date.to_string() == "1-01-01" ); ++first_date; assert( first_date.to_string() == "1-01-02" ); --first_date; assert( first_date.to_string() == "1-01-01" ); // Decrementing January 1, 1 violates a precondition. // Uncomment the following statement to verify that the // assertion in operator--() fails. // // --first_date; std::cout << "All tests passed." << std::endl; return 0; }