mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
ivector swap (#1256)
* Etl vector swap implementation * Implement swap function overload * Fix nitpicks * Add size check * Remove unnessecary etl swap overloads * Use swap_range and move range --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
parent
6d6ecc9fb5
commit
3206ac9feb
@ -467,6 +467,31 @@ namespace etl
|
||||
return iterator(base_t::erase(base_t::const_iterator(first), base_t::const_iterator(last)));
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Swap contents with another vector. Performs operation on each individual element.
|
||||
///\param other The other vector to swap with.
|
||||
//*********************************************************************
|
||||
void swap(ivector<T*>& other)
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ETL_ASSERT_OR_RETURN(this->max_size() >= other.size() && other.max_size() >= this->size(), ETL_ERROR(vector_full));
|
||||
|
||||
ivector<T*>& smaller = other.size() > this->size() ? *this : other;
|
||||
ivector<T*>& larger = other.size() > this->size() ? other : *this;
|
||||
|
||||
ETL_OR_STD::swap_ranges(smaller.begin(), smaller.end(), larger.begin());
|
||||
|
||||
typename ivector<T*>::iterator larger_itr = etl::next(larger.begin(), smaller.size());
|
||||
|
||||
etl::move(larger_itr, larger.end(), etl::back_inserter(smaller));
|
||||
|
||||
larger.erase(larger_itr, larger.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
@ -890,6 +915,31 @@ namespace etl
|
||||
return iterator(base_t::erase(base_t::iterator(first), base_t::iterator(last)));
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Swap contents with another vector. Performs operation on each individual element.
|
||||
///\param other The other vector to swap with.
|
||||
//*********************************************************************
|
||||
void swap(ivector<const T*>& other)
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ETL_ASSERT_OR_RETURN(this->max_size() >= other.size() && other.max_size() >= this->size(), ETL_ERROR(vector_full));
|
||||
|
||||
ivector<const T*>& smaller = other.size() > this->size() ? *this : other;
|
||||
ivector<const T*>& larger = other.size() > this->size() ? other : *this;
|
||||
|
||||
ETL_OR_STD::swap_ranges(smaller.begin(), smaller.end(), larger.begin());
|
||||
|
||||
typename ivector<const T*>::iterator larger_itr = etl::next(larger.begin(), smaller.size());
|
||||
|
||||
etl::move(larger_itr, larger.end(), etl::back_inserter(smaller));
|
||||
|
||||
larger.erase(larger_itr, larger.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
|
||||
@ -947,6 +947,31 @@ namespace etl
|
||||
return first_;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Swap contents with another vector. Performs operation on each individual element.
|
||||
///\param other The other vector to swap with.
|
||||
//*********************************************************************
|
||||
void swap(ivector<T>& other)
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ETL_ASSERT_OR_RETURN(this->max_size() >= other.size() && other.max_size() >= this->size(), ETL_ERROR(vector_full));
|
||||
|
||||
ivector<T>& smaller = other.size() > this->size() ? *this : other;
|
||||
ivector<T>& larger = other.size() > this->size() ? other : *this;
|
||||
|
||||
ETL_OR_STD::swap_ranges(smaller.begin(), smaller.end(), larger.begin());
|
||||
|
||||
typename ivector<T>::iterator larger_itr = etl::next(larger.begin(), smaller.size());
|
||||
|
||||
etl::move(larger_itr, larger.end(), etl::back_inserter(smaller));
|
||||
|
||||
larger.erase(larger_itr, larger.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assignment operator.
|
||||
//*************************************************************************
|
||||
@ -1863,6 +1888,17 @@ namespace etl
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Overloaded swap for etl::ivector<T>
|
||||
///\param lhs The first vector to swap with.
|
||||
///\param rhs The second vector to swap with.
|
||||
//*********************************************************************
|
||||
template<typename T>
|
||||
void swap(ivector<T>& lhs, ivector<T>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -52,6 +52,8 @@ namespace
|
||||
Compare_Data different_data;
|
||||
Compare_Data insert_data;
|
||||
Compare_Data blank_data;
|
||||
Compare_Data swap_data;
|
||||
Compare_Data swap_other_data;
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
@ -63,6 +65,8 @@ namespace
|
||||
int n_less[] = { 0, 1, 2, 3, 3, 5, 6, 7, 8, 9 };
|
||||
int n_greater[] = { 0, 1, 2, 4, 4, 5, 6, 7, 8, 9 };
|
||||
int n_blank[] = { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 };
|
||||
int n_swap[] = { 0, 1, 2, 3, 4, 5 };
|
||||
int n_swap_other[] = { 6, 7, 8, 9 };
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
||||
@ -71,6 +75,8 @@ namespace
|
||||
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
||||
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
||||
blank_data.assign(std::begin(n_blank), std::end(n_blank));
|
||||
swap_data.assign(std::begin(n_swap), std::end(n_swap));
|
||||
swap_other_data.assign(std::begin(n_swap_other), std::end(n_swap_other));
|
||||
}
|
||||
};
|
||||
|
||||
@ -1620,5 +1626,113 @@ namespace
|
||||
|
||||
CHECK(std::equal(blank_data.begin(), blank_data.end(), data.begin()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_same_capacity)
|
||||
{
|
||||
Data etl_data(swap_data.begin(), swap_data.end());
|
||||
Data etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<int, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_insufficient_capacity)
|
||||
{
|
||||
etl::vector<int, 4> etl_data(4);
|
||||
etl::vector<int, 6> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_etl_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<int, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl::swap(etl_data, etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl::swap(etl_data, etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +58,8 @@ namespace
|
||||
Compare_Data shorter_data;
|
||||
Compare_Data different_data;
|
||||
Compare_Data insert_data;
|
||||
Compare_Data swap_data;
|
||||
Compare_Data swap_other_data;
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
@ -68,6 +70,8 @@ namespace
|
||||
int n_insert[] = { 11, 12, 13 };
|
||||
int n_less[] = { 0, 1, 2, 3, 3, 5, 6, 7, 8, 9 };
|
||||
int n_greater[] = { 0, 1, 2, 4, 4, 5, 6, 7, 8, 9 };
|
||||
int n_swap[] = { 0, 1, 2, 3, 4, 5 };
|
||||
int n_swap_other[] = { 6, 7, 8, 9 };
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
||||
@ -75,6 +79,8 @@ namespace
|
||||
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
||||
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
||||
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
||||
swap_data.assign(std::begin(n_swap), std::end(n_swap));
|
||||
swap_other_data.assign(std::begin(n_swap_other), std::end(n_swap_other));
|
||||
|
||||
std::fill_n(buffer1, SIZE, -1);
|
||||
std::fill_n(buffer2, SIZE, -1);
|
||||
@ -1320,5 +1326,113 @@ namespace
|
||||
CHECK_EQUAL(raw[4].i, dest[6].i);
|
||||
CHECK_EQUAL(raw[5].i, dest[7].i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_same_capacity)
|
||||
{
|
||||
Data etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
Data etl_data2(swap_other_data.begin(), swap_other_data.end(), buffer2, SIZE);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
Data etl_data2(swap_other_data.begin(), swap_other_data.end(), buffer2, other_size);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_insufficient_capacity)
|
||||
{
|
||||
Data etl_data(4, buffer1, 4);
|
||||
etl::vector<int, SIZE> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_between_internal_and_external)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
etl::vector<int, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +62,8 @@ namespace
|
||||
CompareDataNDC shorter_data;
|
||||
CompareDataNDC different_data;
|
||||
CompareDataNDC insert_data;
|
||||
CompareDataNDC swap_data;
|
||||
CompareDataNDC swap_other_data;
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
@ -72,6 +74,8 @@ namespace
|
||||
NDC n_insert[] = { NDC("11"), NDC("12"), NDC("13") };
|
||||
NDC n_less[] = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("3"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") };
|
||||
NDC n_greater[] = { NDC("0"), NDC("1"), NDC("2"), NDC("4"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") };
|
||||
NDC n_swap[] = { NDC("0"), NDC("1"), NDC("2"), NDC("4"), NDC("4"), NDC("5") };
|
||||
NDC n_swap_other[] = { NDC("6"), NDC("7"), NDC("8"), NDC("9") };
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
||||
@ -79,6 +83,8 @@ namespace
|
||||
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
||||
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
||||
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
||||
swap_data.assign(std::begin(n_swap), std::end(n_swap));
|
||||
swap_other_data.assign(std::begin(n_swap_other), std::end(n_swap_other));
|
||||
}
|
||||
};
|
||||
|
||||
@ -1407,5 +1413,80 @@ namespace
|
||||
const DataNDC initial2(initial_data.begin(), initial_data.end());
|
||||
CHECK((initial >= initial2) == (initial_data >= initial_data));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_same_capacity)
|
||||
{
|
||||
DataNDC etl_data(swap_data.begin(), swap_data.end());
|
||||
DataNDC etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
DataNDC etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<NDC, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_insufficient_capacity)
|
||||
{
|
||||
etl::vector<DC, 4> etl_data(4);
|
||||
etl::vector<DC, 6> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +54,8 @@ namespace
|
||||
Compare_Data shorter_data;
|
||||
Compare_Data different_data;
|
||||
Compare_Data insert_data;
|
||||
Compare_Data swap_data;
|
||||
Compare_Data swap_other_data;
|
||||
|
||||
int n0 = 0;
|
||||
int n1 = 1;
|
||||
@ -78,6 +80,8 @@ namespace
|
||||
int* n_insert[] = { &n11, &n12, &n13 };
|
||||
int* n_less[] = { &n0, &n1, &n2, &n3, &n3, &n5, &n6, &n7, &n8, &n9 };
|
||||
int* n_greater[] = { &n0, &n1, &n2, &n4, &n4, &n5, &n6, &n7, &n8, &n9 };
|
||||
int* n_swap[] = { &n0, &n1, &n2, &n3, &n4, &n5 };
|
||||
int* n_swap_other[] = { &n6, &n7, &n8, &n9 };
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
||||
@ -85,6 +89,8 @@ namespace
|
||||
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
||||
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
||||
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
||||
swap_data.assign(std::begin(n_swap), std::end(n_swap));
|
||||
swap_other_data.assign(std::begin(n_swap_other), std::end(n_swap_other));
|
||||
}
|
||||
};
|
||||
|
||||
@ -2199,5 +2205,221 @@ namespace
|
||||
CHECK_EQUAL(9, *data[9]);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_same_capacity)
|
||||
{
|
||||
Data etl_data(swap_data.begin(), swap_data.end());
|
||||
Data etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_const_same_capacity)
|
||||
{
|
||||
CData etl_data(swap_data.begin(), swap_data.end());
|
||||
CData etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<int*, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_const_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
CData etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<const int*, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_insufficient_capacity)
|
||||
{
|
||||
etl::vector<int*, 4> etl_data(4);
|
||||
etl::vector<int*, 6> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_const_insufficient_capacity)
|
||||
{
|
||||
etl::vector<const int*, 4> etl_data(4);
|
||||
etl::vector<const int*, 6> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_etl_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<int*, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl::swap(etl_data, etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl::swap(etl_data, etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_etl_swap_const_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
CData etl_data(swap_data.begin(), swap_data.end());
|
||||
etl::vector<const int*, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl::swap(etl_data, etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl::swap(etl_data, etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +62,8 @@ namespace
|
||||
Compare_Data shorter_data;
|
||||
Compare_Data different_data;
|
||||
Compare_Data insert_data;
|
||||
Compare_Data swap_data;
|
||||
Compare_Data swap_other_data;
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
@ -87,6 +89,8 @@ namespace
|
||||
int* n_insert[] = { &n11, &n12, &n13 };
|
||||
int* n_less[] = { &n0, &n1, &n2, &n3, &n3, &n5, &n6, &n7, &n8, &n9 };
|
||||
int* n_greater[] = { &n0, &n1, &n2, &n4, &n4, &n5, &n6, &n7, &n8, &n9 };
|
||||
int* n_swap[] = { &n0, &n1, &n2, &n3, &n4, &n5 };
|
||||
int* n_swap_other[] = { &n6, &n7, &n8, &n9 };
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
||||
@ -94,6 +98,8 @@ namespace
|
||||
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
||||
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
||||
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
||||
swap_data.assign(std::begin(n_swap), std::end(n_swap));
|
||||
swap_other_data.assign(std::begin(n_swap_other), std::end(n_swap_other));
|
||||
|
||||
std::fill_n(buffer1, SIZE, nullptr);
|
||||
std::fill_n(buffer2, SIZE, nullptr);
|
||||
@ -2013,5 +2019,222 @@ namespace
|
||||
CHECK(i1 == *i2);
|
||||
CHECK(&i1 == i2);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_same_capacity)
|
||||
{
|
||||
Data etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
Data etl_data2(swap_other_data.begin(), swap_other_data.end(), buffer2, SIZE);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_const_same_capacity)
|
||||
{
|
||||
CData etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
CData etl_data2(swap_other_data.begin(), swap_other_data.end(), buffer2, SIZE);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
Data etl_data2(swap_other_data.begin(), swap_other_data.end(), buffer2, other_size);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_const_different_capacity)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
CData etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
CData etl_data2(swap_other_data.begin(), swap_other_data.end(), buffer2, other_size);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_insufficient_capacity)
|
||||
{
|
||||
Data etl_data(4, buffer1, 4);
|
||||
etl::vector<int*, SIZE> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_swap_const_insufficient_capacity)
|
||||
{
|
||||
CData etl_data(4, buffer1, 4);
|
||||
etl::vector<const int*, SIZE> etl_data2(6);
|
||||
|
||||
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
||||
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_between_internal_and_external)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
Data etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
etl::vector<int*, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_swap_const_between_internal_and_external)
|
||||
{
|
||||
const size_t other_size = 6;
|
||||
CData etl_data(swap_data.begin(), swap_data.end(), buffer1, SIZE);
|
||||
etl::vector<const int*, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_other_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
|
||||
etl_data.swap(etl_data2);
|
||||
|
||||
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
||||
CHECK(etl_data.size() == swap_data.size());
|
||||
CHECK(etl_data.max_size() == SIZE);
|
||||
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
||||
CHECK(etl_data2.size() == swap_other_data.size());
|
||||
CHECK(etl_data2.max_size() == other_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user