From 2ee17d108ef7637533e7ea869fa768c43c3dbf80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 4 Jun 2015 11:41:29 +0200 Subject: [PATCH] Add capacity-related tests --- test/vector_test.hpp | 79 ++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/test/vector_test.hpp b/test/vector_test.hpp index 6662d84..eee6374 100644 --- a/test/vector_test.hpp +++ b/test/vector_test.hpp @@ -42,6 +42,52 @@ namespace boost{ namespace container { namespace test{ +template +struct vector_hash_function_capacity +{ + typedef typename Vector::size_type size_type; + template struct Check; + template static char func(Check *); + template static int func(...); + + public: + static const bool value = sizeof(func(0)) == sizeof(char); +}; + +template +bool vector_vector_hash_function_capacity_only(V1&, V2&, boost::container::container_detail::false_type) +{ + return true; +} + +template +bool vector_vector_hash_function_capacity_only(MyBoostVector&boostvector, MyStdVector&stdvector, boost::container::container_detail::true_type) +{ + //deque has no reserve + boostvector.reserve(boostvector.size()*2); + stdvector.reserve(stdvector.size()*2); + if(!test::CheckEqualContainers(boostvector, stdvector)) return false; + + std::size_t cap = boostvector.capacity(); + boostvector.reserve(cap*2); + stdvector.reserve(cap*2); + if(!test::CheckEqualContainers(boostvector, stdvector)) return false; + boostvector.resize(0); + stdvector.resize(0); + if(!test::CheckEqualContainers(boostvector, stdvector)) return false; + + boostvector.resize(cap*2); + stdvector.resize(cap*2); + if(!test::CheckEqualContainers(boostvector, stdvector)) return false; + + boostvector.resize(cap*2); + stdvector.resize(cap*2); + if(!test::CheckEqualContainers(boostvector, stdvector)) return false; + + return true; +} + + template bool vector_copyable_only(V1&, V2&, boost::container::container_detail::false_type) { @@ -263,11 +309,7 @@ int vector_test() stdvector.insert(stdvector.begin() + old_size/2, aux_vect2, aux_vect2 + 50); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } -/* //deque has no reserve - boostvector.reserve(boostvector.size()*2); - stdvector.reserve(stdvector.size()*2); - if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; -*/ + boostvector.shrink_to_fit(); MyStdVector(stdvector).swap(stdvector); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; @@ -353,33 +395,20 @@ 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)) + + if(!vector_vector_hash_function_capacity_only(boostvector, stdvector, container_detail::bool_::value>())) return 1; -/* deque has no reserve or capacity - std::size_t cap = boostvector.capacity(); - boostvector.reserve(cap*2); - stdvector.reserve(cap*2); - if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; - boostvector.resize(0); - stdvector.resize(0); - if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; - - boostvector.resize(cap*2); - stdvector.resize(cap*2); - if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; boostvector.clear(); stdvector.clear(); boostvector.shrink_to_fit(); MyStdVector(stdvector).swap(stdvector); - if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; + if(!test::CheckEqualContainers(boostvector, stdvector)) return false; + + boostvector.resize(100); + if(!test_nth_index_of(boostvector)) + return 1; - boostvector.resize(cap*2); - stdvector.resize(cap*2); - if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; -*/ } std::cout << std::endl << "Test OK!" << std::endl; return 0;