etl/test/test_cyclic_value.cpp
John Wellbelove a2da3ed940
Optimise cyclic value (#1607)
* Updated ignore for hard link for CLion

* Initial working version

* Optimised advance template call

* Further optimsed advance

Updated docs and tests

* Moved comparison operators out of the class.

* Implement spaceship operator <=> for No-STL case (#1604)

This was disabled explicitly in recent commit
232c948674cff1b4b72c2d6b3acfa7342d096dd1 to prevent using
the <compare> header from STL.

Now, re-enabling by implementing an ETL version of it in compare.h

* Sponsorship message updates

* Fix duplicated check runs

* Refactored the advance function to fix issues with signed unsigned mod operations.

* clang-format

* Updated documentation for cyclic_value

* Modified code comments

* Fixed a logic issue in advance() where a less than maximum step from the minimum value for a cyclic value covering the full type's range would take the wrong logical path (Step would roll over), although calculating the correct result.

This could be cofusing to someone debugging cyclc_value.

* Added runtime ans static asserts for reverse ordered limts.

* clang-format

* Spelling fix 'fast' -> 'last'

* Code review updates

* clang-format

* Code review updates

* Code review updates

---------

Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
2026-10-09 17:39:04 +01:00

1034 lines
29 KiB
C++

///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2014 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 "unit_test_framework.h"
#include "etl/cyclic_value.h"
namespace
{
SUITE(test_cyclic_value)
{
//*************************************************************************
TEST(test_compile_time_initialisation)
{
etl::cyclic_value<int, 2, 7> value;
CHECK_EQUAL(2, value);
CHECK_EQUAL(2, value.first());
CHECK_EQUAL(7, value.last());
}
//*************************************************************************
TEST(test_run_time_initialisation)
{
etl::cyclic_value<int> value(2, 7);
CHECK_EQUAL(2, value);
CHECK_EQUAL(2, value.first());
CHECK_EQUAL(7, value.last());
}
//*************************************************************************
TEST(test_reversed_run_time_initialisation)
{
etl::cyclic_value<int> value(1, 2);
CHECK_THROW(etl::cyclic_value<int>(7, 2), etl::cyclic_value_reversed_limits);
CHECK_THROW(value.set(7, 2), etl::cyclic_value_reversed_limits);
}
//*************************************************************************
TEST(test_copy_constructor_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
etl::cyclic_value<int, 2, 7> value2(value);
CHECK(value == value2);
}
//*************************************************************************
TEST(test_copy_constructor_run_time)
{
etl::cyclic_value<int> value(2, 7);
etl::cyclic_value<int> value2(value);
CHECK(value == value2);
}
//*************************************************************************
TEST(test_set_compile_time)
{
using CV = etl::cyclic_value<int, 2, 7>;
CV value;
CHECK_EQUAL(2, value.first());
CHECK_EQUAL(7, value.last());
CHECK_EQUAL(2, CV::first());
CHECK_EQUAL(7, CV::last());
value.set(5);
CHECK_EQUAL(5, value.get());
value.set(1);
CHECK_EQUAL(value.first(), value.get());
value.set(8);
CHECK_EQUAL(value.last(), value.get());
}
//*************************************************************************
TEST(test_set_compile_time_initial_value_in_range)
{
etl::cyclic_value<int, 2, 7> value(5);
CHECK_EQUAL(5, value.get());
}
//*************************************************************************
TEST(test_set_compile_time_initial_value_out_of_range)
{
etl::cyclic_value<int, 2, 7> value1(1);
etl::cyclic_value<int, 2, 7> value2(8);
CHECK_EQUAL(2, value1.get());
CHECK_EQUAL(7, value2.get());
}
//*************************************************************************
TEST(test_set_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
CHECK_EQUAL(2, value.get());
CHECK_EQUAL(2, value.first());
CHECK_EQUAL(7, value.last());
value.set(5);
CHECK_EQUAL(5, value.get());
value.set(1);
CHECK_EQUAL(value.first(), value.get());
value.set(8);
CHECK_EQUAL(value.last(), value.get());
}
//*************************************************************************
TEST(test_set_run_time_initial_value_in_range)
{
etl::cyclic_value<int> value(2, 7, 5);
CHECK_EQUAL(5, value.get());
}
//*************************************************************************
TEST(test_set_run_time_initial_value_out_of_range)
{
etl::cyclic_value<int> value1(2, 7, 1);
etl::cyclic_value<int> value2(2, 7, 8);
CHECK_EQUAL(2, value1.get());
CHECK_EQUAL(7, value2.get());
}
//*************************************************************************
TEST(test_to_first_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
++value;
value.to_first();
CHECK_EQUAL(value.first(), value);
}
//*************************************************************************
TEST(test_to_first_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
++value;
value.to_first();
CHECK_EQUAL(value.first(), value);
}
//*************************************************************************
TEST(test_to_last_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.to_last();
CHECK_EQUAL(value.last(), value);
}
//*************************************************************************
TEST(test_to_last_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
CHECK_EQUAL(value.last(), value);
}
//*************************************************************************
TEST(test_increment_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
for (int i = value.first(); i <= value.last(); ++i)
{
CHECK_EQUAL(i, value);
++value;
}
}
//*************************************************************************
TEST(test_increment_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
for (int i = value.first(); i <= value.last(); ++i)
{
CHECK_EQUAL(i, value);
++value;
}
}
//*************************************************************************
TEST(test_decrement_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.to_last();
for (int i = value.last(); i >= value.first(); --i)
{
CHECK_EQUAL(i, value);
--value;
}
}
//*************************************************************************
TEST(test_decrement_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
for (int i = value.last(); i >= value.first(); --i)
{
CHECK_EQUAL(i, value);
--value;
}
}
//*************************************************************************
TEST(test_increment_wrap_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
int expected[8] = {2, 3, 4, 5, 6, 7, 2, 3};
for (int i = 0; i < 8; ++i)
{
CHECK_EQUAL(expected[i], value);
++value;
}
}
//*************************************************************************
TEST(test_increment_wrap_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
int expected[8] = {2, 3, 4, 5, 6, 7, 2, 3};
for (int i = 0; i < 8; ++i)
{
CHECK_EQUAL(expected[i], value);
++value;
}
}
//*************************************************************************
TEST(test_decrement_wrap_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
int expected[8] = {2, 7, 6, 5, 4, 3, 2, 7};
for (int i = 0; i < 8; ++i)
{
CHECK_EQUAL(expected[i], value);
--value;
}
}
//*************************************************************************
TEST(test_decrement_wrap_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
int expected[8] = {2, 7, 6, 5, 4, 3, 2, 7};
for (int i = 0; i < 8; ++i)
{
CHECK_EQUAL(expected[i], value);
--value;
}
}
//*************************************************************************
TEST(test_advance_positive_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.advance(2);
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_advance_positive_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.advance(2);
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_advance_positive_large_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.advance(20);
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_advance_positive_large_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.advance(20);
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_advance_negative_large_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.to_last();
value.advance(-20);
CHECK_EQUAL(5, value);
}
//*************************************************************************
TEST(test_advance_negative_large_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
value.advance(-20);
CHECK_EQUAL(5, value);
}
//*************************************************************************
TEST(test_advance_negative_unsigned_compile_time)
{
etl::cyclic_value<size_t, 0U, 2U> value;
value.advance(-2);
CHECK_EQUAL(1U, value);
}
//*************************************************************************
TEST(test_advance_negative_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
value.advance(-14);
CHECK_EQUAL(5, value);
}
//*************************************************************************
TEST(test_advance_negative_unsigned_run_time)
{
etl::cyclic_value<size_t> value;
value.set(0U, 2U);
value.advance(-2);
CHECK_EQUAL(1U, value);
}
//*************************************************************************
TEST(test_add_positive_n_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value += 2;
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_add_positive_n_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value += 2;
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_add_positive_n_large_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value += 20;
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_add_positive_n_large_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value += 20;
CHECK_EQUAL(4, value);
}
//*************************************************************************
TEST(test_add_negative_n_large_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.to_last();
value += -20;
CHECK_EQUAL(5, value);
}
//*************************************************************************
TEST(test_add_negative_n_large_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
value += -20;
CHECK_EQUAL(5, value);
}
//*************************************************************************
TEST(test_add_negative_n_unsigned_compile_time)
{
etl::cyclic_value<size_t, 0U, 2U> value;
value += -2;
CHECK_EQUAL(1U, value);
}
//*************************************************************************
TEST(test_add_negative_n_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
value += -20;
CHECK_EQUAL(5, value);
}
//*************************************************************************
TEST(test_decrease_positive_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value -= 2;
CHECK_EQUAL(6, value);
}
//*************************************************************************
TEST(test_subtract_positive_n_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value -= 2;
CHECK_EQUAL(6, value);
}
//*************************************************************************
TEST(test_subtract_positive_n_large_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value -= 20;
CHECK_EQUAL(6, value);
}
//*************************************************************************
TEST(test_subtract_positive_n_large_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value -= 20;
CHECK_EQUAL(6, value);
}
//*************************************************************************
TEST(test_subtract_negative_n_large_compile_time)
{
etl::cyclic_value<int, 2, 7> value;
value.to_last();
value -= -20;
CHECK_EQUAL(3, value);
}
//*************************************************************************
TEST(test_subtract_negative_n_large_run_time)
{
etl::cyclic_value<int> value;
value.set(2, 7);
value.to_last();
value -= -20;
CHECK_EQUAL(3, value);
}
//*************************************************************************
TEST(test_subtract_negative_n_unsigned_compile_time)
{
etl::cyclic_value<size_t, 0U, 2U> value;
value -= -2;
CHECK_EQUAL(2U, value);
}
//*************************************************************************
TEST(test_assignment_compile_time)
{
etl::cyclic_value<int, 2, 7> value1;
etl::cyclic_value<int, 2, 7> value2;
++value1;
value1 = value2;
CHECK((int)value1 == (int)value2);
value1 = 4;
CHECK((int)value1 == 4);
}
//*************************************************************************
TEST(test_assignment_run_time)
{
etl::cyclic_value<int> value1(2, 7);
etl::cyclic_value<int> value2(3, 8);
value1 = value2;
CHECK(value1.get() == value2.get());
CHECK(value1.first() == value2.first());
CHECK(value1.last() == value2.last());
value1 = 4;
CHECK((int)value1 == 4);
}
//*************************************************************************
TEST(test_equality_compile_time)
{
etl::cyclic_value<int, 2, 7> value1;
etl::cyclic_value<int, 3, 8> value2;
etl::cyclic_value<int, 3, 9> value3;
CHECK(value1 != value2);
CHECK(value2 == value3);
}
//*************************************************************************
TEST(test_equality_run_time)
{
etl::cyclic_value<int> value1(2, 7);
etl::cyclic_value<int> value2(3, 8);
etl::cyclic_value<int> value3(3, 8);
CHECK(value1 != value2);
CHECK(value2 == value3);
}
//*************************************************************************
TEST(test_swap_compile_time)
{
etl::cyclic_value<int, 2, 7> compare1;
etl::cyclic_value<int, 2, 7> compare2;
etl::cyclic_value<int, 2, 7> data1(compare1);
etl::cyclic_value<int, 2, 7> data2(compare2);
swap(data1, data2);
CHECK(data1 == compare2);
CHECK(data2 == compare1);
}
//*************************************************************************
TEST(test_swap_run_time)
{
etl::cyclic_value<int> compare1;
etl::cyclic_value<int> compare2;
compare1.set(2, 7);
compare2.set(3, 8);
etl::cyclic_value<int> data1(compare1);
etl::cyclic_value<int> data2(compare2);
swap(data1, data2);
CHECK(data1 == compare2);
CHECK(data2 == compare1);
}
//*************************************************************************
TEST(test_comparison_operators)
{
etl::cyclic_value<int, 0, 9> cv1(3);
etl::cyclic_value<int, 0, 9> cv2(3);
etl::cyclic_value<int, 0, 9> cv3(5);
etl::cyclic_value<int, -1, 8> cv4(3);
CHECK_TRUE(cv1 == cv2);
CHECK_FALSE(cv1 == cv3);
CHECK_FALSE(cv1 != cv2);
CHECK_TRUE(cv1 != cv3);
CHECK_FALSE(cv1 < cv2);
CHECK_FALSE(cv2 < cv1);
CHECK_TRUE(cv1 < cv3);
CHECK_FALSE(cv3 < cv1);
CHECK_FALSE(cv1 < cv4);
CHECK_FALSE(cv4 < cv1);
CHECK_FALSE(cv1 > cv2);
CHECK_FALSE(cv2 > cv1);
CHECK_FALSE(cv1 > cv3);
CHECK_TRUE(cv3 > cv1);
CHECK_FALSE(cv1 > cv4);
CHECK_FALSE(cv4 > cv1);
CHECK_TRUE(cv1 <= cv2);
CHECK_TRUE(cv2 <= cv1);
CHECK_TRUE(cv1 <= cv3);
CHECK_FALSE(cv3 <= cv1);
CHECK_TRUE(cv1 <= cv4);
CHECK_TRUE(cv4 <= cv1);
CHECK_TRUE(cv1 >= cv2);
CHECK_TRUE(cv2 >= cv1);
CHECK_FALSE(cv1 >= cv3);
CHECK_TRUE(cv3 >= cv1);
CHECK_TRUE(cv1 >= cv4);
CHECK_TRUE(cv4 >= cv1);
}
#if ETL_USING_CPP11
//*************************************************************************
TEST(test_cyclic_value_constexpr_ctor)
{
constexpr etl::cyclic_value<int, 0, 9> cv;
static_assert(cv.get() == 0, "constexpr default ctor");
CHECK(true);
}
#if ETL_USING_CPP14
//*************************************************************************
TEST(test_cyclic_value_constexpr_ctor_with_range)
{
constexpr etl::cyclic_value<int> cv(0, 9);
static_assert(cv.first() == 0, "constexpr range ctor first");
static_assert(cv.last() == 9, "constexpr range ctor last");
CHECK(true);
}
#endif
//*************************************************************************
TEST(test_cyclic_value_constexpr_copy_ctor)
{
constexpr etl::cyclic_value<int, 0, 9> cv1;
constexpr etl::cyclic_value<int, 0, 9> cv2(cv1);
static_assert(cv2.get() == 0, "constexpr copy ctor");
CHECK(true);
}
//*************************************************************************
TEST(test_constexpr_comparison_operators)
{
constexpr etl::cyclic_value<int, 0, 9> cv1(3);
constexpr etl::cyclic_value<int, 0, 9> cv2(3);
constexpr etl::cyclic_value<int, 0, 9> cv3(5);
constexpr etl::cyclic_value<int, -1, 8> cv4(3);
static_assert((cv1 == cv2), "(cv1 == cv2) failed");
static_assert(!(cv1 == cv3), "!(cv1 == cv3) failed");
static_assert(!(cv1 != cv2), "!(cv1 != cv2) failed");
static_assert((cv1 != cv3), "(cv1 != cv3) failed");
static_assert(!(cv1 < cv2), "!(cv1 < cv2) failed");
static_assert(!(cv2 < cv1), "!(cv2 < cv1) failed");
static_assert((cv1 < cv3), "(cv1 < cv3) failed");
static_assert(!(cv3 < cv1), "!(cv3 < cv1) failed");
static_assert(!(cv1 < cv4), "!(cv1 < cv4) failed");
static_assert(!(cv4 < cv1), "!(cv4 < cv1) failed");
static_assert(!(cv1 > cv2), "!(cv1 > cv2) failed");
static_assert(!(cv2 > cv1), "!(cv2 > cv1) failed");
static_assert(!(cv1 > cv3), "!(cv1 > cv3) failed");
static_assert((cv3 > cv1), "(cv3 > cv1) failed");
static_assert(!(cv1 > cv4), "!(cv1 > cv4) failed");
static_assert(!(cv4 > cv1), "!(cv4 > cv1) failed");
static_assert((cv1 <= cv2), "(cv1 <= cv2) failed");
static_assert((cv2 <= cv1), "(cv2 <= cv1) failed");
static_assert((cv1 <= cv3), "(cv1 <= cv3) failed");
static_assert(!(cv3 <= cv1), "!(cv3 <= cv1) failed");
static_assert((cv1 <= cv4), "(cv1 <= cv4) failed");
static_assert((cv4 <= cv1), "(cv4 <= cv1) failed");
static_assert((cv1 >= cv2), "(cv1 >= cv2) failed");
static_assert((cv2 >= cv1), "(cv2 >= cv1) failed");
static_assert(!(cv1 >= cv3), "!(cv1 >= cv3) failed");
static_assert((cv3 >= cv1), "(cv3 >= cv1) failed");
static_assert((cv1 >= cv4), "(cv1 >= cv4) failed");
static_assert((cv4 >= cv1), "(cv4 >= cv1) failed");
}
#endif
//*************************************************************************
TEST(test_maximum_unsigned_range_wrap_with_large_step_type)
{
etl::cyclic_value<uint8_t, 0, 255> value(0);
value.advance(static_cast<int32_t>(255));
CHECK_EQUAL(255, value);
value.advance(static_cast<int32_t>(1));
CHECK_EQUAL(0, value);
value.advance(static_cast<int32_t>(256));
CHECK_EQUAL(0, value);
value.advance(static_cast<int32_t>(-256));
CHECK_EQUAL(0, value);
value.advance(static_cast<int32_t>(-1));
CHECK_EQUAL(255, value);
}
//*************************************************************************
TEST(test_maximum_signed_range_wrap_with_large_step_type)
{
etl::cyclic_value<int8_t, -128, 127> value(0);
value.advance(static_cast<int32_t>(127));
CHECK_EQUAL(127, int(value));
value.advance(static_cast<int32_t>(1));
CHECK_EQUAL(-128, int(value));
value.advance(static_cast<int32_t>(256));
CHECK_EQUAL(-128, int(value));
value.advance(static_cast<int32_t>(-256));
CHECK_EQUAL(-128, int(value));
value.advance(static_cast<int32_t>(-1));
CHECK_EQUAL(127, int(value));
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_unsigned_limits_where_step_is_same_size_type)
{
const auto minimum = etl::integral_limits<uint8_t>::min;
const auto maximum = etl::integral_limits<uint8_t>::max;
etl::cyclic_value<uint8_t> value(minimum, maximum);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_signed_limits_where_step_is_same_size_type)
{
const auto minimum = etl::integral_limits<int8_t>::min;
const auto maximum = etl::integral_limits<int8_t>::max;
etl::cyclic_value<int8_t> value(minimum, maximum);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_unsigned_limits_where_step_is_larger_type)
{
const auto minimum = etl::integral_limits<uint8_t>::min;
const auto maximum = etl::integral_limits<uint8_t>::max;
etl::cyclic_value<uint8_t, minimum, maximum> value(0);
value.advance(int16_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_signed_limits_where_step_is_larger_type)
{
const auto minimum = etl::integral_limits<int8_t>::min;
const auto maximum = etl::integral_limits<int8_t>::max;
etl::cyclic_value<int8_t> value(minimum, maximum);
value.advance(uint16_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_unsigned_limits_where_step_is_smaller_type)
{
const auto minimum = etl::integral_limits<uint16_t>::min;
const auto maximum = etl::integral_limits<uint16_t>::max;
etl::cyclic_value<uint16_t, minimum, maximum> value(0);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_signed_limits_where_step_is_smaller_type)
{
const auto minimum = etl::integral_limits<int16_t>::min;
const auto maximum = etl::integral_limits<int16_t>::max;
etl::cyclic_value<int16_t> value(minimum, maximum);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_unsigned_limits_where_the_types_are_64bit)
{
const auto minimum = etl::integral_limits<uint64_t>::min;
const auto maximum = etl::integral_limits<uint64_t>::max;
etl::cyclic_value<uint64_t, minimum, maximum> value(0);
value.advance(int64_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_compile_time_range_issue_in_advance_for_full_range_signed_limits_where_the_types_are_64bit)
{
const auto minimum = etl::integral_limits<int64_t>::min;
const auto maximum = etl::integral_limits<int64_t>::max;
etl::cyclic_value<int64_t> value(minimum, maximum);
value.advance(int64_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_unsigned_limits_where_step_is_same_size_type)
{
const auto minimum = etl::integral_limits<uint8_t>::min;
const auto maximum = etl::integral_limits<uint8_t>::max;
etl::cyclic_value<uint8_t> value(minimum, maximum);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_signed_limits_where_step_is_same_size_type)
{
const auto minimum = etl::integral_limits<int8_t>::min;
const auto maximum = etl::integral_limits<int8_t>::max;
etl::cyclic_value<int8_t> value(minimum, maximum);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_unsigned_limits_where_step_is_larger_type)
{
const auto minimum = etl::integral_limits<uint8_t>::min;
const auto maximum = etl::integral_limits<uint8_t>::max;
etl::cyclic_value<uint8_t, minimum, maximum> value(0);
value.advance(int16_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_signed_limits_where_step_is_larger_type)
{
const auto minimum = etl::integral_limits<int8_t>::min;
const auto maximum = etl::integral_limits<int8_t>::max;
etl::cyclic_value<int8_t> value(minimum, maximum);
value.advance(uint16_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_unsigned_limits_where_step_is_smaller_type)
{
const auto minimum = etl::integral_limits<uint16_t>::min;
const auto maximum = etl::integral_limits<uint16_t>::max;
etl::cyclic_value<uint16_t, minimum, maximum> value(0);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_signed_limits_where_step_is_smaller_type)
{
const auto minimum = etl::integral_limits<int16_t>::min;
const auto maximum = etl::integral_limits<int16_t>::max;
etl::cyclic_value<int16_t> value(minimum, maximum);
value.advance(int8_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_unsigned_limits_where_the_types_are_64bit)
{
const auto minimum = etl::integral_limits<uint64_t>::min;
const auto maximum = etl::integral_limits<uint64_t>::max;
etl::cyclic_value<uint64_t, minimum, maximum> value(0);
value.advance(int64_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
//*************************************************************************
TEST(test_run_time_range_issue_in_advance_for_full_range_signed_limits_where_the_types_are_64bit)
{
const auto minimum = etl::integral_limits<int64_t>::min;
const auto maximum = etl::integral_limits<int64_t>::max;
etl::cyclic_value<int64_t> value(minimum, maximum);
value.advance(int64_t(2));
CHECK_EQUAL(minimum + 2, value.get());
}
}
} // namespace