mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +02:00
Refactor initializer_list tests to avoid code duplication and add some missing initializer_list overload tests
This commit is contained in:
@@ -411,39 +411,6 @@ int test_map_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename FlatMapType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<std::pair<int, int>> il
|
||||
= {std::make_pair(1, 2), std::make_pair(3, 4)};
|
||||
|
||||
const FlatMapType expected(il.begin(), il.end());
|
||||
{
|
||||
const FlatMapType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
const FlatMapType sil_ordered(ordered_unique_range, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
FlatMapType sil_assign = {std::make_pair(99, 100)};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
FlatMapType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::container::test;
|
||||
@@ -506,10 +473,10 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_support_for_initialization_list_for<flat_map<int, int> >())
|
||||
if(!boost::container::test::test_map_support_for_initialization_list_for<flat_map<int, int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<flat_multimap<int, int> >())
|
||||
if (!boost::container::test::test_map_support_for_initialization_list_for<flat_multimap<int, int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
|
@@ -590,10 +590,10 @@ int main()
|
||||
if(!boost::container::test::test_emplace<flat_multiset<test::EmplaceInt>, SetOptions>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<flat_set<int> >())
|
||||
if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<flat_set<int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<flat_multiset<int> >())
|
||||
if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<flat_multiset<int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
|
@@ -126,10 +126,14 @@ bool test_support_for_initializer_list()
|
||||
const std::initializer_list<int> il = {1, 10};
|
||||
const list<int> expectedList(il.begin(), il.end());
|
||||
|
||||
const list<int> testConstructor = il;
|
||||
const list<int> testConstructor((il));
|
||||
if(testConstructor != expectedList)
|
||||
return false;
|
||||
|
||||
const list<int> testConstructorAllocator(il, list<int>::allocator_type());
|
||||
if (testConstructorAllocator != expectedList)
|
||||
return false;
|
||||
|
||||
list<int> testAssignOperator = {10, 11};
|
||||
testAssignOperator = il;
|
||||
if(testAssignOperator != expectedList)
|
||||
|
@@ -318,38 +318,6 @@ int test_map_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename MapType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<std::pair<const int, int>> il
|
||||
= {std::make_pair(1, 2), std::make_pair(3, 4)};
|
||||
const MapType expected(il.begin(), il.end());
|
||||
{
|
||||
const MapType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
const MapType sil_ordered(ordered_unique_range, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
MapType sil_assign = {std::make_pair(99, 100)};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
MapType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
struct boost_container_map;
|
||||
struct boost_container_multimap;
|
||||
|
||||
@@ -460,10 +428,10 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<boost_container_multimap>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<map<int, int> >())
|
||||
if (!boost::container::test::test_map_support_for_initialization_list_for<map<int, int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<multimap<int, int> >())
|
||||
if (!boost::container::test::test_map_support_for_initialization_list_for<multimap<int, int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
|
@@ -663,6 +663,76 @@ int map_test()
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
template<typename MapType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<std::pair<const int, int>> il
|
||||
= {std::make_pair(1, 2), std::make_pair(3, 4)};
|
||||
const MapType expected(il.begin(), il.end());
|
||||
{
|
||||
const MapType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
const MapType sil_ordered(ordered_unique_range, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
MapType sil_assign = {std::make_pair(99, 100)};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
MapType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
template<typename MapType>
|
||||
bool test_map_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
const std::initializer_list<std::pair<typename MapType::value_type::first_type, typename MapType::mapped_type>> il
|
||||
= { std::make_pair(1, 2), std::make_pair(3, 4) };
|
||||
|
||||
const MapType expected(il.begin(), il.end());
|
||||
{
|
||||
const MapType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
MapType sila(il, typename MapType::allocator_type());
|
||||
if (sila != expected)
|
||||
return false;
|
||||
|
||||
const MapType sil_ordered(ordered_unique_range, il);
|
||||
if (sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
MapType sil_assign = { std::make_pair(99, 100) };
|
||||
sil_assign = il;
|
||||
if (sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
MapType sil;
|
||||
sil.insert(il);
|
||||
if (sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} //namespace test{
|
||||
} //namespace container {
|
||||
|
@@ -322,36 +322,7 @@ int test_set_variants()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename SetType>
|
||||
bool test_support_for_initialization_list_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
std::initializer_list<int> il = {1, 2, 3, 4, 5};
|
||||
SetType expected(il.begin(), il.end());
|
||||
{
|
||||
SetType sil = il;
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_ordered(ordered_unique_range, il);
|
||||
if(sil_ordered != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_assign = {99, 100, 101, 102, 103, 104, 105};
|
||||
sil_assign = il;
|
||||
if(sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
SetType sil;
|
||||
sil.insert(il);
|
||||
if(sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
int main ()
|
||||
{
|
||||
//Recursive container instantiation
|
||||
@@ -431,10 +402,10 @@ int main ()
|
||||
if(!boost::container::test::test_propagate_allocator<boost_container_multiset>())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<set<int> >())
|
||||
if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<set<int> >())
|
||||
return 1;
|
||||
|
||||
if(!test_support_for_initialization_list_for<multiset<int> >())
|
||||
if (!boost::container::test::test_set_methods_with_initializer_list_as_argument_for<multiset<int> >())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
|
@@ -705,6 +705,43 @@ int set_test ()
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename SetType>
|
||||
bool test_set_methods_with_initializer_list_as_argument_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
std::initializer_list<int> il = { 1, 2, 3, 4, 5, 5 };
|
||||
std::initializer_list<int> ilu = { 1, 2, 3, 4, 5 };
|
||||
SetType expected(il.begin(), il.end());
|
||||
SetType expectedu(ilu.begin(), ilu.end());
|
||||
{
|
||||
SetType sil((il));
|
||||
if (sil != expected)
|
||||
return false;
|
||||
|
||||
SetType sila(il, typename SetType::allocator_type());
|
||||
if (sila != expected)
|
||||
return false;
|
||||
|
||||
SetType sil_ordered(ordered_unique_range, ilu);
|
||||
if (sil_ordered != expectedu)
|
||||
return false;
|
||||
|
||||
SetType sil_assign = { 99, 100, 101, 102, 103, 104, 105 };
|
||||
sil_assign = il;
|
||||
if (sil_assign != expected)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
SetType sil;
|
||||
sil.insert(il);
|
||||
if (sil != expected)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
} //namespace test{
|
||||
} //namespace container {
|
||||
} //namespace boost{
|
||||
|
@@ -121,7 +121,12 @@ bool test_support_for_initializer_list()
|
||||
if(sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
slist<int> sl({ 1, 2 }, slist<int>::allocator_type());
|
||||
sl = il;
|
||||
if (sl != expected_list)
|
||||
return false;
|
||||
}
|
||||
{
|
||||
slist<int> sl = {4, 5};
|
||||
sl.assign(il);
|
||||
|
@@ -389,12 +389,17 @@ template<typename VectorContainerType>
|
||||
bool test_vector_methods_with_initializer_list_as_argument_for()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
typedef typename VectorContainerType::allocator_type allocator_type;
|
||||
{
|
||||
const VectorContainerType testedVector = {1, 2, 3};
|
||||
const std::vector<int> expectedVector = {1, 2, 3};
|
||||
if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
|
||||
}
|
||||
|
||||
{
|
||||
const VectorContainerType testedVector( { 1, 2, 3 }, allocator_type() );
|
||||
const std::vector<int> expectedVector = {1, 2, 3};
|
||||
if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
|
||||
}
|
||||
{
|
||||
VectorContainerType testedVector = {1, 2, 3};
|
||||
testedVector = {11, 12, 13};
|
||||
|
Reference in New Issue
Block a user