aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_cow_iterator_01.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-01-09 14:05:07 +0100
committerSven Gothel <[email protected]>2021-01-09 14:05:07 +0100
commit325157a4eb7a2cdc6f502618a606c720847a8b28 (patch)
tree163bfe3caeac8b9a85912ea48ba8ca7e7887f582 /test/test_cow_iterator_01.cpp
parent9a1e8911a2a6ae52f5b9695ba9f24d44965adfec (diff)
test_cow_iterator_01.cpp: Use uint64_t and compare each mutation with ad-hock initializer list; Cleanup type names etc
Diffstat (limited to 'test/test_cow_iterator_01.cpp')
-rw-r--r--test/test_cow_iterator_01.cpp830
1 files changed, 474 insertions, 356 deletions
diff --git a/test/test_cow_iterator_01.cpp b/test/test_cow_iterator_01.cpp
index 5b97a52..d79406c 100644
--- a/test/test_cow_iterator_01.cpp
+++ b/test/test_cow_iterator_01.cpp
@@ -34,8 +34,6 @@
#include <catch2/catch_amalgamated.hpp>
#include <jau/test/catch2_ext.hpp>
-#include "test_datatype01.hpp"
-
#include <jau/basic_algos.hpp>
#include <jau/basic_types.hpp>
#include <jau/darray.hpp>
@@ -54,65 +52,40 @@
*/
using namespace jau;
-static uint8_t start_addr_b[] = {0x20, 0x26, 0x2A, 0x01, 0x20, 0x10};
-static Addr48Bit start_addr(start_addr_b);
-
-typedef std::vector<DataType01, counting_allocator<DataType01>> std_vector_DataType01;
-typedef jau::darray<DataType01, counting_callocator<DataType01>> jau_darray_DataType01;
-typedef jau::cow_vector<DataType01, counting_allocator<DataType01>> jau_cow_vector_DataType01;
-typedef jau::cow_darray<DataType01, counting_callocator<DataType01>> jau_cow_darray_DataType01;
+typedef std::vector<uint64_t, counting_allocator<uint64_t>> std_vector_uint64_t;
+typedef jau::darray<uint64_t, counting_callocator<uint64_t>> jau_darray_uint64_t;
+typedef jau::cow_vector<uint64_t, counting_allocator<uint64_t>> jau_cow_vector_uint64_t;
+typedef jau::cow_darray<uint64_t, counting_callocator<uint64_t>> jau_cow_darray_uint64_t;
-JAU_TYPENAME_CUE_ALL(std_vector_DataType01)
-JAU_TYPENAME_CUE_ALL(jau_darray_DataType01)
-JAU_TYPENAME_CUE_ALL(jau_cow_vector_DataType01)
-JAU_TYPENAME_CUE_ALL(jau_cow_darray_DataType01)
+JAU_TYPENAME_CUE_ALL(std_vector_uint64_t)
+JAU_TYPENAME_CUE_ALL(jau_darray_uint64_t)
+JAU_TYPENAME_CUE_ALL(jau_cow_vector_uint64_t)
+JAU_TYPENAME_CUE_ALL(jau_cow_darray_uint64_t)
template<class T>
-static int test_00_list_itr(T& data, const bool show) {
- Addr48Bit a0(start_addr);
- int some_number = 0, i=0; // add some validated work, avoiding any 'optimization away'
- jau::for_each_const(data, [&some_number, &a0, &i, show](const DataType01 & e) {
- some_number += e.nop();
- if( show ) {
- printf("data[%d]: %s\n", i, e.toString().c_str());
- }
- REQUIRE( a0.next() );
- REQUIRE(e.address == a0);
- ++i;
+static void print_list(T& data) {
+ printf("list: %d { ", (int)data.size());
+ jau::for_each_const(data, [](const uint64_t & e) {
+ printf("%s, ", uint64DecString(e, ',', 2).c_str());
} );
- REQUIRE(some_number > 0);
- return some_number;
+ printf("}\n");
}
template<class T>
-static void test_00_seq_find_itr(T& data) {
- Addr48Bit a0(start_addr);
- const std::size_t size = data.size();
- std::size_t fi = 0, i=0;
-
- for(; i<size && a0.next(); i++) {
- DataType01 elem(a0, static_cast<uint8_t>(1));
- const DataType01 *found = jau::find_const(data, elem);
- if( nullptr != found ) {
- fi++;
- found->nop();
- }
- }
- REQUIRE(fi == i);
+static void print_list(const std::string& pre, T& data) {
+ printf("%s: %d { ", pre.c_str(), (int)data.size());
+ jau::for_each_const(data, [](const uint64_t & e) {
+ printf("%s, ", uint64DecString(e, ',', 2).c_str());
+ } );
+ printf("}\n");
}
template<class T>
-static void test_00_seq_fill(T& data, const std::size_t size) {
- Addr48Bit a0(start_addr);
+static void fill_list(T& data, const std::size_t size) {
std::size_t i=0;
- for(; i<size && a0.next(); i++) {
- data.emplace_back( a0, static_cast<uint8_t>(1) );
- }
- if( i != data.size() ) {
- test_00_list_itr(data, true);
- printf("a0 %s\n", a0.toString().c_str());
- printf("Size %zu, expected %zu, iter %zu\n", static_cast<std::size_t>(data.size()), size, i);
+ for(; i<size; i++) {
+ data.emplace_back( static_cast<uint64_t>(i+1) );
}
REQUIRE(i == data.size());
}
@@ -145,18 +118,20 @@ static void print_iterator_info(const std::string& typedefname,
template<class T>
static bool test_00_inspect_iterator_types(const std::string& type_id) {
- typedef typename T::size_type T_size_t;
- typedef typename T::difference_type T_difference_t;
+ typedef typename T::size_type size_type;
+ typedef typename T::iterator iter_type;
+ typedef typename T::difference_type diff_type;
+ typedef typename T::const_iterator citer_type;
printf("**** Type Info: %s\n", type_id.c_str());
jau::type_cue<T>::print("T");
jau::type_cue<typename T::value_type>::print("T::value_type");
- jau::type_cue<T_size_t>::print("T::size_type");
- jau::type_cue<T_difference_t>::print("T::difference_type");
+ jau::type_cue<size_type>::print("T::size_type");
+ jau::type_cue<diff_type>::print("T::difference_type");
jau::type_cue<typename T::reference>::print("T::reference");
jau::type_cue<typename T::pointer>::print("T::pointer");
- print_iterator_info<typename T::iterator>("T::iterator");
- print_iterator_info<typename T::const_iterator>("T::const_iterator");
+ print_iterator_info<iter_type>("T::iterator");
+ print_iterator_info<citer_type>("T::citer_type");
printf("\n\n");
return true;
@@ -204,8 +179,11 @@ static void test_iterator_compare(const typename T::size_type size,
const typename T::difference_type citer1_idx,
const typename T::difference_type citer2_idx)
{
- typename T::difference_type d_size = static_cast<typename T::difference_type>(size);
- typename T::difference_type distance = citer2_idx - citer1_idx;
+ typedef typename T::difference_type diff_type;
+
+ diff_type d_size = static_cast<diff_type>(size);
+ diff_type distance = citer2_idx - citer1_idx;
+
// iter op-(iter1, iter2)
REQUIRE( ( end - begin ) == d_size);
REQUIRE( ( citer2 - begin ) == citer2_idx);
@@ -221,8 +199,8 @@ static void test_iterator_compare(const typename T::size_type size,
// iter op+(iter, difference_type) and iter op==(iter1, iter2)
{
- typename T::difference_type d_citer1_end = end - citer1;
- typename T::difference_type d_citer2_end = end - citer2;
+ diff_type d_citer1_end = end - citer1;
+ diff_type d_citer2_end = end - citer2;
REQUIRE( ( citer1_idx + d_citer1_end ) == d_size); // validate op-(iter1, iter2)
REQUIRE( ( citer2_idx + d_citer2_end ) == d_size); // validate op-(iter1, iter2)
@@ -296,19 +274,11 @@ static void test_iterator_dereference(const typename T::size_type size,
REQUIRE( *(citer2+size-1) == *(end -1) );
REQUIRE( citer2[size-1] == end[-1] );
- REQUIRE( (citer2+0)->toString() == begin[0].toString() );
- REQUIRE( (citer2+1)->toString() == begin[1].toString() );
- REQUIRE( (citer2+2)->toString() == begin[2].toString() );
- REQUIRE( (citer2+3)->toString() == begin[3].toString() );
- REQUIRE( (citer2+size-1)->toString() == (end-1)->toString() );
-
-#if 0
- printf("[0]: %s == %s\n", (citer2+0)->toString().c_str(), begin[3].toString().c_str());
- printf("[1]: %s == %s\n", (citer2+1)->toString().c_str(), begin[3].toString().c_str());
- printf("[2]: %s == %s\n", (citer2+2)->toString().c_str(), begin[3].toString().c_str());
- printf("[3]: %s == %s\n", (citer2+3)->toString().c_str(), begin[3].toString().c_str());
- printf("[E]: %s == %s\n", (citer2+size-1)->toString().c_str(), (end-1)->toString().c_str());
-#endif
+ REQUIRE( *(citer2+0) == begin[0] );
+ REQUIRE( *(citer2+1) == begin[1] );
+ REQUIRE( *(citer2+2) == begin[2] );
+ REQUIRE( *(citer2+3) == begin[3] );
+ REQUIRE( *(citer2+size-1) == end[-1] );
test_iterator_compare<T, iterator_type>(size, begin, end, citer1, citer2, 0, 0);
}
@@ -320,7 +290,7 @@ static void test_iterator_arithmetic(const typename T::size_type size,
printf("**** test_iterator_arithmetic:\n");
print_iterator_info<iterator_type>("iterator_type");
- // const_iterator operations
+ // citer_type operations
// op++(), op--(), op++(int), op--(int),
// op+=(difference_type), op+(iter a, difference_type) ..
{
@@ -343,30 +313,25 @@ static void test_iterator_arithmetic(const typename T::size_type size,
// iter op--(int)
citer1--;
test_iterator_compare<T, iterator_type>(size, begin, end, citer1, citer2, 0, 0);
- REQUIRE( citer2->toString() == begin[0].toString() );
- // printf("[0]: %s == %s\n", citer2->toString().c_str(), begin[0].toString().c_str());
+ REQUIRE( *citer2 == begin[0] );
// iter op++(int)
citer2++;
test_iterator_compare<T, iterator_type>(size, begin, end, citer1, citer2, 0, 1);
REQUIRE( *citer2 == *(begin+1) ); // iter op*(), op+(iter, difference_type) and value_type ==
REQUIRE( *citer2 == begin[1] ); // iter op*(), op[](difference_type) and value_type ==
- REQUIRE( citer2->toString() == begin[1].toString() );
// iter op++(int)
citer2++;
test_iterator_compare<T, iterator_type>(size, begin, end, citer1, citer2, 0, 2);
REQUIRE( *citer2 == *(begin+2) ); // iter op*(), op+(iter, difference_type) and value_type ==
REQUIRE( *citer2 == begin[2] ); // iter op*(), op[](difference_type) and value_type ==
- REQUIRE( citer2->toString() == begin[2].toString() );
// iter op++(int)
citer2++;
test_iterator_compare<T, iterator_type>(size, begin, end, citer1, citer2, 0, 3);
REQUIRE( *citer2 == *(begin+3) ); // iter op*(), op+(iter, difference_type) and value_type ==
REQUIRE( *citer2 == begin[3] ); // iter op*(), op[](difference_type) and value_type ==
- REQUIRE( citer2->toString() == begin[3].toString() );
- // printf("[3]: %s == %s\n", citer2->toString().c_str(), begin[3].toString().c_str());
// iter op++()
--citer2;
@@ -375,8 +340,6 @@ static void test_iterator_arithmetic(const typename T::size_type size,
test_iterator_compare<T, iterator_type>(size, begin, end, citer1, citer2, 0, 0);
REQUIRE( *citer2 == *(begin+0) ); // iter op*(), op+(iter, difference_type) and value_type ==
REQUIRE( *citer2 == begin[0] ); // iter op*(), op[](difference_type) and value_type ==
- REQUIRE( citer2->toString() == begin[0].toString() );
- // printf("[3]: %s == %s\n", citer2->toString().c_str(), begin[3].toString().c_str());
// iter +=(diff)
citer2 += 3;
@@ -414,16 +377,23 @@ static void test_iterator_arithmetic(const typename T::size_type size,
}
template<class T>
-static bool test_const_iterator_ops(const std::string& type_id, T& data,
+static bool test_citer_type_ops(const std::string& type_id,
std::enable_if_t< is_cow_type<T>::value, bool> = true )
{
- printf("**** test_const_iterator_ops(CoW): %s\n", type_id.c_str());
+ typedef typename T::const_iterator citer_type;
+ typedef typename T::difference_type diff_type;
+ typedef typename T::const_iterator citer_type;
+
+ T data;
+ fill_list(data, 10);
+
+ printf("**** test_citer_type_ops(CoW): %s\n", type_id.c_str());
{
- typename T::const_iterator begin = data.cbegin(); // immutable new_store non-const iterator, gets held until destruction
- typename T::const_iterator end = begin.end(); // no new store iterator, on same store as begin, obtained from begin
- typename T::difference_type data_size = static_cast<typename T::difference_type>(data.size());
- typename T::difference_type begin_size = static_cast<typename T::difference_type>(begin.size());
- typename T::difference_type end_size = static_cast<typename T::difference_type>(end.size());
+ citer_type begin = data.cbegin(); // immutable new_store non-const iterator, gets held until destruction
+ citer_type end = begin.end(); // no new store iterator, on same store as begin, obtained from begin
+ diff_type data_size = static_cast<diff_type>(data.size());
+ diff_type begin_size = static_cast<diff_type>(begin.size());
+ diff_type end_size = static_cast<diff_type>(end.size());
REQUIRE( begin_size == data_size );
REQUIRE( end_size == data_size );
REQUIRE( end - begin == data_size );
@@ -431,34 +401,36 @@ static bool test_const_iterator_ops(const std::string& type_id, T& data,
REQUIRE( begin + begin_size == end );
REQUIRE( *( end - end_size ) == *begin );
REQUIRE( *( begin + begin_size ) == *end );
- test_iterator_dereference<T, typename T::const_iterator>(begin.size(), begin, end);
+ test_iterator_dereference<T, citer_type>(begin.size(), begin, end);
}
{
- typename T::const_iterator begin = data.cbegin(); // no new store const_iterator
- typename T::const_iterator end = begin.end(); // no new store const_iterator, on same store as begin, obtained from begin
- test_iterator_arithmetic<T, typename T::const_iterator>(data.size(), begin, end);
+ citer_type begin = data.cbegin(); // no new store citer_type
+ citer_type end = begin.end(); // no new store citer_type, on same store as begin, obtained from begin
+ test_iterator_arithmetic<T, citer_type>(data.size(), begin, end);
}
-#if 0
{
- // INTENIONAL FAILURES, checking behavior of error values etc
- typename T::const_iterator begin = data.cbegin(); // no new store const_iterator
- typename T::const_iterator iter = begin + 1;
- CHECK( *begin == *iter );
- CHECK( begin == iter );
+ T data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ print_list("work", data);
+ print_list("expt", data2);
+ REQUIRE(data == data2);
}
-#endif
return true;
}
template<class T>
-static bool test_const_iterator_ops(const std::string& type_id, T& data,
+static bool test_citer_type_ops(const std::string& type_id,
std::enable_if_t< !is_cow_type<T>::value, bool> = true )
{
- printf("**** test_const_iterator_ops: %s\n", type_id.c_str());
+ typedef typename T::const_iterator citer_type;
+ typedef typename T::difference_type diff_type;
+ T data;
+ fill_list(data, 10);
+
+ printf("**** test_citer_type_ops: %s\n", type_id.c_str());
{
- typename T::const_iterator begin = data.cbegin(); // mutable new_store non-const iterator, gets held until destruction
- typename T::const_iterator end = data.cend(); // no new store iterator, on same store as begin and from begin
- typename T::difference_type data_size = static_cast<typename T::difference_type>(data.size());
+ citer_type begin = data.cbegin(); // mutable new_store non-const iterator, gets held until destruction
+ citer_type end = data.cend(); // no new store iterator, on same store as begin and from begin
+ diff_type data_size = static_cast<diff_type>(data.size());
REQUIRE( end - begin == data_size );
REQUIRE( end - data_size == begin );
REQUIRE( begin + data_size == end );
@@ -466,37 +438,40 @@ static bool test_const_iterator_ops(const std::string& type_id, T& data,
REQUIRE( *( begin + data_size - 1 ) == *( end - 1 ) );
REQUIRE( end[-data_size] == begin[0] );
REQUIRE( begin[data_size - 1] == end[-1] );
- test_iterator_dereference<T, typename T::const_iterator>(data.size(), begin, end);
+ test_iterator_dereference<T, citer_type>(data.size(), begin, end);
}
{
- typename T::const_iterator begin = data.cbegin(); // no new store const_iterator
- typename T::const_iterator end = data.cend(); // no new store const_iterator, on same store as begin
- test_iterator_arithmetic<T, typename T::const_iterator>(data.size(), begin, end);
+ citer_type begin = data.cbegin(); // no new store citer_type
+ citer_type end = data.cend(); // no new store citer_type, on same store as begin
+ test_iterator_arithmetic<T, citer_type>(data.size(), begin, end);
}
-#if 0
{
- // INTENIONAL FAILURES, checking behavior of error values etc
- typename T::const_iterator begin = data.cbegin(); // no new store const_iterator
- typename T::const_iterator iter = begin + 1;
- CHECK( *begin == *iter );
- CHECK( begin == iter );
+ T data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ REQUIRE(data == data2);
}
-#endif
return true;
}
template<class T>
-static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
+static bool test_mutable_iterator_ops(const std::string& type_id,
std::enable_if_t< is_cow_type<T>::value, bool> = true )
{
+ typedef typename T::size_type size_type;
+ typedef typename T::const_iterator citer_type;
+ typedef typename T::iterator iter_type;
+ typedef typename T::difference_type diff_type;
+ typedef typename T::value_type value_type;
+
printf("**** test_mutable_iterator_ops(CoW): %s\n", type_id.c_str());
{
- typename T::iterator begin = data.begin(); // mutable new_store non-const iterator, gets held until destruction
- typename T::iterator end = begin.end(); // no new store iterator, on same store as begin and from begin
- typename T::difference_type data_size = static_cast<typename T::difference_type>(data.size());
- typename T::difference_type begin_size = static_cast<typename T::difference_type>(begin.size());
- typename T::difference_type end_size = static_cast<typename T::difference_type>(end.size());
+ T data;
+ fill_list(data, 10);
+ iter_type begin = data.begin(); // mutable new_store non-const iterator, gets held until destruction
+ iter_type end = begin.end(); // no new store iterator, on same store as begin and from begin
+ diff_type data_size = static_cast<diff_type>(data.size());
+ diff_type begin_size = static_cast<diff_type>(begin.size());
+ diff_type end_size = static_cast<diff_type>(end.size());
REQUIRE( begin_size == data_size );
REQUIRE( end_size == data_size );
REQUIRE( end - begin == data_size );
@@ -506,54 +481,68 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
REQUIRE( *( begin + begin_size - 1 ) == *( end - 1 ) );
REQUIRE( end[-end_size] == begin[0] );
REQUIRE( begin[begin_size - 1] == end[-1] );
- test_iterator_dereference<T, typename T::iterator>(begin.size(), begin, end);
+ test_iterator_dereference<T, iter_type>(begin.size(), begin, end);
}
{
- typename T::iterator begin = data.begin(); // mutable new_store non-const iterator, gets held until destruction
- typename T::iterator end = begin.end();
- test_iterator_arithmetic<T, typename T::iterator>(data.size(), begin, end);
+ T data;
+ fill_list(data, 10);
+ iter_type begin = data.begin(); // mutable new_store non-const iterator, gets held until destruction
+ iter_type end = begin.end();
+ test_iterator_arithmetic<T, iter_type>(data.size(), begin, end);
}
// iterator-op: darray/vector-op
// -------------------------------------------
// 1 pop_back()
- // 1 erase (): erase (const_iterator pos)
- // 3 erase (count): erase (iterator first, const_iterator last)
- // 1 insert(const value_type& x): iterator insert(const_iterator pos, const value_type& x)
- // 0 insert(value_type&& x): iterator insert(const_iterator pos, value_type&& x)
- // 1 emplace(Args&&... args): emplace(const_iterator pos, Args&&... args)
- // 2 insert(InputIt first, InputIt last ): insert( const_iterator pos, InputIt first, InputIt last )
+ // 1 erase (): erase (citer_type pos)
+ // 3 erase (count): erase (iterator first, citer_type last)
+ // 1 insert(const value_type& x): iterator insert(citer_type pos, const value_type& x)
+ // 0 insert(value_type&& x): iterator insert(citer_type pos, value_type&& x)
+ // 1 emplace(Args&&... args): emplace(citer_type pos, Args&&... args)
+ // 2 insert(InputIt first, InputIt last ): insert( citer_type pos, InputIt first, InputIt last )
// 1 void push_back(value_type& x)
// 1 void push_back(value_type&& x)
// 1 reference emplace_back(Args&&... args)
// 0 [void push_back( InputIt first, InputIt last )]
// 1 rewind()
{
- typename T::iterator iter = data.begin(); // mutable new_store non-const iterator, gets held until destruction
- typename T::iterator::size_type size_pre = iter.size();
- typename T::iterator::value_type elem = iter.end()[-2];
+ T data;
+ fill_list(data, 10);
+ iter_type iter = data.begin(); // mutable new_store non-const iterator, gets held until destruction
+ size_type size_pre = iter.size();
+ value_type elem = iter.end()[-2];
- // pop_back()
int i;
(void)i;
+ // pop_back()
iter.pop_back();
REQUIRE( iter.size() == size_pre-1 );
REQUIRE( iter == iter.end() );
REQUIRE( iter == iter.begin()+size_pre-1 );
REQUIRE( iter[-1] == elem );
+ {
+ T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // insert( const_iterator pos, InputIt first, InputIt last )
+ // insert( citer_type pos, InputIt first, InputIt last )
REQUIRE( iter == iter.end() );
size_pre = iter.size();
- jau_darray_DataType01 data2;
- test_00_seq_fill(data2, 10);
- // iter.push_back(data2.cbegin(), data2.cend()); // FIXME: Only in jau::darray not stl::vector
- iter.insert(data2.cbegin(), data2.cend()); // same as push_pack(..) since pointing to end() - but iter points here to first new elem
+ {
+ T data2;
+ fill_list(data2, 10);
+ // iter.push_back(data2.cbegin(), data2.cend()); // FIXME: Only in jau::darray not stl::vector
+ iter.insert(data2.cbegin(), data2.cbegin()+data2.size()); // same as push_pack(..) since pointing to end() - but iter points here to first new elem
+ }
REQUIRE( iter.size() == size_pre+10 );
REQUIRE( iter == iter.end()-10 );
+ {
+ T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ REQUIRE(data == data_exp);
+ }
- // erase (count): erase (iterator first, const_iterator last)
+ // erase (count): erase (iterator first, citer_type last)
REQUIRE( iter == iter.end()-10 );
size_pre = iter.size();
// std::cout << "iter.5" << iter << (iter - iter.begin()) << "/" << iter.size() << ", size2 " << size2 << std::endl;
@@ -561,6 +550,10 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
// std::cout << "iter.6" << iter << (iter - iter.begin()) << "/" << iter.size() << std::endl;
REQUIRE( iter.size() == size_pre-10 );
REQUIRE( iter == iter.end() );
+ {
+ T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// erase ()
size_pre = iter.size();
@@ -571,41 +564,58 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
REQUIRE( iter.size() == size_pre-1 );
REQUIRE( iter == iter.begin() );
REQUIRE( *iter == elem );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// void push_back(value_type& x)
size_pre = iter.size();
REQUIRE( iter == iter.begin() );
elem = iter.end()[-1];
- iter.push_back(data2[0]);
- iter.push_back(data2[1]);
- iter.push_back(data2[2]);
- REQUIRE( iter.size() == size_pre+3 );
- REQUIRE( iter == iter.end() );
- REQUIRE( iter[-3] == data2[0] );
- REQUIRE( iter[-2] == data2[1] );
- REQUIRE( iter[-1] == data2[2] );
+ {
+ T data2;
+ fill_list(data2, 10);
+ citer_type data2_iter = data2.cbegin();
+ iter.push_back(data2_iter[0]);
+ iter.push_back(data2_iter[1]);
+ iter.push_back(data2_iter[2]);
+ REQUIRE( iter.size() == size_pre+3 );
+ REQUIRE( iter == iter.end() );
+ REQUIRE( iter[-3] == data2_iter[0] );
+ REQUIRE( iter[-2] == data2_iter[1] );
+ REQUIRE( iter[-1] == data2_iter[2] );
+ }
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };
+ REQUIRE(data == data_exp);
+ }
- // erase (count): erase (iterator first, const_iterator last)
+ // erase (count): erase (iterator first, citer_type last)
size_pre = iter.size();
REQUIRE( iter == iter.end() );
iter -= 3;
iter.erase(3);
REQUIRE( iter.size() == size_pre-3 );
REQUIRE( iter == iter.end() );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// void push_back(value_type&& x)
size_pre = iter.size();
REQUIRE( iter == iter.end() );
{
- typename T::iterator::value_type elem0 = iter.begin()[0];
+ value_type elem0 = iter.begin()[0];
iter.push_back( std::move(elem0));
}
{
- typename T::iterator::value_type elem0 = iter.begin()[1];
+ value_type elem0 = iter.begin()[1];
iter.push_back( std::move(elem0));
}
{
- typename T::iterator::value_type elem0 = iter.begin()[2];
+ value_type elem0 = iter.begin()[2];
iter.push_back( std::move(elem0));
}
REQUIRE( iter.size() == size_pre+3 );
@@ -613,127 +623,175 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
REQUIRE( iter[-3] == iter.begin()[0] );
REQUIRE( iter[-2] == iter.begin()[1] );
REQUIRE( iter[-1] == iter.begin()[2] );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 };
+ REQUIRE(data == data_exp);
+ }
+
+ // erase last three
+ REQUIRE( iter == iter.end() );
+ iter -= 3;
+ iter.erase();
+ iter.erase();
+ iter.erase();
+ REQUIRE( iter == iter.end() );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // iterator insert(const_iterator pos, const value_type& x)
+ // iterator insert(citer_type pos, const value_type& x)
iter.rewind();
- iter += 20;
- REQUIRE( iter == iter.begin()+20 );
+ iter += 5;
+ REQUIRE( iter == iter.begin()+5 );
size_pre = iter.size();
- iter.insert(data2[0]);
- iter.insert(data2[1]);
- iter.insert(data2[2]);
- // i=0; jau::for_each(iter.begin(), iter.end(), [&](const typename T::iterator::value_type & e) { printf("data[%d]: %s\n", i++, e.toString().c_str()); } );
- REQUIRE( iter.size() == size_pre+3 );
- REQUIRE( iter == iter.begin()+20 );
- iter.rewind();
- REQUIRE( iter[20] == data2[2] );
- REQUIRE( iter[21] == data2[1] );
- REQUIRE( iter[22] == data2[0] );
+ {
+ T data2;
+ fill_list(data2, 10);
+ citer_type data2_iter = data2.cbegin();
+ iter.insert(data2_iter[0]);
+ iter.insert(data2_iter[1]);
+ iter.insert(data2_iter[2]);
+ REQUIRE( iter.size() == size_pre+3 );
+ REQUIRE( iter == iter.begin()+5 );
+ iter.rewind();
+ REQUIRE( iter[5] == data2_iter[2] );
+ REQUIRE( iter[6] == data2_iter[1] );
+ REQUIRE( iter[7] == data2_iter[0] );
+ }
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 3, 2, 1, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // insert( const_iterator pos, InputIt first, InputIt last )
- iter += 20;
- REQUIRE( iter == iter.begin()+20 );
+ // insert( citer_type pos, InputIt first, InputIt last )
+ iter += 5;
+ REQUIRE( iter == iter.begin()+5 );
size_pre = iter.size();
- iter.insert(data2.cbegin(), data2.cbegin()+11);
- REQUIRE( iter.size() == size_pre+11 );
- REQUIRE( iter == iter.begin()+20 );
+ {
+ T data2;
+ fill_list(data2, 10);
+ iter.insert(data2.cbegin(), data2.cbegin()+3);
+ }
+ REQUIRE( iter.size() == size_pre+3 );
+ REQUIRE( iter == iter.begin()+5 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 1, 2, 3, 3, 2, 1, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // erase (count): erase (iterator first, const_iterator last)
- REQUIRE( iter == iter.begin()+20 );
+ // erase (count): erase (iterator first, citer_type last)
+ REQUIRE( iter == iter.begin()+5 );
size_pre = iter.size();
- iter -= 10;
- REQUIRE( iter == iter.begin()+10 );
- iter.erase(11);
- REQUIRE( iter.size() == size_pre-11 );
- REQUIRE( iter == iter.begin()+10 );
+ iter.erase(6);
+ REQUIRE( iter.size() == size_pre-6 );
+ REQUIRE( iter == iter.begin()+5 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // 1 emplace(Args&&... args): emplace(const_iterator pos, Args&&... args)
- Addr48Bit a0(start_addr);
+ // 1 emplace(Args&&... args): emplace(citer_type pos, Args&&... args)
size_pre = iter.size();
- REQUIRE( iter == iter.begin()+10 );
- iter.emplace( a0, static_cast<uint8_t>(2) );
- a0.next();
- iter.emplace( a0, static_cast<uint8_t>(3) );
- a0.next();
- iter.emplace( a0, static_cast<uint8_t>(4) );
- a0.next();
- REQUIRE( iter == iter.begin()+10 );
- REQUIRE( iter[0].type == 4 );
- REQUIRE( iter[1].type == 3 );
- REQUIRE( iter[2].type == 2 );
+ REQUIRE( iter == iter.begin()+5 );
+ iter.emplace( static_cast<uint64_t>(2) );
+ iter.emplace( static_cast<uint64_t>(3) );
+ iter.emplace( static_cast<uint64_t>(4) );
+ REQUIRE( iter == iter.begin()+5 );
+ REQUIRE( iter[0] == 4 );
+ REQUIRE( iter[1] == 3 );
+ REQUIRE( iter[2] == 2 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// 1 reference emplace_back(Args&&... args)
size_pre = iter.size();
- REQUIRE( iter == iter.begin()+10 );
- iter.emplace_back( a0, static_cast<uint8_t>(2) );
- a0.next();
- iter.emplace_back( a0, static_cast<uint8_t>(3) );
- a0.next();
- iter.emplace_back( a0, static_cast<uint8_t>(4) );
- a0.next();
+ REQUIRE( iter == iter.begin()+5 );
+ iter.emplace_back( static_cast<uint64_t>(2) );
+ iter.emplace_back( static_cast<uint64_t>(3) );
+ iter.emplace_back( static_cast<uint64_t>(4) );
REQUIRE( iter == iter.end() );
- REQUIRE( iter[-1].type == 4 );
- REQUIRE( iter[-2].type == 3 );
- REQUIRE( iter[-3].type == 2 );
+ REQUIRE( iter[-1] == 4 );
+ REQUIRE( iter[-2] == 3 );
+ REQUIRE( iter[-3] == 2 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9, 2, 3, 4 };
+ REQUIRE(data == data_exp);
+ }
// multiple erase()
size_pre = iter.size();
REQUIRE( iter == iter.end() );
- iter -= 15;
- REQUIRE( iter == iter.end()-15 );
+ iter -= 10;
+ REQUIRE( iter == iter.end()-10 );
{
int count = 0;
while( iter != iter.end() ) {
iter.erase();
count++;
}
- REQUIRE( iter.size() == size_pre - 15 );
+ REQUIRE( iter.size() == size_pre - 10 );
REQUIRE( iter == iter.end() );
}
+ {
+ T data_exp = { 2, 3, 4, 5 };
+ REQUIRE(data == data_exp);
+ }
}
return true;
}
template<class T>
-static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
+static bool test_mutable_iterator_ops(const std::string& type_id,
std::enable_if_t< !is_cow_type<T>::value, bool> = true )
{
+ typedef typename T::iterator iter_type;
+ typedef typename T::difference_type diff_type;
+
printf("**** test_mutable_iterator_ops(___): %s\n", type_id.c_str());
{
- typename T::iterator begin = data.begin();
- typename T::iterator end = data.end();
- typename T::difference_type data_size = static_cast<typename T::difference_type>(data.size());
+ T data;
+ fill_list(data, 10);
+ iter_type begin = data.begin();
+ iter_type end = data.end();
+ diff_type data_size = static_cast<diff_type>(data.size());
REQUIRE( end - begin == data_size );
REQUIRE( end - data_size == begin );
REQUIRE( begin + data_size == end );
REQUIRE( *( end - data_size ) == *begin );
REQUIRE( *( begin + data_size ) == *end );
- test_iterator_dereference<T, typename T::iterator>(data.size(), begin, end);
+ test_iterator_dereference<T, iter_type>(data.size(), begin, end);
}
{
- typename T::iterator begin = data.begin();
- typename T::iterator end = data.end();
- test_iterator_arithmetic<T, typename T::iterator>(data.size(), begin, end);
+ T data;
+ fill_list(data, 10);
+ iter_type begin = data.begin();
+ iter_type end = data.end();
+ test_iterator_arithmetic<T, iter_type>(data.size(), begin, end);
}
// iterator-op: darray/vector-op
// -------------------------------------------
// 1 pop_back()
- // 1 erase (const_iterator pos)
- // 3 erase (iterator first, const_iterator last)
- // 1 iterator insert(const_iterator pos, const value_type& x)
- // 0 iterator insert(const_iterator pos, value_type&& x)
- // 1 emplace(const_iterator pos, Args&&... args)
- // 2 insert( const_iterator pos, InputIt first, InputIt last )
+ // 1 erase (citer_type pos)
+ // 3 erase (iterator first, citer_type last)
+ // 1 iterator insert(citer_type pos, const value_type& x)
+ // 0 iterator insert(citer_type pos, value_type&& x)
+ // 1 emplace(citer_type pos, Args&&... args)
+ // 2 insert( citer_type pos, InputIt first, InputIt last )
// 1 void push_back(value_type& x)
// 1 void push_back(value_type&& x)
// 1 reference emplace_back(Args&&... args)
// 0 [void push_back( InputIt first, InputIt last )]
// 1 rewind()
{
- typename T::iterator iter = data.end();
+ T data;
+ fill_list(data, 10);
+ iter_type iter = data.end();
typename T::size_type size_pre = data.size();
typename T::value_type elem = iter[-2];
@@ -746,18 +804,27 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
REQUIRE( iter == data.end() );
REQUIRE( iter == data.begin()+size_pre-1 );
REQUIRE( iter[-1] == elem );
+ {
+ T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // insert( const_iterator pos, InputIt first, InputIt last )
+ // insert( citer_type pos, InputIt first, InputIt last )
REQUIRE( iter == data.end() );
size_pre = data.size();
- jau_darray_DataType01 data2;
- test_00_seq_fill(data2, 10);
- // data.push_back(data2.cbegin(), data2.cend()); // FIXME: Only in jau::darray not stl::vector
- iter = data.insert(iter, data2.cbegin(), data2.cend()); // same as push_pack(..) since pointing to end() - but data points here to first new elem
+ {
+ T data2;
+ fill_list(data2, 10);
+ iter = data.insert(iter, data2.cbegin(), data2.cbegin()+data2.size()); // same as push_pack(..) since pointing to end() - but data points here to first new elem
+ }
REQUIRE( data.size() == size_pre+10 );
REQUIRE( iter == data.end()-10 );
+ {
+ T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ REQUIRE(data == data_exp);
+ }
- // erase (count): erase (iterator first, const_iterator last)
+ // erase (count): erase (iterator first, citer_type last)
REQUIRE( iter == data.end()-10 );
size_pre = data.size();
// std::cout << "data.5" << data << (data - data.begin()) << "/" << data.size() << ", size2 " << size2 << std::endl;
@@ -765,40 +832,58 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
// std::cout << "data.6" << data << (data - data.begin()) << "/" << data.size() << std::endl;
REQUIRE( data.size() == size_pre-10 );
REQUIRE( iter == data.end() );
+ {
+ T data_exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// erase ()
size_pre = data.size();
iter = data.begin();
REQUIRE( iter == data.begin() );
elem = iter[1];
- // i=0; jau::for_each(data.begin(), data.begin()+3, [&](const typename T::value_type & e) { printf("data[%d]: %s\n", i++, e.toString().c_str()); } );
iter = data.erase(iter);
- // i=0; jau::for_each(data.begin(), data.begin()+3, [&](const typename T::value_type & e) { printf("data[%d]: %s\n", i++, e.toString().c_str()); } );
REQUIRE( data.size() == size_pre-1 );
REQUIRE( iter == data.begin() );
REQUIRE( *iter == elem );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// void push_back(value_type& x)
size_pre = data.size();
REQUIRE( iter == data.begin() );
elem = data.end()[-1];
- data.push_back(data2[0]);
- data.push_back(data2[1]);
- data.push_back(data2[2]);
- iter = data.end();
- REQUIRE( data.size() == size_pre+3 );
- REQUIRE( iter == data.end() );
- REQUIRE( iter[-3] == data2[0] );
- REQUIRE( iter[-2] == data2[1] );
- REQUIRE( iter[-1] == data2[2] );
+ {
+ T data2;
+ fill_list(data2, 10);
+ data.push_back(data2[0]);
+ data.push_back(data2[1]);
+ data.push_back(data2[2]);
+ iter = data.end();
+ REQUIRE( data.size() == size_pre+3 );
+ REQUIRE( iter == data.end() );
+ REQUIRE( iter[-3] == data2[0] );
+ REQUIRE( iter[-2] == data2[1] );
+ REQUIRE( iter[-1] == data2[2] );
+ }
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3 };
+ REQUIRE(data == data_exp);
+ }
- // erase (count): erase (iterator first, const_iterator last)
+ // erase (count): erase (iterator first, citer_type last)
size_pre = data.size();
REQUIRE( iter == data.end() );
iter -= 3;
iter = data.erase(iter, iter+3);
REQUIRE( data.size() == size_pre-3 );
REQUIRE( iter == data.end() );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// void push_back(value_type&& x)
size_pre = data.size();
@@ -821,83 +906,134 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
REQUIRE( iter[-3] == data.begin()[0] );
REQUIRE( iter[-2] == data.begin()[1] );
REQUIRE( iter[-1] == data.begin()[2] );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 };
+ REQUIRE(data == data_exp);
+ }
- // iterator insert(const_iterator pos, const value_type& x)
+ // erase last three
+ REQUIRE( iter == data.end() );
+ iter -= 3;
+ iter = data.erase(iter);
+ iter = data.erase(iter);
+ iter = data.erase(iter);
+ REQUIRE( iter == data.end() );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
+
+ // iterator insert(citer_type pos, const value_type& x)
iter = data.begin();
- iter += 20;
- REQUIRE( iter == data.begin()+20 );
+ iter += 5;
+ REQUIRE( iter == data.begin()+5 );
size_pre = data.size();
- iter = data.insert(iter, data2[0]);
- iter = data.insert(iter, data2[1]);
- iter = data.insert(iter, data2[2]);
- REQUIRE( data.size() == size_pre+3 );
- REQUIRE( iter == data.begin()+20 );
- iter = data.begin();
- REQUIRE( iter[20] == data2[2] );
- REQUIRE( iter[21] == data2[1] );
- REQUIRE( iter[22] == data2[0] );
+ {
+ T data2;
+ fill_list(data2, 10);
+ iter = data.insert(iter, data2[0]);
+ iter = data.insert(iter, data2[1]);
+ iter = data.insert(iter, data2[2]);
+ REQUIRE( data.size() == size_pre+3 );
+ REQUIRE( iter == data.begin()+5 );
+ iter = data.begin();
+ REQUIRE( iter[5] == data2[2] );
+ REQUIRE( iter[6] == data2[1] );
+ REQUIRE( iter[7] == data2[0] );
+ }
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 3, 2, 1, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // insert( const_iterator pos, InputIt first, InputIt last )
- iter += 20;
- REQUIRE( iter == data.begin()+20 );
+ // insert( citer_type pos, InputIt first, InputIt last )
+ iter += 5;
+ REQUIRE( iter == data.begin()+5 );
size_pre = data.size();
- iter = data.insert(iter, data2.cbegin(), data2.cbegin()+11);
- REQUIRE( data.size() == size_pre+11 );
- REQUIRE( iter == data.begin()+20 );
+ {
+ T data2;
+ fill_list(data2, 10);
+ iter = data.insert(iter, data2.cbegin(), data2.cbegin()+3);
+ }
+ REQUIRE( data.size() == size_pre+3 );
+ REQUIRE( iter == data.begin()+5 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 1, 2, 3, 3, 2, 1, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // erase (count): erase (iterator first, const_iterator last)
- REQUIRE( iter == data.begin()+20 );
+ // erase (count): erase (iterator first, citer_type last)
+ REQUIRE( iter == data.begin()+5 );
size_pre = data.size();
- iter -= 10;
- REQUIRE( iter == data.begin()+10 );
- iter = data.erase(iter, iter+11);
- REQUIRE( data.size() == size_pre-11 );
- REQUIRE( iter == data.begin()+10 );
+ iter = data.erase(iter, iter+6);
+ REQUIRE( data.size() == size_pre-6 );
+ REQUIRE( iter == data.begin()+5 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
- // 1 emplace(Args&&... args): emplace(const_iterator pos, Args&&... args)
- Addr48Bit a0(start_addr);
+ // 1 emplace(Args&&... args): emplace(citer_type pos, Args&&... args)
size_pre = data.size();
- REQUIRE( iter == data.begin()+10 );
- iter = data.emplace(iter, a0, static_cast<uint8_t>(2) );
- a0.next();
- iter = data.emplace(iter, a0, static_cast<uint8_t>(3) );
- a0.next();
- iter = data.emplace(iter, a0, static_cast<uint8_t>(4) );
- a0.next();
- REQUIRE( iter == data.begin()+10 );
- REQUIRE( iter[0].type == 4 );
- REQUIRE( iter[1].type == 3 );
- REQUIRE( iter[2].type == 2 );
+ REQUIRE( iter == data.begin()+5 );
+ iter = data.emplace(iter, static_cast<uint64_t>(2) );
+ iter = data.emplace(iter, static_cast<uint64_t>(3) );
+ iter = data.emplace(iter, static_cast<uint64_t>(4) );
+
+ REQUIRE( iter == data.begin()+5 );
+ REQUIRE( iter[0] == 4 );
+ REQUIRE( iter[1] == 3 );
+ REQUIRE( iter[2] == 2 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9 };
+ REQUIRE(data == data_exp);
+ }
// 1 reference emplace_back(Args&&... args)
size_pre = data.size();
- REQUIRE( iter == data.begin()+10 );
- data.emplace_back( a0, static_cast<uint8_t>(2) );
- a0.next();
- data.emplace_back( a0, static_cast<uint8_t>(3) );
- a0.next();
- data.emplace_back( a0, static_cast<uint8_t>(4) );
- a0.next();
+ REQUIRE( iter == data.begin()+5 );
+ data.emplace_back( static_cast<uint64_t>(2) );
+ data.emplace_back( static_cast<uint64_t>(3) );
+ data.emplace_back( static_cast<uint64_t>(4) );
iter = data.end();
REQUIRE( iter == data.end() );
- REQUIRE( iter[-1].type == 4 );
- REQUIRE( iter[-2].type == 3 );
- REQUIRE( iter[-3].type == 2 );
+ REQUIRE( iter[-1] == 4 );
+ REQUIRE( iter[-2] == 3 );
+ REQUIRE( iter[-3] == 2 );
+ {
+ T data_exp = { 2, 3, 4, 5, 6, 4, 3, 2, 7, 8, 9, 2, 3, 4 };
+ REQUIRE(data == data_exp);
+ }
// multiple erase()
size_pre = data.size();
REQUIRE( iter == data.end() );
- iter -= 15;
- REQUIRE( iter == data.end()-15 );
+ iter -= 10;
+ REQUIRE( iter == data.end()-10 );
{
int count = 0;
while( iter != data.end() ) {
iter = data.erase(iter);
count++;
}
- REQUIRE( data.size() == size_pre - 15 );
+ REQUIRE( data.size() == size_pre - 10 );
REQUIRE( iter == data.end() );
}
+ {
+ T data_exp = { 2, 3, 4, 5 };
+ REQUIRE(data == data_exp);
+ }
+ }
+ {
+ T data;
+ fill_list(data, 10);
+ T data2 = data;
+ T data3(data);
+ print_list("orig", data2);
+ print_list("copy1", data2);
+ print_list("copy2", data3);
+ REQUIRE(data == data2);
+ REQUIRE(data == data3);
}
return true;
}
@@ -907,43 +1043,25 @@ static bool test_mutable_iterator_ops(const std::string& type_id, T& data,
template<class T>
static bool test_01_validate_iterator_ops(const std::string& type_id) {
- const std::size_t size0 = 100;
- T data;
- REQUIRE(0 == data.get_allocator().memory_usage);
- REQUIRE(data.size() == 0);
- REQUIRE(data.capacity() == 0);
- REQUIRE(data.empty() == true);
+ test_citer_type_ops<T>(type_id);
- test_00_seq_fill(data, size0);
- REQUIRE(0 != data.get_allocator().memory_usage);
- REQUIRE(data.size() == size0);
- REQUIRE(data.size() <= data.capacity());
-
- test_00_list_itr(data, false);
- REQUIRE(0 != data.get_allocator().memory_usage);
- REQUIRE(data.size() == size0);
+ test_mutable_iterator_ops<T>(type_id);
- test_const_iterator_ops<T>(type_id, data);
-
- test_mutable_iterator_ops<T>(type_id, data);
-
- data.clear();
- REQUIRE(data.size() == 0);
- // REQUIRE(0 == data.get_allocator().memory_usage);
- return data.size() == 0;
+ return true;
}
template<class T>
static bool test_01_cow_iterator_properties(const std::string& type_id) {
- typedef typename T::const_iterator const_iterator;
- typedef typename T::iterator write_iterator;
+ typedef typename T::size_type size_type;
+ typedef typename T::const_iterator citer_type;
+ typedef typename T::iterator iter_type;
printf("**** test_cow_iterator_properties: %s\n", type_id.c_str());
- print_iterator_info<const_iterator>("const_iterator");
- print_iterator_info<write_iterator>("write_iterator");
+ print_iterator_info<citer_type>("citer_type");
+ print_iterator_info<iter_type>("iter_type");
- const std::size_t size0 = 100;
+ const size_type size0 = 100;
T data;
REQUIRE(0 == data.get_allocator().memory_usage);
@@ -951,16 +1069,16 @@ static bool test_01_cow_iterator_properties(const std::string& type_id) {
REQUIRE(data.capacity() == 0);
REQUIRE(data.empty() == true);
- test_00_seq_fill(data, size0);
+ fill_list(data, size0);
REQUIRE(0 != data.get_allocator().memory_usage);
REQUIRE(data.size() == size0);
REQUIRE(data.size() <= data.capacity());
- // test relationship and distance with mixed iterator and const_iterator
+ // test relationship and distance with mixed iterator and citer_type
// in both direction using the free overloaded operator of cow_ro_* and cow_rw_*
{
- write_iterator citer1 = data.begin();
- const_iterator citer2(citer1);
+ iter_type citer1 = data.begin();
+ citer_type citer2(citer1);
REQUIRE( ( citer1 == citer2 ) == true); // iter op==()
REQUIRE( ( citer2 == citer1 ) == true); // iter op==()
@@ -989,49 +1107,49 @@ static bool test_01_cow_iterator_properties(const std::string& type_id) {
}
// test mutable non-const 'new store' behavior
- // inclusive 'iterator -> const_iterator' conversion if 'iterator_is_const == true'
- const_iterator c_begin0 = data.cbegin(); // orig store
+ // inclusive 'iterator -> citer_type' conversion if 'iterator_is_const == true'
+ citer_type c_begin0 = data.cbegin(); // orig store
{
- // iterator_type is const_iterator.
+ // iterator_type is citer_type.
// The cow_rw_iterator is being fetched via data.begin(), which creates a new store.
// The cow_rw_iterator is converted immediately to cow_ro_iterator and the cow_rw_iterator gets destructed.
// This destruction moves the cow_rw_iterator's new store into the cow container right away.
- printf("testing mutable non-const behavior incl 'iterator -> const_iterator' conversion.\n");
+ printf("testing mutable non-const behavior incl 'iterator -> citer_type' conversion.\n");
- const_iterator c_begin1;
+ citer_type c_begin1;
{
- const_iterator m_begin1( data.begin() ); // mutable iterator first, converts to const_iterator and
+ citer_type m_begin1( data.begin() ); // mutable iterator first, converts to citer_type and
// mutable iterator destructs (new_store -> cow)
c_begin1 = data.cbegin();
REQUIRE(*c_begin1 == *m_begin1);
REQUIRE( c_begin1 == m_begin1);
REQUIRE( ( c_begin1 - m_begin1 ) == 0);
printf(" 1st store: %s == %s, dist %u\n",
- c_begin1->toString().c_str(), m_begin1->toString().c_str(), (unsigned int)(c_begin1 - m_begin1));
+ uint64DecString(*c_begin1, ',', 2).c_str(), uint64DecString(*m_begin1, ',', 2).c_str(), (unsigned int)(c_begin1 - m_begin1));
REQUIRE(*c_begin1 == *c_begin0);
REQUIRE( c_begin1 != c_begin0);
REQUIRE( ( c_begin1 - c_begin0 ) != 0);
printf("1st -> 0st store: %s == %s, dist %u != 0\n",
- c_begin1->toString().c_str(), c_begin0->toString().c_str(), (unsigned int)(c_begin1 - c_begin0));
+ uint64DecString(*c_begin1, ',', 2).c_str(), uint64DecString(*c_begin0, ',', 2).c_str(), (unsigned int)(c_begin1 - c_begin0) );
- const_iterator c_begin2;
+ citer_type c_begin2;
{
- const_iterator m_begin2 ( data.begin() ); // mutable iterator first, converts to const_iterator and
+ citer_type m_begin2 ( data.begin() ); // mutable iterator first, converts to citer_type and
// mutable iterator destructs (new_store -> cow)
c_begin2 = data.cbegin();
REQUIRE(*c_begin2 == *m_begin2);
REQUIRE( c_begin2 == m_begin2);
REQUIRE( ( c_begin2 - m_begin2 ) == 0);
printf(" 2nd store: %s == %s, dist %u\n",
- c_begin2->toString().c_str(), m_begin2->toString().c_str(), (unsigned int)(c_begin2 - m_begin2));
+ uint64DecString(*c_begin2, ',', 2).c_str(), uint64DecString(*m_begin2, ',', 2).c_str(), (unsigned int)(c_begin2 - m_begin2) );
REQUIRE(*c_begin2 == *c_begin1);
REQUIRE( c_begin2 != c_begin1);
REQUIRE( ( c_begin2 - c_begin1 ) != 0);
printf("2nd -> 1st store: %s == %s, dist %u != 0\n",
- c_begin1->toString().c_str(), c_begin0->toString().c_str(), (unsigned int)(c_begin1 - c_begin0));
+ uint64DecString(*c_begin1, ',', 2).c_str(), uint64DecString(*c_begin0, ',', 2).c_str(), (unsigned int)(c_begin1 - c_begin0) );
}
}
@@ -1045,47 +1163,47 @@ static bool test_01_cow_iterator_properties(const std::string& type_id) {
// when the cow_rw_iterator gets destructed later on (out of scope).
printf("testing mutable non-const behavior.\n");
- const_iterator c_begin1;
+ citer_type c_begin1;
{
- write_iterator m_begin1 = data.begin(); // mutable new_store non-const iterator, gets held until destruction
- c_begin1 = m_begin1; // get immutable const_iterator from newly created store
+ iter_type m_begin1 = data.begin(); // mutable new_store non-const iterator, gets held until destruction
+ c_begin1 = m_begin1; // get immutable citer_type from newly created store
REQUIRE(*c_begin1 == *m_begin1);
REQUIRE( c_begin1 == m_begin1);
REQUIRE( ( c_begin1 - m_begin1 ) == 0);
printf(" 1st store: %s == %s, dist %u\n",
- c_begin1->toString().c_str(), m_begin1->toString().c_str(), (unsigned int)(c_begin1 - m_begin1));
- const_iterator c_begin2;
+ uint64DecString(*c_begin1, ',', 2).c_str(), uint64DecString(*m_begin1, ',', 2).c_str(), (unsigned int)(c_begin1 - m_begin1));
+ citer_type c_begin2;
{
- write_iterator m_begin2 = data.begin(); // mutable new_store non-const iterator, gets held until destruction
- c_begin2 = m_begin2; // get immutable const_iterator from newly created store
+ iter_type m_begin2 = data.begin(); // mutable new_store non-const iterator, gets held until destruction
+ c_begin2 = m_begin2; // get immutable citer_type from newly created store
REQUIRE(*c_begin2 == *m_begin2);
REQUIRE( c_begin2 == m_begin2);
REQUIRE( ( c_begin2 - m_begin2 ) == 0);
printf(" 2nd store: %s == %s, dist %u\n",
- c_begin2->toString().c_str(), m_begin2->toString().c_str(), (unsigned int)(c_begin2 - m_begin2));
+ uint64DecString(*c_begin2, ',', 2).c_str(), uint64DecString(*m_begin2, ',', 2).c_str(), (unsigned int)(c_begin2 - m_begin2));
REQUIRE(*c_begin2 == *c_begin1);
REQUIRE( c_begin2 != c_begin1);
REQUIRE( ( c_begin2 - c_begin1 ) != 0);
printf("2nd -> 1st store: %s == %s, dist %u\n",
- c_begin2->toString().c_str(), c_begin1->toString().c_str(), (unsigned int)(c_begin2 - c_begin1));
+ uint64DecString(*c_begin2, ',', 2).c_str(), uint64DecString(*c_begin1, ',', 2).c_str(), (unsigned int)(c_begin2 - c_begin1));
}
// 2nd store -> cow_xxx
- const_iterator c_begin2b = data.cbegin();
+ citer_type c_begin2b = data.cbegin();
REQUIRE(*c_begin2 == *c_begin2b);
REQUIRE( c_begin2 == c_begin2b);
REQUIRE( ( c_begin2 - c_begin2b ) == 0);
printf("2nd -> cow == cbegin: %s == %s, dist %u\n",
- c_begin2->toString().c_str(), c_begin2b->toString().c_str(), (unsigned int)(c_begin2 - c_begin2b));
+ uint64DecString(*c_begin2, ',', 2).c_str(), uint64DecString(*c_begin2b, ',', 2).c_str(), (unsigned int)(c_begin2 - c_begin2b));
printf("2nd -> 1st : %s == %s, dist %u\n",
- c_begin1->toString().c_str(), c_begin2->toString().c_str(), (unsigned int)(c_begin1 - c_begin2));
+ uint64DecString(*c_begin1, ',', 2).c_str(), uint64DecString(*c_begin2, ',', 2).c_str(), (unsigned int)(c_begin1 - c_begin2));
}
// 1st store -> cow_xxx
- typename T::const_iterator c_begin1b = data.cbegin();
+ citer_type c_begin1b = data.cbegin();
printf("1st -> cow == cbegin: %s == %s, dist %u\n",
- c_begin1->toString().c_str(), c_begin1b->toString().c_str(), (unsigned int)(c_begin1 - c_begin1b));
+ uint64DecString(*c_begin1, ',', 2).c_str(), uint64DecString(*c_begin1b, ',', 2).c_str(), (unsigned int)(c_begin1 - c_begin1b));
REQUIRE(*c_begin1 == *c_begin1b);
REQUIRE( c_begin1 == c_begin1b);
REQUIRE( ( c_begin1 - c_begin1b ) == 0);
@@ -1097,28 +1215,28 @@ static bool test_01_cow_iterator_properties(const std::string& type_id) {
****************************************************************************************/
TEST_CASE( "Iterator Test 00 - Inspect all Iterator Types", "[datatype][std][vector][darray][cow_vector][cow_darray]" ) {
- test_00_inspect_iterator_types< std_vector_DataType01 >("std::vector<T>");
- test_00_inspect_iterator_types< jau_darray_DataType01 >("jau::darray<T>");
- test_00_inspect_iterator_types< jau_cow_vector_DataType01 >("jau::cow_vector<T>");
- test_00_inspect_iterator_types< jau_cow_darray_DataType01 >("jau::cow_darray<T>");
+ test_00_inspect_iterator_types< std_vector_uint64_t >("std::vector<T>");
+ test_00_inspect_iterator_types< jau_darray_uint64_t >("jau::darray<T>");
+ test_00_inspect_iterator_types< jau_cow_vector_uint64_t >("jau::cow_vector<T>");
+ test_00_inspect_iterator_types< jau_cow_darray_uint64_t >("jau::cow_darray<T>");
}
TEST_CASE( "STD Vector Test 01 - Validate Iterator and Index Operations", "[datatype][std][vector]" ) {
- test_01_validate_iterator_ops< std_vector_DataType01 >("std::vector<T>");
+ test_01_validate_iterator_ops< std_vector_uint64_t >("std::vector<T>");
}
TEST_CASE( "JAU DArray Test 02 - Validate Iterator and Index Operations", "[datatype][jau][darray]" ) {
- test_01_validate_iterator_ops< jau_darray_DataType01 >("jau::darray<T>");
+ test_01_validate_iterator_ops< jau_darray_uint64_t >("jau::darray<T>");
}
TEST_CASE( "JAU COW_Vector Test 11 - Validate Iterator Operations", "[datatype][jau][cow_vector]" ) {
- test_01_validate_iterator_ops< jau_cow_vector_DataType01 >("jau::cow_vector<T>");
+ test_01_validate_iterator_ops< jau_cow_vector_uint64_t >("jau::cow_vector<T>");
- test_01_cow_iterator_properties<jau_cow_vector_DataType01>("jau::cow_vector<T>");
+ test_01_cow_iterator_properties<jau_cow_vector_uint64_t>("jau::cow_vector<T>");
}
TEST_CASE( "JAU COW_DArray Test 21 - Validate Iterator Operations", "[datatype][jau][cow_darray]" ) {
- test_01_validate_iterator_ops< jau_cow_darray_DataType01 >("jau::cow_darray<T>");
+ test_01_validate_iterator_ops< jau_cow_darray_uint64_t >("jau::cow_darray<T>");
- test_01_cow_iterator_properties<jau_cow_darray_DataType01>("jau::cow_darray<T>");
+ test_01_cow_iterator_properties<jau_cow_darray_uint64_t>("jau::cow_darray<T>");
}