mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added year_month_day and year_month_day_last classes and tests
This commit is contained in:
parent
e7cbc10df8
commit
5143aa7f53
@ -36,6 +36,7 @@ SOFTWARE.
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "integral_limits.h"
|
||||
#include "string_view.h"
|
||||
|
||||
#if ETL_NOT_USING_CPP11
|
||||
#error NOT SUPPORTED FOR C++03 OR BELOW
|
||||
@ -75,6 +76,7 @@ namespace etl
|
||||
#include "private/chrono/year_month_weekday.h"
|
||||
#include "private/chrono/hh_mm_ss.h"
|
||||
#include "private/chrono/operators.h"
|
||||
#include "private/chrono/time_zone.h"
|
||||
#endif
|
||||
|
||||
#undef ETL_IN_CHRONO_H
|
||||
|
||||
@ -245,7 +245,11 @@ namespace etl
|
||||
////***********************************************************************
|
||||
//ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT
|
||||
//{
|
||||
// return etl::chrono::local_days();
|
||||
//// Convert the year_month_day to sys_days first
|
||||
//etl::chrono::sys_days sys_days_representation = static_cast<etl::chrono::sys_days>(*this);
|
||||
|
||||
//// Convert sys_days to local_days (assuming local_days is a wrapper around sys_days)
|
||||
//return etl::chrono::local_days(sys_days_representation);
|
||||
//}
|
||||
|
||||
private:
|
||||
@ -270,7 +274,6 @@ namespace etl
|
||||
: y(y)
|
||||
, m(mdl.month())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -305,6 +308,16 @@ namespace etl
|
||||
return etl::chrono::month_day_last(m);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
///
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return y.ok() &&
|
||||
m.ok() &&
|
||||
day() == etl::chrono::month_day_last(m).day();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
///
|
||||
//*************************************************************************
|
||||
|
||||
@ -194,27 +194,27 @@ namespace
|
||||
CHECK_EQUAL(etl::chrono::year(2000), ymdl1.year());
|
||||
CHECK_EQUAL(etl::chrono::January, ymdl1.month());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).day(), ymdl1.day());
|
||||
CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::January) == ymdl1.month_day_last());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).month(), ymdl1.month_day_last().month());
|
||||
|
||||
CHECK_EQUAL(etl::chrono::year(2001), ymdl2.year());
|
||||
CHECK_EQUAL(etl::chrono::February, ymdl2.month());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).day(), ymdl2.day());
|
||||
CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::February) == ymdl2.month_day_last());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).month(), ymdl2.month_day_last().month());
|
||||
|
||||
CHECK_EQUAL(etl::chrono::year(2002), ymdl3.year());
|
||||
CHECK_EQUAL(etl::chrono::March, ymdl3.month());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).day(), ymdl3.day());
|
||||
CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::March) == ymdl3.month_day_last());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).month(), ymdl3.month_day_last().month());
|
||||
|
||||
CHECK_EQUAL(etl::chrono::year(2003), ymdl4.year());
|
||||
CHECK_EQUAL(etl::chrono::April, ymdl4.month());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).day(), ymdl4.day());
|
||||
CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::April) == ymdl4.month_day_last());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).month(), ymdl4.month_day_last().month());
|
||||
|
||||
CHECK_EQUAL(etl::chrono::year(2004), ymdl5.year());
|
||||
CHECK_EQUAL(etl::chrono::May, ymdl5.month());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).day(), ymdl5.day());
|
||||
CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::May) == ymdl5.month_day_last());
|
||||
CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).month(), ymdl5.month_day_last().month());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -94,12 +94,14 @@ namespace
|
||||
TEST(test_year_month_spaceship_operator)
|
||||
{
|
||||
Chrono::year_month ym1{Chrono::year(2000), Chrono::January};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::February};
|
||||
Chrono::year_month ym3{Chrono::year(2000), Chrono::January};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::January};
|
||||
Chrono::year_month ym3{Chrono::year(2000), Chrono::February};
|
||||
|
||||
CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::equal);
|
||||
CHECK_TRUE((ym1 <=> ym1) == std::strong_ordering::equal);
|
||||
CHECK_TRUE((ym1 <=> ym2) == std::strong_ordering::less);
|
||||
CHECK_TRUE((ym2 <=> ym1) == std::strong_ordering::greater);
|
||||
CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::less);
|
||||
CHECK_TRUE((ym3 <=> ym1) == std::strong_ordering::greater);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -108,12 +110,14 @@ namespace
|
||||
TEST(test_year_month_compare)
|
||||
{
|
||||
Chrono::year_month ym1{Chrono::year(2000), Chrono::January};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::February};
|
||||
Chrono::year_month ym3{Chrono::year(2000), Chrono::January};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::January};
|
||||
Chrono::year_month ym3{Chrono::year(2000), Chrono::February};
|
||||
|
||||
CHECK_TRUE(ym1.compare(ym3) == 0);
|
||||
CHECK_TRUE(ym1.compare(ym1) == 0);
|
||||
CHECK_TRUE(ym1.compare(ym2) == -1);
|
||||
CHECK_TRUE(ym2.compare(ym1) == 1);
|
||||
CHECK_TRUE(ym1.compare(ym3) == -1);
|
||||
CHECK_TRUE(ym3.compare(ym1) == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -121,24 +125,24 @@ namespace
|
||||
TEST(test_year_month_equality_operator)
|
||||
{
|
||||
Chrono::year_month ym1{Chrono::year(2000), Chrono::January};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::February};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::January};
|
||||
Chrono::year_month ym3{Chrono::year(2000), Chrono::February};
|
||||
|
||||
CHECK_TRUE(ym1 == ym1); // 2000/January
|
||||
CHECK_FALSE(ym1 == ym2); // 2000/January != 2001/February
|
||||
CHECK_FALSE(ym1 == ym3); // 2000/January != 2000/February
|
||||
CHECK_TRUE(ym1 == ym1); // Same year/month/day
|
||||
CHECK_FALSE(ym1 == ym2); // Different year
|
||||
CHECK_FALSE(ym1 == ym3); // Different month
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_not_equality_operator)
|
||||
{
|
||||
Chrono::year_month ym1{Chrono::year(2000), Chrono::January};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::February};
|
||||
Chrono::year_month ym2{Chrono::year(2001), Chrono::January};
|
||||
Chrono::year_month ym3{Chrono::year(2000), Chrono::February};
|
||||
|
||||
CHECK_FALSE(ym1 != ym1); // 2000/January
|
||||
CHECK_TRUE(ym1 != ym2); // 2000/January != 2001/February
|
||||
CHECK_TRUE(ym1 != ym3); // 2000/January != 2000/February
|
||||
CHECK_FALSE(ym1 != ym1); // Same year/month/day
|
||||
CHECK_TRUE(ym1 != ym2); // Different year
|
||||
CHECK_TRUE(ym1 != ym3); // Different month
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
167
test/test_chrono_year_month_day.cpp
Normal file
167
test/test_chrono_year_month_day.cpp
Normal file
@ -0,0 +1,167 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Documentation:
|
||||
|
||||
Copyright(c) 2025 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/platform.h"
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/chrono.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
// Set to 0 to reference against std::chrono
|
||||
#define ETL_USING_ETL_CHRONO 1
|
||||
|
||||
#if ETL_USING_ETL_CHRONO
|
||||
#define Chrono etl::chrono
|
||||
#else
|
||||
#if ETL_USING_CPP20
|
||||
#include <chrono>
|
||||
#define Chrono std::chrono
|
||||
#else
|
||||
#error std::chrono not supported
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_chrono_year_month_day)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_constructor)
|
||||
{
|
||||
Chrono::year_month_day ymd;
|
||||
|
||||
CHECK_FALSE(ymd.ok()); // Default-constructed year_month_day is not valid
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_with_month_and_day)
|
||||
{
|
||||
Chrono::year_month_day ymd{Chrono::year(2000), Chrono::January, Chrono::day(1)};
|
||||
|
||||
CHECK_TRUE(ymd.ok()); // Valid year_month_day
|
||||
CHECK_EQUAL(2000, (int)ymd.year());
|
||||
CHECK_EQUAL((unsigned)Chrono::January, (unsigned)ymd.month());
|
||||
CHECK_EQUAL(Chrono::day(1), ymd.day());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_invalid_year_month)
|
||||
{
|
||||
Chrono::year_month_day ymd{Chrono::year{32768}, Chrono::January, Chrono::day(1)}; // Invalid year
|
||||
|
||||
CHECK_FALSE(ymd.ok()); // Invalid year_month_day
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_invalid_month_in_year_month)
|
||||
{
|
||||
Chrono::year_month_day ymd{Chrono::year{2000}, Chrono::month{13}, Chrono::day(1)}; // Invalid month (13)
|
||||
|
||||
CHECK_FALSE(ymd.ok()); // Invalid year_month_day
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_invalid_day_in_year_month)
|
||||
{
|
||||
Chrono::year_month_day ymd{Chrono::year{2000}, Chrono::January, Chrono::day(32)}; // Invalid day (32)
|
||||
|
||||
CHECK_FALSE(ymd.ok()); // Invalid year_month_day
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP20
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_day_spaceship_operator)
|
||||
{
|
||||
Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)};
|
||||
Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)};
|
||||
|
||||
CHECK_TRUE((ym1 <=> ym1) == std::strong_ordering::equal);
|
||||
CHECK_TRUE((ym1 <=> ym2) == std::strong_ordering::less);
|
||||
CHECK_TRUE((ym2 <=> ym1) == std::strong_ordering::greater);
|
||||
CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::less);
|
||||
CHECK_TRUE((ym3 <=> ym1) == std::strong_ordering::greater);
|
||||
CHECK_TRUE((ym1 <=> ym4) == std::strong_ordering::less);
|
||||
CHECK_TRUE((ym4 <=> ym1) == std::strong_ordering::greater);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_ETL_CHRONO
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_day_compare)
|
||||
{
|
||||
Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)};
|
||||
Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)};
|
||||
|
||||
CHECK_TRUE(ym1.compare(ym1) == 0);
|
||||
CHECK_TRUE(ym1.compare(ym2) == -1);
|
||||
CHECK_TRUE(ym2.compare(ym1) == 1);
|
||||
CHECK_TRUE(ym1.compare(ym3) == -1);
|
||||
CHECK_TRUE(ym3.compare(ym1) == 1);
|
||||
CHECK_TRUE(ym1.compare(ym4) == -1);
|
||||
CHECK_TRUE(ym4.compare(ym1) == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_day_equality_operator)
|
||||
{
|
||||
Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)};
|
||||
Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)};
|
||||
|
||||
CHECK_TRUE(ym1 == ym1); // Same year/month/day
|
||||
CHECK_FALSE(ym1 == ym2); // Different year
|
||||
CHECK_FALSE(ym1 == ym3); // Different month
|
||||
CHECK_FALSE(ym1 == ym4); // Different day
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_day_not_equality_operator)
|
||||
{
|
||||
Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)};
|
||||
Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)};
|
||||
Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)};
|
||||
|
||||
CHECK_FALSE(ym1 != ym1); // Same year/month/day
|
||||
CHECK_TRUE(ym1 != ym2); // Different year
|
||||
CHECK_TRUE(ym1 != ym3); // Different month
|
||||
CHECK_TRUE(ym1 != ym4); // Different day
|
||||
}
|
||||
};
|
||||
}
|
||||
145
test/test_chrono_year_month_day_last.cpp
Normal file
145
test/test_chrono_year_month_day_last.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Documentation:
|
||||
|
||||
Copyright(c) 2025 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "etl/platform.h"
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/chrono.h"
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
// Set to 0 to reference against std::chrono
|
||||
#define ETL_USING_ETL_CHRONO 1
|
||||
|
||||
#if ETL_USING_ETL_CHRONO
|
||||
#define Chrono etl::chrono
|
||||
#else
|
||||
#if ETL_USING_CPP20
|
||||
#include <chrono>
|
||||
#define Chrono std::chrono
|
||||
#else
|
||||
#error std::chrono not supported
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_chrono_year_month_day_last)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_in_range)
|
||||
{
|
||||
Chrono::year_month_day_last year_month_day_last_2000_january(Chrono::year(2000), Chrono::month_day_last(Chrono::January));
|
||||
Chrono::year_month_day_last year_month_day_last_2001_february(Chrono::year(2001), Chrono::month_day_last(Chrono::February));
|
||||
Chrono::year_month_day_last year_month_day_last_2002_march(Chrono::year(2002), Chrono::month_day_last(Chrono::March));
|
||||
Chrono::year_month_day_last year_month_day_last_2003_april(Chrono::year(2003), Chrono::month_day_last(Chrono::April));
|
||||
Chrono::year_month_day_last year_month_day_last_2004_may(Chrono::year(2004), Chrono::month_day_last(Chrono::May));
|
||||
Chrono::year_month_day_last year_month_day_last_2005_june(Chrono::year(2005), Chrono::month_day_last(Chrono::June));
|
||||
Chrono::year_month_day_last year_month_day_last_2006_july(Chrono::year(2006), Chrono::month_day_last(Chrono::July));
|
||||
Chrono::year_month_day_last year_month_day_last_2007_august(Chrono::year(2007), Chrono::month_day_last(Chrono::August));
|
||||
Chrono::year_month_day_last year_month_day_last_2008_september(Chrono::year(2008), Chrono::month_day_last(Chrono::September));
|
||||
Chrono::year_month_day_last year_month_day_last_2009_october(Chrono::year(2009), Chrono::month_day_last(Chrono::October));
|
||||
Chrono::year_month_day_last year_month_day_last_2010_november(Chrono::year(2010), Chrono::month_day_last(Chrono::November));
|
||||
Chrono::year_month_day_last year_month_day_last_2011_december(Chrono::year(2011), Chrono::month_day_last(Chrono::December));
|
||||
|
||||
CHECK_TRUE(year_month_day_last_2000_january.ok());
|
||||
CHECK_TRUE(year_month_day_last_2001_february.ok());
|
||||
CHECK_TRUE(year_month_day_last_2002_march.ok());
|
||||
CHECK_TRUE(year_month_day_last_2003_april.ok());
|
||||
CHECK_TRUE(year_month_day_last_2004_may.ok());
|
||||
CHECK_TRUE(year_month_day_last_2005_june.ok());
|
||||
CHECK_TRUE(year_month_day_last_2006_july.ok());
|
||||
CHECK_TRUE(year_month_day_last_2007_august.ok());
|
||||
CHECK_TRUE(year_month_day_last_2008_september.ok());
|
||||
CHECK_TRUE(year_month_day_last_2009_october.ok());
|
||||
CHECK_TRUE(year_month_day_last_2010_november.ok());
|
||||
CHECK_TRUE(year_month_day_last_2011_december.ok());
|
||||
|
||||
CHECK_EQUAL(31, year_month_day_last_2000_january.day());
|
||||
CHECK_EQUAL(29, year_month_day_last_2001_february.day());
|
||||
CHECK_EQUAL(31, year_month_day_last_2002_march.day());
|
||||
CHECK_EQUAL(30, year_month_day_last_2003_april.day());
|
||||
CHECK_EQUAL(31, year_month_day_last_2004_may.day());
|
||||
CHECK_EQUAL(30, year_month_day_last_2005_june.day());
|
||||
CHECK_EQUAL(31, year_month_day_last_2006_july.day());
|
||||
CHECK_EQUAL(31, year_month_day_last_2007_august.day());
|
||||
CHECK_EQUAL(30, year_month_day_last_2008_september.day());
|
||||
CHECK_EQUAL(31, year_month_day_last_2009_october.day());
|
||||
CHECK_EQUAL(30, year_month_day_last_2010_november.day());
|
||||
CHECK_EQUAL(31, year_month_day_last_2011_december.day());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_day_last_comparison_operators)
|
||||
{
|
||||
Chrono::year_month_day_last year_month_day_last1(Chrono::year(2000), Chrono::month_day_last(Chrono::January));
|
||||
Chrono::year_month_day_last year_month_day_last2(Chrono::year(2001), Chrono::month_day_last(Chrono::January));
|
||||
Chrono::year_month_day_last year_month_day_last3(Chrono::year(2000), Chrono::month_day_last(Chrono::February));
|
||||
|
||||
CHECK_TRUE(year_month_day_last1 == year_month_day_last1);
|
||||
CHECK_FALSE(year_month_day_last1 == year_month_day_last2);
|
||||
CHECK_FALSE(year_month_day_last1 == year_month_day_last3);
|
||||
|
||||
CHECK_FALSE(year_month_day_last1 != year_month_day_last1);
|
||||
CHECK_TRUE(year_month_day_last1 != year_month_day_last2);
|
||||
CHECK_TRUE(year_month_day_last1 != year_month_day_last3);
|
||||
}
|
||||
|
||||
#if ETL_USING_ETL_CHRONO
|
||||
//*************************************************************************
|
||||
TEST(test_year_month_day_last_hashes_are_unique)
|
||||
{
|
||||
std::vector<size_t> hashes;
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2000), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2001), Chrono::month_day_last(Chrono::February))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2002), Chrono::month_day_last(Chrono::March))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2003), Chrono::month_day_last(Chrono::April))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2004), Chrono::month_day_last(Chrono::May))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2005), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2006), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2007), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2008), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2009), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2010), Chrono::month_day_last(Chrono::January))));
|
||||
hashes.push_back(etl::hash<Chrono::year_month_day_last>()(Chrono::year_month_day_last(Chrono::year(2011), Chrono::month_day_last(Chrono::January))));
|
||||
}
|
||||
|
||||
std::sort(hashes.begin(), hashes.end());
|
||||
(void)std::unique(hashes.begin(), hashes.end());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
@ -3197,6 +3197,7 @@
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\operators.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\system_clock.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\time_point.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\time_zone.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\weekday.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\year.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\year_month.h" />
|
||||
@ -8482,6 +8483,8 @@
|
||||
<ClCompile Include="..\test_chrono_weekday_last.cpp" />
|
||||
<ClCompile Include="..\test_chrono_year.cpp" />
|
||||
<ClCompile Include="..\test_chrono_year_month.cpp" />
|
||||
<ClCompile Include="..\test_chrono_year_month_day.cpp" />
|
||||
<ClCompile Include="..\test_chrono_year_month_day_last.cpp" />
|
||||
<ClCompile Include="..\test_circular_buffer.cpp" />
|
||||
<ClCompile Include="..\test_circular_buffer_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_circular_iterator.cpp" />
|
||||
|
||||
@ -1509,6 +1509,9 @@
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\year_month_weekday.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\time_zone.h">
|
||||
<Filter>ETL\Private\chrono</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
@ -3566,6 +3569,12 @@
|
||||
<ClCompile Include="..\test_chrono_operators.cpp">
|
||||
<Filter>Tests\Chrono</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_chrono_year_month_day.cpp">
|
||||
<Filter>Tests\Chrono</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_chrono_year_month_day_last.cpp">
|
||||
<Filter>Tests\Chrono</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user