mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Work in progress
This commit is contained in:
parent
9705ee233b
commit
8c78fdab04
39
include/etl/chrono.h
Normal file
39
include/etl/chrono.h
Normal file
@ -0,0 +1,39 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2023 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.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_INCLUDED
|
||||
#define ETL_CHRONO_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "private/chrono/duration.h"
|
||||
#include "private/chrono/day.h"
|
||||
|
||||
#endif
|
||||
@ -156,8 +156,8 @@ namespace etl
|
||||
/// Specialisation for signed char.
|
||||
///\ingroup hash
|
||||
//***************************************************************************
|
||||
template<> struct
|
||||
hash<signed char>
|
||||
template <>
|
||||
struct hash<signed char>
|
||||
{
|
||||
ETL_STATIC_ASSERT(sizeof(size_t) >= sizeof(signed char), "size_t smaller than type");
|
||||
|
||||
|
||||
271
include/etl/private/chrono/day.h
Normal file
271
include/etl/private/chrono/day.h
Normal file
@ -0,0 +1,271 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2023 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.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_DAY_INCLUDED
|
||||
#define ETL_CHRONO_DAY_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../hash.h"
|
||||
|
||||
#include "duration.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
//***********************************************************************
|
||||
/// day
|
||||
//***********************************************************************
|
||||
class day
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR day()
|
||||
: value(0)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR day(unsigned value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR day(const etl::chrono::day& other)
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs)
|
||||
{
|
||||
value = rhs.value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
template <typename TToDuration, typename TValue2, typename TPeriod2>
|
||||
ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration<TValue2, TPeriod2>& rhs)
|
||||
{
|
||||
value = etl::chrono::duration_cast<TToDuration, TValue2, TPeriod2>(rhs);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day& operator ++() ETL_NOEXCEPT
|
||||
{
|
||||
++value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::day operator ++(int) ETL_NOEXCEPT
|
||||
{
|
||||
const etl::chrono::day temp = *this;
|
||||
++value;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day& operator --() ETL_NOEXCEPT
|
||||
{
|
||||
--value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR14 etl::chrono::day operator --(int) ETL_NOEXCEPT
|
||||
{
|
||||
const etl::chrono::day temp = *this;
|
||||
--value;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
value += static_cast<unsigned char>(ds.count());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
value -= static_cast<unsigned char>(ds.count());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT
|
||||
{
|
||||
return (value >= 1U) && (value <= 31U);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR operator unsigned() const ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<unsigned>(value);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
unsigned char value;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result += ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result += ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
|
||||
{
|
||||
etl::chrono::day result(d);
|
||||
|
||||
result -= ds;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::days(static_cast<int>(static_cast<unsigned>(d1)) -
|
||||
static_cast<int>(static_cast<unsigned>(d2)));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) == static_cast<unsigned>(d2));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return !(d1 == d2);
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) < static_cast<unsigned>(d2));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) <= static_cast<unsigned>(d2));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) > static_cast<unsigned>(d2));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
|
||||
{
|
||||
return (static_cast<unsigned>(d1) >= static_cast<unsigned>(d2));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
#if ETL_USING_CPP20
|
||||
ETL_CONSTEXPR auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2)
|
||||
{
|
||||
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <>
|
||||
struct hash<etl::chrono::day>
|
||||
{
|
||||
size_t operator()(const etl::chrono::day& d) const
|
||||
{
|
||||
unsigned value = d;
|
||||
const uint8_t* p = reinterpret_cast<const uint8_t*>(&value);
|
||||
|
||||
return etl::private_hash::generic_hash<size_t>(p, p + sizeof(unsigned));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
namespace etl
|
||||
{
|
||||
namespace literals
|
||||
{
|
||||
namespace chrono_literals
|
||||
{
|
||||
//***********************************************************************
|
||||
/// Literal for days
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::day(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
139
include/etl/private/chrono/duration.h
Normal file
139
include/etl/private/chrono/duration.h
Normal file
@ -0,0 +1,139 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2023 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.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_CHRONO_DURATION_INCLUDED
|
||||
#define ETL_CHRONO_DURATION_INCLUDED
|
||||
|
||||
#include "../../platform.h"
|
||||
#include "../../ratio.h"
|
||||
#include "../../static_assert.h"
|
||||
#include "../../limits.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace chrono
|
||||
{
|
||||
//***********************************************************************
|
||||
/// duration
|
||||
//***********************************************************************
|
||||
template <typename TValue, typename TPeriod = etl::ratio<1> >
|
||||
class duration
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR duration() ETL_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_CONSTEXPR duration(const etl::chrono::duration<TValue, TPeriod>& other) ETL_NOEXCEPT
|
||||
: value(other.value)
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
template< typename TValue2 >
|
||||
ETL_CONSTEXPR explicit duration(const TValue2& value_) ETL_NOEXCEPT
|
||||
: value(static_cast<TValue>(value_))
|
||||
{
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
template< typename TValue2, typename TPeriod2 >
|
||||
ETL_CONSTEXPR duration(const etl::chrono::duration<TValue2, TPeriod2>& other) ETL_NOEXCEPT
|
||||
: value(static_cast<TValue>(other.value))
|
||||
{
|
||||
ETL_STATIC_ASSERT(!(etl::is_integral<TValue>::value && etl::is_floating_point<TValue2>::value), "Cannot convert duration from floating point to integral");
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::duration{ 0, TPeriod()};
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration<TValue, TPeriod> min() ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::duration<TValue, TPeriod> { etl::numeric_limits<TValue>::min() };
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration<TValue, TPeriod> max() ETL_NOEXCEPT
|
||||
{
|
||||
return etl::chrono::duration<TValue, TPeriod>{ etl::numeric_limits<TValue>::max() };
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD ETL_CONSTEXPR TValue count() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
TValue value;
|
||||
//TPeriod period;
|
||||
};
|
||||
|
||||
//***********************************************************************
|
||||
/// Duration types
|
||||
//***********************************************************************
|
||||
#if (ETL_USING_64BIT_TYPES)
|
||||
typedef etl::chrono::duration<int64_t, etl::nano> nanoseconds;
|
||||
typedef etl::chrono::duration<int64_t, etl::micro> microseconds;
|
||||
typedef etl::chrono::duration<int64_t, etl::milli> milliseconds;
|
||||
typedef etl::chrono::duration<int64_t, etl::ratio<1U> > seconds;
|
||||
#else
|
||||
typedef etl::chrono::duration<int32_t, etl::nano> nanoseconds;
|
||||
typedef etl::chrono::duration<int32_t, etl::micro> microseconds;
|
||||
typedef etl::chrono::duration<int32_t, etl::milli> milliseconds;
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<1U> > seconds;
|
||||
#endif
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<60U> > minutes;
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<3600U> > hours;
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<86400U> > days;
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<604800U> > weeks;
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<2629746U> > months;
|
||||
typedef etl::chrono::duration<int32_t, etl::ratio<31556952U> > years;
|
||||
|
||||
//***********************************************************************
|
||||
/// duration_cast
|
||||
//***********************************************************************
|
||||
template <typename TToDuration, typename TValue, typename TPeriod>
|
||||
ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration<TValue, TPeriod>& d)
|
||||
{
|
||||
return TToDuration();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -45,6 +45,9 @@ add_executable(etl_tests
|
||||
test_callback_timer_locked.cpp
|
||||
test_char_traits.cpp
|
||||
test_checksum.cpp
|
||||
|
||||
test_chrono_day.cpp
|
||||
|
||||
test_circular_buffer.cpp
|
||||
test_circular_buffer_external_buffer.cpp
|
||||
test_circular_iterator.cpp
|
||||
|
||||
305
test/test_chrono_day.cpp
Normal file
305
test/test_chrono_day.cpp
Normal file
@ -0,0 +1,305 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Documentation:
|
||||
|
||||
Copyright(c) 2023 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"
|
||||
|
||||
#if ETL_USING_CPP20
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/chrono.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(test_chrono_day)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_constructor)
|
||||
{
|
||||
std::chrono::day std_day;
|
||||
etl::chrono::day day;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_constructor_in_range)
|
||||
{
|
||||
for (unsigned i = 0U; i < 256; ++i)
|
||||
{
|
||||
std::chrono::day std_day(i);
|
||||
etl::chrono::day day(i);
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pre_increment)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
{
|
||||
++std_day;
|
||||
++day;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_post_increment)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
{
|
||||
std::chrono::day std_last_day = std_day++;
|
||||
etl::chrono::day last_day = day++;
|
||||
|
||||
CHECK_EQUAL(std_last_day.ok(), last_day.ok());
|
||||
CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day));
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pre_decrement)
|
||||
{
|
||||
std::chrono::day std_day(256);
|
||||
etl::chrono::day day(256);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
{
|
||||
--std_day;
|
||||
--day;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_post_decrement)
|
||||
{
|
||||
std::chrono::day std_day(256);
|
||||
etl::chrono::day day(256);
|
||||
|
||||
for (int i = 0; i < 255; ++i)
|
||||
{
|
||||
std::chrono::day std_last_day = std_day--;
|
||||
etl::chrono::day last_day = day--;
|
||||
|
||||
CHECK_EQUAL(std_last_day.ok(), last_day.ok());
|
||||
CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day));
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_plus_equal_days)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
std_day += std_days;
|
||||
day += days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_plus_days)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
std_day = std_day + std_days;
|
||||
day = day + days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_days_plus_day)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
std_day = std_days + std_day;
|
||||
day = days + day;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_minus_equal_days)
|
||||
{
|
||||
std::chrono::day std_day(256);
|
||||
etl::chrono::day day(256);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
std_day -= std_days;
|
||||
day -= days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_minus_days)
|
||||
{
|
||||
std::chrono::day std_day(0);
|
||||
etl::chrono::day day(0);
|
||||
|
||||
std::chrono::days std_days(2);
|
||||
etl::chrono::days days(2);
|
||||
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
std_day = std_day - std_days;
|
||||
day = day - days;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_minus_day)
|
||||
{
|
||||
for (int i = 1; i < 31; ++i)
|
||||
{
|
||||
std::chrono::day std_day1(i);
|
||||
std::chrono::day std_day2(31 - i);
|
||||
|
||||
etl::chrono::day day1(i);
|
||||
etl::chrono::day day2(31 - i);
|
||||
|
||||
std::chrono::days std_days = std_day1 - std_day2;
|
||||
etl::chrono::days days = day1 - day2;
|
||||
|
||||
CHECK_EQUAL(std_days.count(), days.count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_literal_days)
|
||||
{
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace etl::literals::chrono_literals;
|
||||
|
||||
std::chrono::day std_day = 25d;
|
||||
etl::chrono::day day = 25_d;
|
||||
|
||||
CHECK_EQUAL(std_day.ok(), day.ok());
|
||||
CHECK_EQUAL(unsigned(std_day), unsigned(day));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_comparison_operators)
|
||||
{
|
||||
etl::chrono::day day10(10);
|
||||
etl::chrono::day day20(20);
|
||||
|
||||
CHECK_TRUE(day10 == day10);
|
||||
CHECK_FALSE(day10 != day10);
|
||||
CHECK_TRUE(day10 < day20);
|
||||
CHECK_FALSE(day10 < day10);
|
||||
CHECK_FALSE(day20 < day10);
|
||||
CHECK_TRUE(day10 <= day20);
|
||||
CHECK_TRUE(day10 <= day10);
|
||||
CHECK_FALSE(day20 <= day10);
|
||||
CHECK_FALSE(day10 > day20);
|
||||
CHECK_FALSE(day10 > day10);
|
||||
CHECK_TRUE(day20 > day10);
|
||||
CHECK_FALSE(day10 >= day20);
|
||||
CHECK_TRUE(day10 >= day10);
|
||||
CHECK_TRUE(day20 >= day10);
|
||||
|
||||
#if ETL_USING_CPP20
|
||||
CHECK_TRUE((day10 <=> day10) == 0);
|
||||
CHECK_TRUE((day10 <=> day20) < 0);
|
||||
CHECK_TRUE((day20 <=> day10) > 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_day_hash)
|
||||
{
|
||||
etl::chrono::day day(10);
|
||||
|
||||
size_t h = 0;
|
||||
|
||||
h = etl::hash<etl::chrono::day>()(day);
|
||||
|
||||
CHECK_TRUE(h != 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -2942,6 +2942,7 @@
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_atomic.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_interrupt.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_locked.h" />
|
||||
<ClInclude Include="..\..\include\etl\chrono.h" />
|
||||
<ClInclude Include="..\..\include\etl\circular_buffer.h" />
|
||||
<ClInclude Include="..\..\include\etl\circular_iterator.h" />
|
||||
<ClInclude Include="..\..\include\etl\combinations.h" />
|
||||
@ -3000,6 +3001,7 @@
|
||||
<ClInclude Include="..\..\include\etl\poly_span.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\bitset_legacy.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\bitset_new.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\day.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\diagnostic_array_bounds_push.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\diagnostic_deprecated_push.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\diagnostic_stringop_overread_push.h" />
|
||||
@ -14337,6 +14339,7 @@
|
||||
<ClCompile Include="..\test_callback_timer_interrupt.cpp" />
|
||||
<ClCompile Include="..\test_callback_timer_locked.cpp" />
|
||||
<ClCompile Include="..\test_char_traits.cpp" />
|
||||
<ClCompile Include="..\test_chrono_day.cpp" />
|
||||
<ClCompile Include="..\test_circular_buffer.cpp" />
|
||||
<ClCompile Include="..\test_circular_buffer_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_circular_iterator.cpp" />
|
||||
|
||||
@ -220,6 +220,12 @@
|
||||
<Filter Include="Tests\Messaging">
|
||||
<UniqueIdentifier>{c75cedd3-8b6c-4662-b965-aecbe7fd5d1c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="ETL\Private\chrono">
|
||||
<UniqueIdentifier>{46e23f29-ce01-418f-8331-9c739774414c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Tests\Chrono">
|
||||
<UniqueIdentifier>{1b1afa65-108a-4665-9e74-3c67a27ff917}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\etl\enum_type.h">
|
||||
@ -1362,6 +1368,12 @@
|
||||
<ClInclude Include="..\..\include\etl\stringify.h">
|
||||
<Filter>ETL\Utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\chrono.h">
|
||||
<Filter>ETL\Utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\chrono\day.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
@ -3425,6 +3437,9 @@
|
||||
<ClCompile Include="..\test_macros.cpp">
|
||||
<Filter>Tests\Misc</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_chrono_day.cpp">
|
||||
<Filter>Tests\Chrono</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user