From e68f0c341ef869d0bcf6fde368b8f12860edce12 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 6 Sep 2012 08:49:43 +0000 Subject: [PATCH] Unordered: Fix object counts in tests. [SVN r80417] --- test/helpers/random_values.hpp | 9 ++++----- test/unordered/move_tests.cpp | 12 ++++++++---- test/unordered/rehash_tests.cpp | 7 ++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/helpers/random_values.hpp b/test/helpers/random_values.hpp index 66ffaa3e..46eeb392 100644 --- a/test/helpers/random_values.hpp +++ b/test/helpers/random_values.hpp @@ -35,11 +35,11 @@ namespace test int* int_ptr = 0; len += x.size(); - while(x.size() < len) { + for (std::size_t i = 0; i < len; ++i) { value_type value = generate(value_ptr); int count = type_ == generate_collisions ? - 1 + (generate(int_ptr) % 10) : 1; + 1 + (generate(int_ptr) % 5) : 1; for(int i = 0; i < count; ++i) { x.push_back(value); @@ -64,13 +64,12 @@ namespace test key_type* key_ptr = 0; mapped_type* mapped_ptr = 0; int* int_ptr = 0; - len += x.size(); - while(x.size() < len) { + for (std::size_t i = 0; i < len; ++i) { key_type key = generate(key_ptr); int count = type_ == generate_collisions ? - 1 + (generate(int_ptr) % 10) : 1; + 1 + (generate(int_ptr) % 5) : 1; for(int i = 0; i < count; ++i) { x.push_back(std::pair( diff --git a/test/unordered/move_tests.cpp b/test/unordered/move_tests.cpp index 35e331ea..8866f826 100644 --- a/test/unordered/move_tests.cpp +++ b/test/unordered/move_tests.cpp @@ -158,13 +158,17 @@ namespace move_tests BOOST_TEST(count == test::global_object_count); #elif defined(BOOST_HAS_NRVO) BOOST_TEST( - test::global_object_count.constructions - count.constructions <= - (test::is_set::value ? 25 : 50)); + static_cast(test::global_object_count.constructions + - count.constructions) <= + (test::is_set::value ? 1 : 2) * + (test::has_unique_keys::value ? 25 : v.size())); BOOST_TEST(count.instances == test::global_object_count.instances); #else BOOST_TEST( - test::global_object_count.constructions - count.constructions <= - (test::is_set::value ? 50 : 100)); + static_cast(test::global_object_count.constructions + - count.constructions) <= + (test::is_set::value ? 2 : 4) * + (test::has_unique_keys::value ? 25 : v.size())); BOOST_TEST(count.instances == test::global_object_count.instances); #endif test::check_container(y, v); diff --git a/test/unordered/rehash_tests.cpp b/test/unordered/rehash_tests.cpp index 93cb5803..c77115b5 100644 --- a/test/unordered/rehash_tests.cpp +++ b/test/unordered/rehash_tests.cpp @@ -11,6 +11,7 @@ #include "../helpers/test.hpp" #include "../helpers/random_values.hpp" #include "../helpers/tracker.hpp" +#include "../helpers/metafunctions.hpp" namespace rehash_tests { @@ -115,7 +116,7 @@ void reserve_test1(X*, test::random_generator generator) // For the current standard this should reserve i+1, I've // submitted a defect report and will assume it's a defect // for now. - x.reserve(v.size()); + x.reserve(test::has_unique_keys::value ? i : v.size()); // Insert an element before the range insert, otherwise there are // no iterators to invalidate in the range insert, and it can @@ -148,9 +149,9 @@ void reserve_test2(X*, test::random_generator generator) x.max_load_factor(random_mlf ? static_cast(std::rand() % 1000) / 500.0f + 0.5f : 1.0f); - x.reserve(v.size()); - std::size_t bucket_count = x.bucket_count(); + x.reserve(test::has_unique_keys::value ? i : v.size()); + std::size_t bucket_count = x.bucket_count(); for (typename test::random_values::iterator it = v.begin(); it != v.end(); ++it) {