mirror of
https://github.com/ETLCPP/etl.git
synced 2026-07-31 00:36:20 +08:00
commit c5dc331004b4d9611ab996935bedada203676c71
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Sat Jul 11 12:32:20 2026 +0100
Updated release notes
commit 4bf6ed6ce8d79857658d763e368ee56617542b2c
Author: vcoselev <145198867+vcoselev@users.noreply.github.com>
Date: Sat Jul 11 12:05:39 2026 +0100
Fix for 1405: etl::exchange doesn't work with unique_ptr (#1477)
* Separate bit order and endianness in bit_stream.h (#1495)
* Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)
* Fix exchange to use forwarding reference (U&&) and move
- etl::exchange was using the copy constructor. Changed for etl::move.
- The assignment to the new object is now done with forward.
- Added a test with unique_ptr.
---------
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 2ed9019df04d470530c41c1f27d35adc30b9a32d
Author: Moritz Pflanzer <moritz@pflanzer.eu>
Date: Fri Jul 10 11:42:32 2026 +0200
Update operator[] docs for map class (#1499)
* Separate bit order and endianness in bit_stream.h (#1495)
* Update operator[] docs for map class
No const variant is implemented for the operator[].
---------
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
commit 423e18d96dc645f1c733cb0d8ae6b675b9eb7e83
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Fri Jul 10 11:14:08 2026 +0200
Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)
commit 338bfdbb1f4df3c5c08a68a9038f13b8dae1c28b
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date: Fri Jul 10 10:12:04 2026 +0100
Add coverage report to docs (#1498)
* Updated release notes
* Added link to coverage report
---------
Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
commit 269025424f4c6f61cebac090f4df82985fb3b239
Merge: c004cc9d faa4c15b
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Thu Jul 9 14:18:32 2026 +0100
Merge branch 'development' of https://github.com/ETLCPP/etl into development
commit c004cc9d508efcf398630758a47aae95b37a7eb8
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Thu Jul 9 10:06:17 2026 +0100
Updated release notes
commit faa4c15b49c8ad15475c83ae23e00f5a46f803ca
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Thu Jul 9 10:06:17 2026 +0100
Updated release notes
commit 1523e63e35a15cfd1fa72d230a3c79efa7b9c3e0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Wed Jul 8 20:48:33 2026 +0200
Support non-assignable alternatives in variant (#1496)
commit 878a0ba5a28f6b0dcae9f472a6a6a1f107de0a74
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Wed Jul 8 11:07:01 2026 +0100
Updated version and release notes
commit 5287fe4b3b9f58330881d2a62abf6ce8e1159b8d
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date: Wed Jul 8 09:06:50 2026 +0100
Allow etl::vector to store pointers to functions and member functions (#1492)
* Refactored vector.h
Deleted ivectorpointer.h
* Minor changes
* Fixed code incompatible with C++03
* Clang-format changes
* Removed redundant double-qualified name
* Fixed is_is_object_pointer_v to is_object_pointer_v
* Added new test files to meson.build
* Added overflow checks to vector_ext copy and move constructors and assignments
Added assert throw tests.
* Added diagnostic pushes to eliminate GCC warning false positives
* Changed the GCC C++23 Github action to use GCC14
* Applied clang-format
* Added guard to pop_heap
* Added guard to adjust_heap
* Attempt to fix GCC diagnostic
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* clang-format
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Missing newline at end of file
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
* clang-format
* Changed gcc --version to gcc-14 --version
---------
Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
commit 40dddd7f9601985ae7350e60a404af9028bc9fe9
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 23:41:17 2026 +0200
Add optional etl_profile label_flag for Bazel profile injection (#1491)
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 84fca4cd62f72c382c062376ca934803116a20d5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 21:45:47 2026 +0200
Add missing memory functions, according the standard (#1490)
Adding:
- etl::align
- etl::assume_aligned
- etl::is_sufficiently_aligned
- etl::launder
- etl::pointer_traits
- etl::start_lifetime_as
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit dca6653b3759b2cdc79307fec7425589feea478d
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 21:00:09 2026 +0200
Add missing interfaces to etl::chrono (#1489)
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit c52b2ac7b1f675e6b1d34052239423b7f3634033
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 18:06:05 2026 +0200
Fix etl::mem_cast cross-size copy constructor and assignment (#1488)
The templated cross-size copy constructor and assignment operator were
broken in two ways:
- They accessed other.buffer / rhs.buffer, which is private in a
different mem_cast instantiation, so the cross-size overloads failed
to compile whenever they were actually instantiated.
- They copied Size_ (the destination size) bytes from a source buffer
that is only Other_Size bytes large, reading past the end of the
source when the destination was larger.
Use the public data() accessor and copy Other_Size bytes. The existing
static_assert(Size >= Other_Size) guarantees the destination is big
enough.
Add test_mem_cast_copy_and_assign_from_smaller regression test.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 165674cb23dda1fd4f7e5a1182f49554a796bfe8
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 16:41:50 2026 +0200
Fix etl::pearson::reset() not resetting the first-byte flag (#1487)
reset() cleared the hash array but left the `first` flag false, so a
calculator reused after reset() took the XOR update path on its next
add() instead of the initialisation path. This produced an incorrect
hash for any pearson object that was reset and reused.
Reset `first` to true in reset() so a reset calculator behaves like a
freshly constructed one.
Add test_pearson_reset regression test.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 032ec4cc80f1c0f1baa0383bdbc5f9239b68f268
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 13:40:04 2026 +0200
Fix etl::bitset single-element from_string shift on empty string (#1486)
The single-element from_string overloads (char, wchar_t, char16_t,
char32_t) computed element_type(1) << (string_length - 1U) before the
copy loop. For an empty string, or when active_bits is 0, string_length
is 0, so the shift count underflows to SIZE_MAX. Shifting by more than
the element width is undefined behaviour, which also breaks constexpr
evaluation.
Guard the mask with a zero-length check so the shift is only performed
when string_length > 0. The multi-element from_string overloads were
already safe.
Add test_construct_from_empty_string regression test.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 98cb365d4c28e7b72f8547b734a03a4068acd3f5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 12:32:56 2026 +0200
Fix etl::histogram copy/move not preserving start_index (#1485)
The run-time-offset specialization of etl::histogram stores a start_index
member used to map keys to bins (accumulator[key - start_index]). Its copy
constructor, move constructor, copy assignment, and move assignment copied
only the accumulator and left start_index uninitialized, so a copied or
moved histogram indexed the wrong bin in operator[]/add(), causing
out-of-bounds access (undefined behavior).
All four special member functions now also copy start_index. The
compile-time-offset specialization is unaffected, as its start index is a
template constant rather than a data member.
Add regression tests covering copy/move construction and assignment.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 5cd2f28cd54e4019f7be126bcf7394a6a8318eb9
Author: Drew Rife <darife@jlg.com>
Date: Tue Jul 7 03:14:48 2026 -0400
Refactor variant::emplace to perfect forward args instead of copy/move construct (#1494)
* refactor: emplace logic to use do_emplace for in-place construction with forwarded arguments #1493
* Add test for variant_variadic
---------
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
commit a47c0aae81b886259918961d5fcee20faa06fdd0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Mon Jul 6 17:32:26 2026 +0200
Fix etl::message_timer firing following timers early on unregister (#1484)
active_list.remove(id, has_expired) adjusts the next timer's delta only
when has_expired is false. When unregistering an active, non-expired timer,
unregister_timer() incorrectly passed true, skipping that adjustment, so
every timer after the removed one in the active list fired early by the
removed timer's delta.
Pass false instead, matching the etl::callback_timer family. tick() still
passes true, since the timer has genuinely expired there. The bug affected
all four variants: message_timer, message_timer_interrupt,
message_timer_atomic and message_timer_locked. Existing tests missed it
because they only ever unregistered the tail timer, where the delta
adjustment is a no-op.
Add a regression test that unregisters a non-tail active timer and checks
the following timer still fires at its original absolute time.
1818 lines
64 KiB
C++
1818 lines
64 KiB
C++
/******************************************************************************
|
|
The MIT License(MIT)
|
|
|
|
Embedded Template Library.
|
|
https://github.com/ETLCPP/etl
|
|
https://www.etlcpp.com
|
|
|
|
Copyright(c) 2014 John Wellbelove, rlindeman
|
|
|
|
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 <algorithm>
|
|
#include <array>
|
|
#include <iterator>
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "etl/map.h"
|
|
#include "etl/string.h"
|
|
|
|
#include "data.h"
|
|
|
|
static const size_t MAX_SIZE = 10UL;
|
|
|
|
#define TEST_GREATER_THAN
|
|
#ifdef TEST_GREATER_THAN
|
|
using Data = etl::map<std::string, int, MAX_SIZE, std::greater<std::string>>;
|
|
using IData = etl::imap<std::string, int, std::greater<std::string>>;
|
|
using Compare_Data = std::map<std::string, int, std::greater<std::string>>;
|
|
#else
|
|
using Data = etl::map<std::string, int, MAX_SIZE, std::less<std::string>>;
|
|
using IData = etl::imap<std::string, int, std::less<std::string>>;
|
|
using Compare_Data = std::map<std::string, int, std::less<std::string>>;
|
|
#endif
|
|
|
|
using ItemM = TestDataM<int>;
|
|
using DataM = etl::map<std::string, ItemM, MAX_SIZE>;
|
|
|
|
using Data_iterator = Data::iterator;
|
|
using Data_const_iterator = Data::const_iterator;
|
|
using Compare_Data_iterator = Compare_Data::iterator;
|
|
using Compare_Data_const_iterator = Compare_Data::const_iterator;
|
|
|
|
namespace
|
|
{
|
|
struct Key
|
|
{
|
|
Key(const char* k_)
|
|
: k(k_)
|
|
{
|
|
}
|
|
|
|
std::string k;
|
|
};
|
|
|
|
bool operator<(const Key& lhs, const std::string& rhs)
|
|
{
|
|
return (lhs.k < rhs);
|
|
}
|
|
|
|
bool operator<(const std::string& lhs, const Key& rhs)
|
|
{
|
|
return (lhs < rhs.k);
|
|
}
|
|
|
|
SUITE(test_map)
|
|
{
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_null_dereference_push.h"
|
|
template <typename T1, typename T2>
|
|
bool Check_Equal(T1 begin1, T1 end1, T2 begin2)
|
|
{
|
|
while (begin1 != end1)
|
|
{
|
|
if ((begin1->first != begin2->first) || (begin1->second != begin2->second))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
++begin1;
|
|
++begin2;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
struct SetupFixture
|
|
{
|
|
// Maps of predefined data from which to construct maps used in each test
|
|
std::map<std::string, int> initial_data;
|
|
std::map<std::string, int> excess_data;
|
|
std::map<std::string, int> different_data;
|
|
std::map<std::string, int> random_data;
|
|
std::map<std::string, int> initial_data_even;
|
|
std::map<std::string, int> test_data;
|
|
|
|
SetupFixture()
|
|
{
|
|
// Create a map of initial data
|
|
initial_data["0"] = 0;
|
|
initial_data["1"] = 1;
|
|
initial_data["2"] = 2;
|
|
initial_data["3"] = 3;
|
|
initial_data["4"] = 4;
|
|
initial_data["5"] = 5;
|
|
initial_data["6"] = 6;
|
|
initial_data["7"] = 7;
|
|
initial_data["8"] = 8;
|
|
initial_data["9"] = 9;
|
|
|
|
// Create a map of excess data
|
|
excess_data["0"] = 0;
|
|
excess_data["1"] = 1;
|
|
excess_data["2"] = 2;
|
|
excess_data["3"] = 3;
|
|
excess_data["4"] = 4;
|
|
excess_data["5"] = 5;
|
|
excess_data["6"] = 6;
|
|
excess_data["7"] = 7;
|
|
excess_data["8"] = 8;
|
|
excess_data["9"] = 9;
|
|
excess_data["10"] = 10;
|
|
|
|
// Create a map of different data
|
|
different_data["10"] = 10;
|
|
different_data["11"] = 11;
|
|
different_data["12"] = 12;
|
|
different_data["13"] = 13;
|
|
different_data["14"] = 14;
|
|
different_data["15"] = 15;
|
|
different_data["16"] = 16;
|
|
different_data["17"] = 17;
|
|
different_data["18"] = 18;
|
|
different_data["19"] = 19;
|
|
|
|
// Create a map of random data
|
|
random_data["6"] = 6;
|
|
random_data["5"] = 5;
|
|
random_data["0"] = 0;
|
|
random_data["8"] = 8;
|
|
random_data["9"] = 9;
|
|
random_data["2"] = 2;
|
|
random_data["1"] = 1;
|
|
random_data["3"] = 3;
|
|
random_data["7"] = 7;
|
|
random_data["4"] = 4;
|
|
|
|
// even values
|
|
initial_data_even["00"] = 0;
|
|
initial_data_even["02"] = 2;
|
|
initial_data_even["04"] = 4;
|
|
initial_data_even["06"] = 6;
|
|
initial_data_even["08"] = 8;
|
|
initial_data_even["10"] = 10;
|
|
initial_data_even["12"] = 12;
|
|
initial_data_even["14"] = 14;
|
|
initial_data_even["16"] = 16;
|
|
initial_data_even["18"] = 18;
|
|
|
|
// test set
|
|
test_data["00"] = 0;
|
|
test_data["01"] = 1;
|
|
test_data["02"] = 2;
|
|
test_data["03"] = 3;
|
|
test_data["04"] = 4;
|
|
test_data["05"] = 5;
|
|
test_data["06"] = 6;
|
|
test_data["07"] = 7;
|
|
test_data["08"] = 8;
|
|
test_data["09"] = 9;
|
|
test_data["10"] = 10;
|
|
test_data["11"] = 11;
|
|
test_data["12"] = 12;
|
|
test_data["13"] = 13;
|
|
test_data["14"] = 14;
|
|
test_data["15"] = 15;
|
|
test_data["16"] = 16;
|
|
test_data["17"] = 17;
|
|
test_data["18"] = 18;
|
|
test_data["19"] = 19;
|
|
}
|
|
};
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_default_constructor)
|
|
{
|
|
Data data;
|
|
|
|
CHECK(data.size() == 0UL);
|
|
CHECK(data.empty());
|
|
CHECK(data.capacity() == MAX_SIZE);
|
|
CHECK(data.max_size() == MAX_SIZE);
|
|
CHECK(data.begin() == data.end());
|
|
}
|
|
|
|
#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_cpp17_deduced_constructor)
|
|
{
|
|
etl::map data{std::pair<std::string, int>("0", 0), std::pair<std::string, int>("1", 1), std::pair<std::string, int>("2", 2),
|
|
std::pair<std::string, int>("3", 3), std::pair<std::string, int>("4", 4), std::pair<std::string, int>("5", 5),
|
|
std::pair<std::string, int>("6", 6), std::pair<std::string, int>("7", 7), std::pair<std::string, int>("8", 8),
|
|
std::pair<std::string, int>("9", 9)};
|
|
etl::map<std::string, int, 10U> check = {std::pair<std::string, int>("0", 0), std::pair<std::string, int>("1", 1),
|
|
std::pair<std::string, int>("2", 2), std::pair<std::string, int>("3", 3),
|
|
std::pair<std::string, int>("4", 4), std::pair<std::string, int>("5", 5),
|
|
std::pair<std::string, int>("6", 6), std::pair<std::string, int>("7", 7),
|
|
std::pair<std::string, int>("8", 8), std::pair<std::string, int>("9", 9)};
|
|
|
|
CHECK(!data.empty());
|
|
CHECK(data.full());
|
|
CHECK(data.begin() != data.end());
|
|
CHECK_EQUAL(10U, data.size());
|
|
CHECK_EQUAL(0U, data.available());
|
|
CHECK_EQUAL(10U, data.capacity());
|
|
CHECK_EQUAL(10U, data.max_size());
|
|
CHECK(data == check);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data1(compare_data.begin(), compare_data.end());
|
|
Data data2(data1);
|
|
|
|
CHECK(initial_data.size() == data1.size());
|
|
CHECK(data1.size() == data2.size());
|
|
|
|
bool isEqual = false;
|
|
|
|
isEqual = Check_Equal(data1.begin(), data1.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
isEqual = Check_Equal(data2.begin(), data2.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data2.begin(), data2.end(), data2.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_move_constructor)
|
|
{
|
|
DataM data1;
|
|
|
|
ItemM d1(1);
|
|
ItemM d2(2);
|
|
ItemM d3(3);
|
|
|
|
data1.insert(DataM::value_type(std::string("1"), etl::move(d1)));
|
|
data1.insert(DataM::value_type(std::string("2"), etl::move(d2)));
|
|
data1.insert(DataM::value_type(std::string("3"), etl::move(d3)));
|
|
data1.insert(DataM::value_type(std::string("4"), ItemM(4)));
|
|
|
|
DataM data2(std::move(data1));
|
|
|
|
CHECK(!data1.empty()); // Move does not clear the source.
|
|
|
|
CHECK(1 == data2.at("1").value);
|
|
CHECK(2 == data2.at("2").value);
|
|
CHECK(3 == data2.at("3").value);
|
|
CHECK(4 == data2.at("4").value);
|
|
|
|
CHECK_TRUE(std::is_sorted(data2.begin(), data2.end(), data2.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_destruct_via_imap)
|
|
{
|
|
Data* pdata = new Data(initial_data.begin(), initial_data.end());
|
|
|
|
IData* pidata = pdata;
|
|
delete pidata;
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
size_t d = static_cast<size_t>(std::distance(data.begin(), data.end()));
|
|
|
|
CHECK(d == MAX_SIZE);
|
|
CHECK(data.size() == MAX_SIZE);
|
|
CHECK(!data.empty());
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_initializer_list)
|
|
{
|
|
Compare_Data compare_data = {Data::value_type(std::string("0"), 0), Data::value_type(std::string("1"), 1),
|
|
Data::value_type(std::string("2"), 2), Data::value_type(std::string("3"), 3)};
|
|
|
|
Data data = {Data::value_type(std::string("0"), 0), Data::value_type(std::string("1"), 1), Data::value_type(std::string("2"), 2),
|
|
Data::value_type(std::string("3"), 3)};
|
|
|
|
CHECK(compare_data.size() == data.size());
|
|
CHECK(!data.empty());
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assignment)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data otherData;
|
|
|
|
otherData = data;
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), otherData.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(otherData.begin(), otherData.end(), otherData.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assignment_interface)
|
|
{
|
|
Data data1(initial_data.begin(), initial_data.end());
|
|
Data data2;
|
|
|
|
IData& idata1 = data1;
|
|
IData& idata2 = data2;
|
|
|
|
idata2 = idata1;
|
|
|
|
bool isEqual = std::equal(data1.begin(), data1.end(), data2.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data2.begin(), data2.end(), data2.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_self_assignment)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data other_data(data);
|
|
|
|
#include "etl/private/diagnostic_self_assign_overloaded_push.h"
|
|
other_data = other_data;
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
bool isEqual = std::equal(data.begin(), data.end(), other_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_move_assignment)
|
|
{
|
|
DataM data1;
|
|
DataM data2;
|
|
|
|
ItemM d1(1);
|
|
ItemM d2(2);
|
|
ItemM d3(3);
|
|
|
|
data1.insert(DataM::value_type(std::string("1"), etl::move(d1)));
|
|
data1.insert(DataM::value_type(std::string("2"), etl::move(d2)));
|
|
data1.insert(DataM::value_type(std::string("3"), etl::move(d3)));
|
|
data1.insert(DataM::value_type(std::string("4"), ItemM(4)));
|
|
|
|
data2.insert(DataM::value_type(std::string("5"), ItemM(5)));
|
|
data2 = std::move(data1);
|
|
|
|
CHECK(1 == data2.at("1").value);
|
|
CHECK(2 == data2.at("2").value);
|
|
CHECK(3 == data2.at("3").value);
|
|
CHECK(4 == data2.at("4").value);
|
|
|
|
CHECK_TRUE(std::is_sorted(data2.begin(), data2.end(), data2.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_begin)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
const Data constData(data);
|
|
|
|
CHECK(data.begin() == std::begin(data));
|
|
CHECK(constData.begin() == std::begin(constData));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_end)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
const Data constData(data);
|
|
|
|
CHECK(data.end() == std::end(data));
|
|
CHECK(constData.end() == std::end(constData));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_empty)
|
|
{
|
|
Data data;
|
|
data.insert(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.full());
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_full)
|
|
{
|
|
Data data;
|
|
|
|
CHECK(!data.full());
|
|
CHECK(data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_index)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
CHECK(data["0"] == compare_data["0"]);
|
|
CHECK(data["1"] == compare_data["1"]);
|
|
CHECK(data["2"] == compare_data["2"]);
|
|
CHECK(data["3"] == compare_data["3"]);
|
|
CHECK(data["4"] == compare_data["4"]);
|
|
CHECK(data["5"] == compare_data["5"]);
|
|
CHECK(data["6"] == compare_data["6"]);
|
|
CHECK(data["7"] == compare_data["7"]);
|
|
CHECK(data["8"] == compare_data["8"]);
|
|
CHECK(data["9"] == compare_data["9"]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_index_value_changed)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data["0"] = 0;
|
|
compare_data["0"] = 0;
|
|
|
|
data["0"] = 1;
|
|
compare_data["0"] = 1;
|
|
|
|
CHECK(data["0"] == compare_data["0"]);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.at("0") == compare_data.at("0"));
|
|
CHECK(data.at("1") == compare_data.at("1"));
|
|
CHECK(data.at("2") == compare_data.at("2"));
|
|
CHECK(data.at("3") == compare_data.at("3"));
|
|
CHECK(data.at("4") == compare_data.at("4"));
|
|
CHECK(data.at("5") == compare_data.at("5"));
|
|
CHECK(data.at("6") == compare_data.at("6"));
|
|
CHECK(data.at("7") == compare_data.at("7"));
|
|
CHECK(data.at("8") == compare_data.at("8"));
|
|
CHECK(data.at("9") == compare_data.at("9"));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
CMap compare_data(initial_data.begin(), initial_data.end());
|
|
EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.at(Key("0")) == compare_data.at("0"));
|
|
CHECK(data.at(Key("1")) == compare_data.at("1"));
|
|
CHECK(data.at(Key("2")) == compare_data.at("2"));
|
|
CHECK(data.at("3") == compare_data.at("3"));
|
|
CHECK(data.at(Key("4")) == compare_data.at("4"));
|
|
CHECK(data.at(Key("5")) == compare_data.at("5"));
|
|
CHECK(data.at(Key("6")) == compare_data.at("6"));
|
|
CHECK(data.at(Key("7")) == compare_data.at("7"));
|
|
CHECK(data.at(Key("8")) == compare_data.at("8"));
|
|
CHECK(data.at(Key("9")) == compare_data.at("9"));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_exception)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
data.erase("5");
|
|
|
|
CHECK_THROW(data.at("-1"), etl::map_out_of_bounds);
|
|
CHECK_THROW(data.at("5"), etl::map_out_of_bounds);
|
|
CHECK_THROW(data.at("10"), etl::map_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_const)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.at("0") == compare_data.at("0"));
|
|
CHECK(data.at("1") == compare_data.at("1"));
|
|
CHECK(data.at("2") == compare_data.at("2"));
|
|
CHECK(data.at("3") == compare_data.at("3"));
|
|
CHECK(data.at("4") == compare_data.at("4"));
|
|
CHECK(data.at("5") == compare_data.at("5"));
|
|
CHECK(data.at("6") == compare_data.at("6"));
|
|
CHECK(data.at("7") == compare_data.at("7"));
|
|
CHECK(data.at("8") == compare_data.at("8"));
|
|
CHECK(data.at("9") == compare_data.at("9"));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_const_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
const CMap compare_data(initial_data.begin(), initial_data.end());
|
|
const EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.at(Key("0")) == compare_data.at("0"));
|
|
CHECK(data.at(Key("1")) == compare_data.at("1"));
|
|
CHECK(data.at(Key("2")) == compare_data.at("2"));
|
|
CHECK(data.at(Key("3")) == compare_data.at("3"));
|
|
CHECK(data.at(Key("4")) == compare_data.at("4"));
|
|
CHECK(data.at(Key("5")) == compare_data.at("5"));
|
|
CHECK(data.at(Key("6")) == compare_data.at("6"));
|
|
CHECK(data.at(Key("7")) == compare_data.at("7"));
|
|
CHECK(data.at(Key("8")) == compare_data.at("8"));
|
|
CHECK(data.at(Key("9")) == compare_data.at("9"));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_const_exception)
|
|
{
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.at("10"), etl::map_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_range)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data;
|
|
|
|
data.assign(compare_data.begin(), compare_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_value)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
ETL_OR_STD::pair<Data::iterator, bool> data_result = data.insert(Data::value_type(std::string("0"), 0));
|
|
ETL_OR_STD::pair<Compare_Data::iterator, bool> compare_result = compare_data.insert(ETL_OR_STD::make_pair(std::string("0"), 0));
|
|
|
|
// Check that both return successful return results
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.second == compare_result.second);
|
|
|
|
// Try adding a duplicate (should return iterator pointing to duplicate)
|
|
data_result = data.insert(Data::value_type(std::string("0"), 0));
|
|
compare_result = compare_data.insert(ETL_OR_STD::make_pair(std::string("0"), 0));
|
|
|
|
// Check that both return successful return results
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.second == compare_result.second);
|
|
|
|
// Check that elements in map are the same
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
data.insert(ETL_OR_STD::make_pair(std::string("2"), 2));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("2"), 2));
|
|
|
|
isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
data.insert(ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
|
|
isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_value2)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.insert(Data::value_type(std::string("0"), 0));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("0"), 0));
|
|
|
|
data.insert(Data::value_type(std::string("1"), 1));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
|
|
data.insert(Data::value_type(std::string("-1"), -1));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("-1"), -1));
|
|
|
|
// Check that elements in map are the same
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_moved_value)
|
|
{
|
|
DataM data;
|
|
|
|
ItemM d1(1);
|
|
ItemM d2(2);
|
|
ItemM d3(3);
|
|
|
|
data.insert(DataM::value_type(std::string("1"), etl::move(d1)));
|
|
data.insert(DataM::value_type(std::string("2"), etl::move(d2)));
|
|
data.insert(DataM::value_type(std::string("3"), etl::move(d3)));
|
|
data.insert(DataM::value_type(std::string("4"), ItemM(4)));
|
|
|
|
CHECK(!bool(d1));
|
|
CHECK(!bool(d2));
|
|
CHECK(!bool(d3));
|
|
|
|
CHECK(1 == data.at("1").value);
|
|
CHECK(2 == data.at("2").value);
|
|
CHECK(3 == data.at("3").value);
|
|
CHECK(4 == data.at("4").value);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_value_changed)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.insert(Data::value_type(std::string("0"), 0));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("0"), 0));
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
data.insert(ETL_OR_STD::make_pair(std::string("0"), 1));
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("0"), 1));
|
|
|
|
isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_hint_value)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
ETL_OR_STD::pair<Data::iterator, bool> data_result = data.insert(Data::value_type(std::string("2"), 2));
|
|
ETL_OR_STD::pair<Compare_Data::iterator, bool> compare_result = compare_data.insert(ETL_OR_STD::make_pair(std::string("2"), 2));
|
|
|
|
// Check that both return successful return results
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.second == compare_result.second);
|
|
|
|
// Check that elements in map are the same
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
data.insert(data_result.first, ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
compare_data.insert(compare_result.first, ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
|
|
isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_const_hint_value)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
ETL_OR_STD::pair<Data::iterator, bool> data_result = data.insert(Data::value_type(std::string("2"), 2));
|
|
ETL_OR_STD::pair<Compare_Data::iterator, bool> compare_result = compare_data.insert(ETL_OR_STD::make_pair(std::string("2"), 2));
|
|
|
|
// Check that both return successful return results
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.second == compare_result.second);
|
|
|
|
// Check that elements in map are the same
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
data.insert(Data::const_iterator(data_result.first), ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
compare_data.insert(Compare_Data::const_iterator(compare_result.first), ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
|
|
isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_value_excess)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.insert(ETL_OR_STD::make_pair(std::string("10"), 10)), etl::map_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_range)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.insert(initial_data.begin(), initial_data.end());
|
|
compare_data.insert(initial_data.begin(), initial_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_range_random)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.insert(random_data.begin(), random_data.end());
|
|
compare_data.insert(random_data.begin(), random_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_range_excess)
|
|
{
|
|
Data data;
|
|
|
|
CHECK_THROW(data.insert(excess_data.begin(), excess_data.end()), etl::map_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_value)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
ETL_OR_STD::pair<Data::iterator, bool> data_result = data.emplace(std::string("0"), 0);
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("0"), 0));
|
|
|
|
// Check that the insertion was successful
|
|
CHECK(data_result.first->first == std::string("0"));
|
|
CHECK(data_result.first->second == 0);
|
|
CHECK(data_result.second == true);
|
|
|
|
// Try adding a duplicate (should return iterator pointing to duplicate, inserted = false)
|
|
data_result = data.emplace(std::string("0"), 1);
|
|
|
|
CHECK(data_result.first->first == std::string("0"));
|
|
CHECK(data_result.first->second == 0);
|
|
CHECK(data_result.second == false);
|
|
|
|
// Add more elements
|
|
data.emplace(std::string("2"), 2);
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("2"), 2));
|
|
|
|
data.emplace(std::string("1"), 1);
|
|
compare_data.insert(ETL_OR_STD::make_pair(std::string("1"), 1));
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_value_from_pair)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
Data::value_type pair0(std::string("0"), 0);
|
|
Data::value_type pair1(std::string("1"), 1);
|
|
Data::value_type pair2(std::string("2"), 2);
|
|
|
|
data.emplace(pair0);
|
|
compare_data.insert(pair0);
|
|
|
|
data.emplace(pair1);
|
|
compare_data.insert(pair1);
|
|
|
|
data.emplace(pair2);
|
|
compare_data.insert(pair2);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_moved_value)
|
|
{
|
|
DataM data;
|
|
|
|
ItemM d1(1);
|
|
ItemM d2(2);
|
|
ItemM d3(3);
|
|
|
|
data.emplace(std::string("1"), etl::move(d1));
|
|
data.emplace(std::string("2"), etl::move(d2));
|
|
data.emplace(std::string("3"), etl::move(d3));
|
|
data.emplace(std::string("4"), ItemM(4));
|
|
|
|
CHECK(!bool(d1));
|
|
CHECK(!bool(d2));
|
|
CHECK(!bool(d3));
|
|
|
|
CHECK(1 == data.at("1").value);
|
|
CHECK(2 == data.at("2").value);
|
|
CHECK(3 == data.at("3").value);
|
|
CHECK(4 == data.at("4").value);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_excess)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.emplace(std::string("10"), 10), etl::map_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_try_emplace_value)
|
|
{
|
|
Data data;
|
|
|
|
ETL_OR_STD::pair<Data::iterator, bool> result1 = data.try_emplace(std::string("0"), 0);
|
|
CHECK(result1.first->first == std::string("0"));
|
|
CHECK(result1.first->second == 0);
|
|
CHECK(result1.second == true);
|
|
|
|
// Try adding a duplicate (should not construct value, return existing)
|
|
ETL_OR_STD::pair<Data::iterator, bool> result2 = data.try_emplace(std::string("0"), 99);
|
|
CHECK(result2.first->first == std::string("0"));
|
|
CHECK(result2.first->second == 0);
|
|
CHECK(result2.second == false);
|
|
|
|
CHECK_EQUAL(1U, data.size());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_try_emplace_moved_value)
|
|
{
|
|
DataM data;
|
|
|
|
ItemM d1(1);
|
|
ItemM d2(2);
|
|
|
|
data.try_emplace(std::string("1"), etl::move(d1));
|
|
CHECK(!bool(d1));
|
|
CHECK(1 == data.at("1").value);
|
|
|
|
// Duplicate key: d2 should NOT be moved from
|
|
data.try_emplace(std::string("1"), etl::move(d2));
|
|
CHECK(bool(d2));
|
|
CHECK(1 == data.at("1").value);
|
|
CHECK_EQUAL(1U, data.size());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_try_emplace_rvalue_key)
|
|
{
|
|
DataM data;
|
|
|
|
std::string key1("1");
|
|
std::string key2("2");
|
|
std::string key1_dup("1");
|
|
|
|
auto result1 = data.try_emplace(etl::move(key1), ItemM(1));
|
|
CHECK(result1.second == true);
|
|
CHECK(key1.empty()); // key was moved from
|
|
CHECK(1 == data.at("1").value);
|
|
|
|
auto result2 = data.try_emplace(etl::move(key2), ItemM(2));
|
|
CHECK(result2.second == true);
|
|
CHECK(key2.empty()); // key was moved from
|
|
CHECK(2 == data.at("2").value);
|
|
|
|
// Duplicate key: key should NOT be moved from
|
|
auto result3 = data.try_emplace(etl::move(key1_dup), ItemM(99));
|
|
CHECK(result3.second == false);
|
|
CHECK(!key1_dup.empty()); // key was NOT moved
|
|
CHECK(1 == data.at("1").value);
|
|
CHECK_EQUAL(2U, data.size());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_equal_range)
|
|
{
|
|
Compare_Data compare_data(random_data.begin(), random_data.end());
|
|
Data data(random_data.begin(), random_data.end());
|
|
|
|
ETL_OR_STD::pair<Data::iterator, Data::iterator> data_result = data.equal_range("2");
|
|
Data::iterator data_lb = data.lower_bound("2");
|
|
ETL_OR_STD::pair<Compare_Data::iterator, Compare_Data::iterator> compare_result = compare_data.equal_range("2");
|
|
Compare_Data::iterator compare_data_lb = compare_data.lower_bound("2");
|
|
|
|
// Check that both return the same return results
|
|
CHECK(data_lb->first == compare_data_lb->first);
|
|
CHECK(data_lb->second == compare_data_lb->second);
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.first->second == compare_result.first->second);
|
|
CHECK(data_result.second->first == compare_result.second->first);
|
|
CHECK(data_result.second->second == compare_result.second->second);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_equal_range_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
CMap compare_data(random_data.begin(), random_data.end());
|
|
EMap data(random_data.begin(), random_data.end());
|
|
|
|
ETL_OR_STD::pair<EMap::iterator, EMap::iterator> data_result = data.equal_range(Key("2"));
|
|
EMap::iterator data_lb = data.lower_bound("2");
|
|
ETL_OR_STD::pair<CMap::iterator, CMap::iterator> compare_result = compare_data.equal_range("2");
|
|
CMap::iterator compare_data_lb = compare_data.lower_bound("2");
|
|
|
|
// Check that both return the same return results
|
|
CHECK(data_lb->first == compare_data_lb->first);
|
|
CHECK(data_lb->second == compare_data_lb->second);
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.first->second == compare_result.first->second);
|
|
CHECK(data_result.second->first == compare_result.second->first);
|
|
CHECK(data_result.second->second == compare_result.second->second);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_equal_range)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
ETL_OR_STD::pair<Data::const_iterator, Data::const_iterator> data_result = data.equal_range("2");
|
|
ETL_OR_STD::pair<Compare_Data::const_iterator, Compare_Data::const_iterator> compare_result = compare_data.equal_range("2");
|
|
|
|
// Check that both return the same return results
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.first->second == compare_result.first->second);
|
|
CHECK(data_result.second->first == compare_result.second->first);
|
|
CHECK(data_result.second->second == compare_result.second->second);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_equal_range_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
const CMap compare_data(random_data.begin(), random_data.end());
|
|
const EMap data(random_data.begin(), random_data.end());
|
|
|
|
ETL_OR_STD::pair<EMap::const_iterator, EMap::const_iterator> data_result = data.equal_range(Key("2"));
|
|
EMap::const_iterator data_lb = data.lower_bound("2");
|
|
ETL_OR_STD::pair<CMap::const_iterator, CMap::const_iterator> compare_result = compare_data.equal_range("2");
|
|
CMap::const_iterator compare_data_lb = compare_data.lower_bound("2");
|
|
|
|
// Check that both return the same return results
|
|
CHECK(data_lb->first == compare_data_lb->first);
|
|
CHECK(data_lb->second == compare_data_lb->second);
|
|
CHECK(data_result.first->first == compare_result.first->first);
|
|
CHECK(data_result.first->second == compare_result.first->second);
|
|
CHECK(data_result.second->first == compare_result.second->first);
|
|
CHECK(data_result.second->second == compare_result.second->second);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_value)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
compare_data.erase("5");
|
|
data.erase("5");
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_value_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
CMap compare_data(initial_data.begin(), initial_data.end());
|
|
EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
compare_data.erase("5");
|
|
data.erase(Key("5"));
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::iterator i_compare = compare_data.begin();
|
|
Data::iterator i_data = data.begin();
|
|
|
|
std::advance(i_compare, 2);
|
|
std::advance(i_data, 2);
|
|
|
|
Compare_Data::iterator i_compare1 = compare_data.erase(i_compare);
|
|
Data::iterator i_data1 = data.erase(i_data);
|
|
|
|
CHECK(i_compare1->second == i_data1->second);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_erase_single)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::const_iterator i_compare = compare_data.cbegin();
|
|
Data::const_iterator i_data = data.cbegin();
|
|
|
|
std::advance(i_compare, 2);
|
|
std::advance(i_data, 2);
|
|
|
|
Compare_Data::const_iterator i_compare1 = compare_data.erase(i_compare);
|
|
Data::const_iterator i_data1 = data.erase(i_data);
|
|
|
|
CHECK(i_compare1->second == i_data1->second);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_range)
|
|
{
|
|
Compare_Data compare_data(random_data.begin(), random_data.end());
|
|
Data data(random_data.begin(), random_data.end());
|
|
|
|
Compare_Data::iterator i_compare = compare_data.begin();
|
|
Data::iterator i_data = data.begin();
|
|
|
|
Compare_Data::iterator i_compare_end = compare_data.begin();
|
|
Data::iterator i_data_end = data.begin();
|
|
|
|
std::advance(i_compare, 2);
|
|
std::advance(i_data, 2);
|
|
|
|
std::advance(i_compare_end, 4);
|
|
std::advance(i_data_end, 4);
|
|
|
|
compare_data.erase(i_compare, i_compare_end);
|
|
data.erase(i_data, i_data_end);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_erase_range)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::const_iterator i_compare = compare_data.cbegin();
|
|
Data::const_iterator i_data = data.cbegin();
|
|
|
|
Compare_Data::const_iterator i_compare_end = compare_data.cbegin();
|
|
Data::const_iterator i_data_end = data.cbegin();
|
|
|
|
std::advance(i_compare, 2);
|
|
std::advance(i_data, 2);
|
|
|
|
std::advance(i_compare_end, 6);
|
|
std::advance(i_data_end, 6);
|
|
|
|
compare_data.erase(i_compare, i_compare_end);
|
|
data.erase(i_data, i_data_end);
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
CHECK(isEqual);
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_clear)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
data.clear();
|
|
|
|
CHECK(data.size() == 0UL);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_count)
|
|
{
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.count("3") == 1UL);
|
|
|
|
CHECK(data.count("A") == 0UL);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_count_using_transparent_comparator)
|
|
{
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
const EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.count(Key("3")) == 1UL);
|
|
|
|
CHECK(data.count(Key("A")) == 0UL);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_reverse_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.rbegin(), data.rend(), compare_data.rbegin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool isEqual = Check_Equal(data.crbegin(), data.crend(), compare_data.crbegin());
|
|
|
|
CHECK(isEqual);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_find)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Data::iterator it = data.find("3");
|
|
CHECK(data.end() != it && 3 == it->second);
|
|
|
|
it = data.find("A");
|
|
CHECK(data.end() == it);
|
|
|
|
it = data.find("!");
|
|
CHECK(data.end() == it);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_find_using_transparent_comparator)
|
|
{
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
EMap::iterator it = data.find(Key("3"));
|
|
CHECK(data.end() != it && 3 == it->second);
|
|
|
|
it = data.find(Key("A"));
|
|
CHECK(data.end() == it);
|
|
|
|
it = data.find(Key("!"));
|
|
CHECK(data.end() == it);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_find_const)
|
|
{
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Data::const_iterator it = data.find("3");
|
|
CHECK(data.end() != it && 3 == it->second);
|
|
|
|
it = data.find("A");
|
|
CHECK(data.end() == it);
|
|
|
|
it = data.find("!");
|
|
CHECK(data.end() == it);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_find_const_using_transparent_comparator)
|
|
{
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
const EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
EMap::const_iterator it = data.find(Key("3"));
|
|
CHECK(data.end() != it && 3 == it->second);
|
|
|
|
it = data.find(Key("A"));
|
|
CHECK(data.end() == it);
|
|
|
|
it = data.find(Key("!"));
|
|
CHECK(data.end() == it);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_equal)
|
|
{
|
|
const Data initial1(initial_data.begin(), initial_data.end());
|
|
const Data initial2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(initial1 == initial2);
|
|
|
|
const Data different(different_data.begin(), different_data.end());
|
|
|
|
CHECK(!(initial1 == different));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_not_equal)
|
|
{
|
|
const Data initial1(initial_data.begin(), initial_data.end());
|
|
const Data initial2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(!(initial1 != initial2));
|
|
|
|
const Data different(different_data.begin(), different_data.end());
|
|
|
|
CHECK(initial1 != different);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_lower_bound)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::iterator i_compare = compare_data.lower_bound("8");
|
|
Data::iterator i_data = data.lower_bound("8");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
#ifdef TEST_GREATER_THAN
|
|
i_compare = compare_data.lower_bound(".");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.lower_bound(".");
|
|
CHECK(data.end() == i_data);
|
|
|
|
i_compare = compare_data.lower_bound("A");
|
|
i_data = data.lower_bound("A");
|
|
CHECK(i_compare->second == i_data->second);
|
|
#else
|
|
i_compare = compare_data.lower_bound(".");
|
|
i_data = data.lower_bound(".");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.lower_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.lower_bound("A");
|
|
CHECK(data.end() == i_data);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_lower_bound_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
CMap compare_data(initial_data.begin(), initial_data.end());
|
|
EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CMap::iterator i_compare = compare_data.lower_bound("8");
|
|
EMap::iterator i_data = data.lower_bound(Key("8"));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.lower_bound(".");
|
|
i_data = data.lower_bound(Key("."));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.lower_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.lower_bound(Key("A"));
|
|
CHECK(data.end() == i_data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_lower_bound_const)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::const_iterator i_compare = compare_data.lower_bound("4");
|
|
Data::const_iterator i_data = data.lower_bound("4");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
#ifdef TEST_GREATER_THAN
|
|
i_compare = compare_data.lower_bound(".");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.lower_bound(".");
|
|
CHECK(data.end() == i_data);
|
|
|
|
i_compare = compare_data.lower_bound("A");
|
|
i_data = data.lower_bound("A");
|
|
CHECK(i_compare->second == i_data->second);
|
|
#else
|
|
i_compare = compare_data.lower_bound(".");
|
|
i_data = data.lower_bound(".");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.lower_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.lower_bound("A");
|
|
CHECK(data.end() == i_data);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_lower_bound_const_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
const CMap compare_data(initial_data.begin(), initial_data.end());
|
|
const EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CMap::const_iterator i_compare = compare_data.lower_bound("8");
|
|
EMap::const_iterator i_data = data.lower_bound(Key("8"));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.lower_bound(".");
|
|
i_data = data.lower_bound(Key("."));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.lower_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.lower_bound(Key("A"));
|
|
CHECK(data.end() == i_data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_upper_bound)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::iterator i_compare = compare_data.upper_bound("2");
|
|
Data::iterator i_data = data.upper_bound("2");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
#ifdef TEST_GREATER_THAN
|
|
i_compare = compare_data.upper_bound(".");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.upper_bound(".");
|
|
CHECK(data.end() == i_data);
|
|
|
|
i_compare = compare_data.upper_bound("A");
|
|
i_data = data.upper_bound("A");
|
|
CHECK(i_compare->second == i_data->second);
|
|
#else
|
|
i_compare = compare_data.upper_bound(".");
|
|
i_data = data.upper_bound(".");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.upper_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.upper_bound("A");
|
|
CHECK(data.end() == i_data);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_upper_bound_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
CMap compare_data(initial_data.begin(), initial_data.end());
|
|
EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CMap::iterator i_compare = compare_data.upper_bound("2");
|
|
EMap::iterator i_data = data.upper_bound(Key("2"));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.upper_bound(".");
|
|
i_data = data.upper_bound(Key("."));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.upper_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.upper_bound(Key("A"));
|
|
CHECK(data.end() == i_data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_upper_bound_const)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::const_iterator i_compare = compare_data.upper_bound("7");
|
|
Data::const_iterator i_data = data.upper_bound("7");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
#ifdef TEST_GREATER_THAN
|
|
i_compare = compare_data.upper_bound(".");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.upper_bound(".");
|
|
CHECK(data.end() == i_data);
|
|
|
|
i_compare = compare_data.upper_bound("A");
|
|
i_data = data.upper_bound("A");
|
|
CHECK(i_compare->second == i_data->second);
|
|
#else
|
|
i_compare = compare_data.upper_bound(".");
|
|
i_data = data.upper_bound(".");
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.upper_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.upper_bound("A");
|
|
CHECK(data.end() == i_data);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_upper_bound_const_using_transparent_comparator)
|
|
{
|
|
using CMap = std::map<std::string, int, std::less<std::string>>;
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
|
|
const CMap compare_data(initial_data.begin(), initial_data.end());
|
|
const EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
CMap::const_iterator i_compare = compare_data.upper_bound("2");
|
|
EMap::const_iterator i_data = data.upper_bound(Key("2"));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.upper_bound(".");
|
|
i_data = data.upper_bound(Key("."));
|
|
CHECK(i_compare->second == i_data->second);
|
|
|
|
i_compare = compare_data.upper_bound("A");
|
|
CHECK(compare_data.end() == i_compare);
|
|
|
|
i_data = data.upper_bound(Key("A"));
|
|
CHECK(data.end() == i_data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_key_compare)
|
|
{
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Data::key_compare compare = data.key_comp();
|
|
|
|
Data::key_type a("A");
|
|
Data::key_type b("B");
|
|
|
|
#ifdef TEST_GREATER_THAN
|
|
CHECK(!compare(a, b));
|
|
CHECK(compare(b, a));
|
|
#else
|
|
CHECK(compare(a, b));
|
|
CHECK(!compare(b, a));
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_key_compare_using_transparent_comparator)
|
|
{
|
|
using EMap = etl::map<std::string, int, MAX_SIZE, etl::less<>>;
|
|
const EMap data(initial_data.begin(), initial_data.end());
|
|
|
|
EMap::key_compare compare = data.key_comp();
|
|
|
|
std::string a("A");
|
|
Key b("B");
|
|
|
|
CHECK(compare(a, b));
|
|
CHECK(!compare(b, a));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_value_compare)
|
|
{
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Data::value_compare compare = data.value_comp();
|
|
|
|
Data::value_type a(std::string("A"), 0);
|
|
Data::value_type b(std::string("B"), 1);
|
|
|
|
#ifdef TEST_GREATER_THAN
|
|
CHECK(!compare(a, b));
|
|
CHECK(compare(b, a));
|
|
#else
|
|
CHECK(compare(a, b));
|
|
CHECK(!compare(b, a));
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_compare_lower_upper_bound)
|
|
{
|
|
Data data(initial_data_even.begin(), initial_data_even.end());
|
|
Compare_Data compare(initial_data_even.begin(), initial_data_even.end());
|
|
|
|
std::vector<ETL_OR_STD::pair<std::string, int> > tab(test_data.begin(), test_data.end());
|
|
|
|
// make sure both data and compare contain same elements
|
|
std::vector<ETL_OR_STD::pair<std::string, int> > data_elements(data.begin(), data.end());
|
|
std::vector<ETL_OR_STD::pair<std::string, int> > compare_data_elements(compare.begin(), compare.end());
|
|
|
|
CHECK(data_elements == compare_data_elements);
|
|
CHECK(data_elements.size() == MAX_SIZE);
|
|
|
|
for (std::vector<ETL_OR_STD::pair<std::string, int> >::iterator it = tab.begin(); it != tab.end(); ++it)
|
|
{
|
|
std::string i = it->first;
|
|
|
|
// lower_bound
|
|
CHECK((compare.lower_bound(i) == compare.end()) == (data.lower_bound(i) == data.end()));
|
|
// if both end, or none
|
|
if ((compare.lower_bound(i) == compare.end()) == (data.lower_bound(i) == data.end()))
|
|
{
|
|
// if both are not end
|
|
if (compare.lower_bound(i) != compare.end())
|
|
{
|
|
CHECK((*compare.lower_bound(i)) == (*data.lower_bound(i)));
|
|
}
|
|
|
|
ETL_OR_STD::pair<Compare_Data::const_iterator, Compare_Data::const_iterator> stlret = compare.equal_range(i);
|
|
ETL_OR_STD::pair<Data::const_iterator, Data::const_iterator> etlret = data.equal_range(i);
|
|
|
|
CHECK((stlret.first == compare.end()) == (etlret.first == data.end()));
|
|
if ((stlret.first != compare.end()) && (etlret.first != data.end()))
|
|
{
|
|
CHECK((*stlret.first) == (*etlret.first));
|
|
}
|
|
CHECK((stlret.second == compare.end()) == (etlret.second == data.end()));
|
|
if ((stlret.second != compare.end()) && (etlret.second != data.end()))
|
|
{
|
|
CHECK((*stlret.second) == (*etlret.second));
|
|
}
|
|
}
|
|
|
|
// upper_bound
|
|
CHECK((compare.upper_bound(i) == compare.end()) == (data.upper_bound(i) == data.end()));
|
|
// if both end, or none
|
|
if ((compare.upper_bound(i) == compare.end()) == (data.upper_bound(i) == data.end()))
|
|
{
|
|
// if both are not end
|
|
if (compare.upper_bound(i) != compare.end())
|
|
{
|
|
CHECK((*compare.upper_bound(i)) == (*data.upper_bound(i)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
|
TEST_FIXTURE(SetupFixture, test_map_template_deduction)
|
|
{
|
|
using Pair = std::pair<const std::string, int>;
|
|
|
|
#include "etl/private/diagnostic_null_dereference_push.h"
|
|
etl::map data{Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5}};
|
|
|
|
auto v = *data.begin();
|
|
using Type = decltype(v);
|
|
CHECK((std::is_same_v<Pair, Type>));
|
|
|
|
CHECK_EQUAL(0, data.at("0"));
|
|
CHECK_EQUAL(1, data.at("1"));
|
|
CHECK_EQUAL(2, data.at("2"));
|
|
CHECK_EQUAL(3, data.at("3"));
|
|
CHECK_EQUAL(4, data.at("4"));
|
|
CHECK_EQUAL(5, data.at("5"));
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
TEST_FIXTURE(SetupFixture, test_make_map)
|
|
{
|
|
using Pair = ETL_OR_STD::pair<const std::string, int>;
|
|
|
|
#include "etl/private/diagnostic_null_dereference_push.h"
|
|
auto data = etl::make_map<const std::string, int, std::less<std::string>>(Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4},
|
|
Pair{"5", 5});
|
|
|
|
auto v = *data.begin();
|
|
using Type = decltype(v);
|
|
CHECK((std::is_same<Pair, Type>::value));
|
|
|
|
CHECK_EQUAL(0, data.at("0"));
|
|
CHECK_EQUAL(1, data.at("1"));
|
|
CHECK_EQUAL(2, data.at("2"));
|
|
CHECK_EQUAL(3, data.at("3"));
|
|
CHECK_EQUAL(4, data.at("4"));
|
|
CHECK_EQUAL(5, data.at("5"));
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_contains)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.contains(std::string("1")));
|
|
CHECK(!data.contains(std::string("99")));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_contains_with_transparent_comparator)
|
|
{
|
|
etl::map<std::string, int, MAX_SIZE, etl::less<>> data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.contains(std::string("1")));
|
|
CHECK(data.contains(Key("1")));
|
|
|
|
CHECK(!data.contains(std::string("99")));
|
|
CHECK(!data.contains(Key("99")));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_if_issue_1298_multiset_iterator_invalidation_during_erase_is_also_in_map)
|
|
{
|
|
using element = std::pair<int, int>;
|
|
|
|
std::vector<element> permutation{{1, 11}, {2, 12}, {3, 13}, {4, 14}};
|
|
const std::vector<element> expected{{1, 11}, {3, 13}, {4, 14}};
|
|
|
|
do {
|
|
etl::map<int, int, 8> data;
|
|
|
|
for (auto i : permutation)
|
|
{
|
|
data.insert(i);
|
|
}
|
|
|
|
auto it = data.find(2);
|
|
data.erase(it);
|
|
|
|
const std::vector<element> actual(data.begin(), data.end());
|
|
|
|
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
|
CHECK_EQUAL(expected.size(), actual.size());
|
|
CHECK_TRUE(actual == expected);
|
|
|
|
} while (std::next_permutation(permutation.begin(), permutation.end()));
|
|
}
|
|
}
|
|
} // namespace
|