- Added nth and index_of.

- Used BOOST_MOVE_BASE
This commit is contained in:
Ion Gaztañaga
2014-11-01 20:03:25 +01:00
parent 6d034733bd
commit 6f1f162cb3
21 changed files with 615 additions and 106 deletions
+1
View File
@@ -101,6 +101,7 @@ bool CheckEqualPairContainers(const MyBoostCont &boostcont, const MyStdCont &std
}
return true;
}
} //namespace test{
} //namespace container {
} //namespace boost{
+86
View File
@@ -0,0 +1,86 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
#define BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
#include <boost/container/detail/config_begin.hpp>
namespace boost{
namespace container {
namespace test{
template<class Container>
const Container &as_const(Container &c)
{ return c; }
//nth, index_of
template<class Container>
bool test_nth_index_of(Container &c)
{
typename Container::iterator it;
typename Container::const_iterator cit;
typename Container::size_type sz, csz;
//index 0
it = c.nth(0);
sz = c.index_of(it);
cit = as_const(c).nth(0);
csz = as_const(c).index_of(cit);
if(it != c.begin())
return false;
if(cit != c.cbegin())
return false;
if(sz != 0)
return false;
if(csz != 0)
return false;
//index size()/2
const typename Container::size_type sz_div_2 = c.size()/2;
it = c.nth(sz_div_2);
sz = c.index_of(it);
cit = as_const(c).nth(sz_div_2);
csz = as_const(c).index_of(cit);
if(it != (c.begin()+sz_div_2))
return false;
if(cit != (c.cbegin()+sz_div_2))
return false;
if(sz != sz_div_2)
return false;
if(csz != sz_div_2)
return false;
//index size()
it = c.nth(c.size());
sz = c.index_of(it);
cit = as_const(c).nth(c.size());
csz = as_const(c).index_of(cit);
if(it != c.end())
return false;
if(cit != c.cend())
return false;
if(sz != c.size())
return false;
if(csz != c.size())
return false;
return true;
}
} //namespace test{
} //namespace container {
} //namespace boost{
#include <boost/container/detail/config_end.hpp>
#endif //#ifndef BOOST_CONTAINER_TEST_CONTAINER_COMMON_TESTS_HPP
+4 -6
View File
@@ -55,8 +55,7 @@ template<class VectorWithExpandBwdAllocator>
bool test_insert_with_expand_bwd()
{
typedef typename VectorWithExpandBwdAllocator::value_type value_type;
typedef typename boost::remove_volatile<value_type>::type non_volatile_value_type;
typedef std::vector<non_volatile_value_type> Vect;
typedef std::vector<value_type> Vect;
const unsigned int MemorySize = 1000;
//Distance old and new buffer
@@ -84,7 +83,7 @@ bool test_insert_with_expand_bwd()
boost::movelib::unique_ptr<char[]> memptr =
boost::movelib::make_unique_definit<char[]>(MemorySize*sizeof(value_type));
value_type *memory = (value_type*)memptr.get();
std::vector<non_volatile_value_type> initial_data;
std::vector<value_type> initial_data;
initial_data.resize(InitialSize[iteration]);
for(unsigned int i = 0; i < InitialSize[iteration]; ++i){
initial_data[i] = i;
@@ -133,7 +132,6 @@ template<class VectorWithExpandBwdAllocator>
bool test_assign_with_expand_bwd()
{
typedef typename VectorWithExpandBwdAllocator::value_type value_type;
typedef typename boost::remove_volatile<value_type>::type non_volatile_value_type;
const unsigned int MemorySize = 200;
const unsigned int Offset[] = { 50, 50, 50};
@@ -147,14 +145,14 @@ bool test_assign_with_expand_bwd()
boost::movelib::make_unique_definit<char[]>(MemorySize*sizeof(value_type));
value_type *memory = (value_type*)memptr.get();
//Create initial data
std::vector<non_volatile_value_type> initial_data;
std::vector<value_type> initial_data;
initial_data.resize(InitialSize[iteration]);
for(unsigned int i = 0; i < InitialSize[iteration]; ++i){
initial_data[i] = i;
}
//Create data to assign
std::vector<non_volatile_value_type> data_to_insert;
std::vector<value_type> data_to_insert;
data_to_insert.resize(InsertSize[iteration]);
for(unsigned int i = 0; i < InsertSize[iteration]; ++i){
data_to_insert[i] = -i;
+17
View File
@@ -19,6 +19,7 @@
#include "movable_int.hpp"
#include "map_test.hpp"
#include "propagate_allocator_test.hpp"
#include "container_common_tests.hpp"
#include "emplace_test.hpp"
#include <vector>
#include <boost/container/detail/flat_tree.hpp>
@@ -445,6 +446,22 @@ int main()
test_move<flat_map<recursive_flat_map, recursive_flat_map> >();
test_move<flat_multimap<recursive_flat_multimap, recursive_flat_multimap> >();
}
//Now test nth/index_of
{
flat_map<int, int> map;
flat_multimap<int, int> mmap;
map.insert(std::pair<int, int>(0, 0));
map.insert(std::pair<int, int>(1, 0));
map.insert(std::pair<int, int>(2, 0));
mmap.insert(std::pair<int, int>(0, 0));
mmap.insert(std::pair<int, int>(1, 0));
mmap.insert(std::pair<int, int>(2, 0));
if(!boost::container::test::test_nth_index_of(map))
return 1;
if(!boost::container::test::test_nth_index_of(mmap))
return 1;
}
////////////////////////////////////
// Ordered insertion test
+17
View File
@@ -21,6 +21,7 @@
#include "set_test.hpp"
#include "propagate_allocator_test.hpp"
#include "emplace_test.hpp"
#include "container_common_tests.hpp"
#include <vector>
#include <boost/container/detail/flat_tree.hpp>
@@ -531,6 +532,22 @@ int main()
test_move<flat_set<recursive_flat_set> >();
test_move<flat_multiset<recursive_flat_multiset> >();
}
//Now test nth/index_of
{
flat_set<int> set;
flat_multiset<int> mset;
set.insert(0);
set.insert(1);
set.insert(2);
mset.insert(0);
mset.insert(1);
mset.insert(2);
if(!boost::container::test::test_nth_index_of(set))
return 1;
if(!boost::container::test::test_nth_index_of(mset))
return 1;
}
////////////////////////////////////
// Ordered insertion test
+5
View File
@@ -34,6 +34,7 @@
#include <boost/core/no_exceptions_support.hpp>
#include <boost/static_assert.hpp>
#include "insert_test.hpp"
#include "container_common_tests.hpp"
namespace boost{
namespace container {
@@ -294,6 +295,10 @@ int vector_test()
stdvector.assign(l.begin(), l.end());
if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
}
boostvector.resize(100);
if(!test_nth_index_of(boostvector))
return 1;
/* deque has no reserve or capacity
std::size_t cap = boostvector.capacity();
boostvector.reserve(cap*2);