mirror of
https://github.com/boostorg/unordered.git
synced 2025-05-11 13:34:06 +00:00
Update tests for standard changes involving bucket count.
It seems my defect report was accepted at some point, and they tweaked the requirements involving bucket counts. This also makes it possible to have a bucket count of 0, which I think wasn't allowed in the past. I don't think I'll change this implementation to do so, but I'd like to be able to run these tests against standard implementations, so I'm starting to take that into account. I believe these changes were made after the C++14 standard, but I've always been tracking the draft standards, so that doesn't really matter.
This commit is contained in:
parent
0d6e58d9fd
commit
1c606980ec
@ -130,6 +130,7 @@ struct insert_test_rehash1 : public insert_test_base<T>
|
||||
|
||||
T x;
|
||||
x.max_load_factor(0.25);
|
||||
// TODO: This doesn't really work is bucket_count is 0
|
||||
size_type bucket_count = x.bucket_count();
|
||||
size_type initial_elements = static_cast<size_type>(
|
||||
ceil(bucket_count * (double) x.max_load_factor()) - 1);
|
||||
|
@ -91,7 +91,7 @@ namespace test
|
||||
|
||||
// Check the load factor.
|
||||
|
||||
float load_factor =
|
||||
float load_factor = size == 0 ? 0 :
|
||||
static_cast<float>(size) / static_cast<float>(x1.bucket_count());
|
||||
using namespace std;
|
||||
if(fabs(x1.load_factor() - load_factor) > x1.load_factor() / 64)
|
||||
|
@ -34,8 +34,10 @@ void tests(X*, test::random_generator generator)
|
||||
|
||||
X x(v.begin(), v.end());
|
||||
|
||||
BOOST_TEST(x.bucket_count() < x.max_bucket_count());
|
||||
std::cerr<<x.bucket_count()<<"<"<<x.max_bucket_count()<<"\n";
|
||||
BOOST_TEST(x.bucket_count() <= x.max_bucket_count());
|
||||
if (!(x.bucket_count() <= x.max_bucket_count())) {
|
||||
std::cerr<<x.bucket_count()<<"<="<<x.max_bucket_count()<<"\n";
|
||||
}
|
||||
|
||||
for(BOOST_DEDUCED_TYPENAME test::random_values<X>::const_iterator
|
||||
it = v.begin(), end = v.end(); it != end; ++it)
|
||||
@ -43,7 +45,7 @@ void tests(X*, test::random_generator generator)
|
||||
size_type bucket = x.bucket(test::get_key<X>(*it));
|
||||
|
||||
BOOST_TEST(bucket < x.bucket_count());
|
||||
if(bucket < x.max_bucket_count()) {
|
||||
if(bucket < x.bucket_count()) {
|
||||
// lit? lend?? I need a new naming scheme.
|
||||
const_local_iterator lit = x.begin(bucket), lend = x.end(bucket);
|
||||
while(lit != lend
|
||||
|
@ -55,7 +55,7 @@ void unique_insert_tests1(X*, test::random_generator generator)
|
||||
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ void equivalent_insert_tests1(X*, test::random_generator generator)
|
||||
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ void insert_tests2(X*, test::random_generator generator)
|
||||
BOOST_TEST(*r1 == *r2);
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ void insert_tests2(X*, test::random_generator generator)
|
||||
BOOST_TEST(*r1 == *r2);
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ void insert_tests2(X*, test::random_generator generator)
|
||||
BOOST_TEST(*pos == *r2);
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ void insert_tests2(X*, test::random_generator generator)
|
||||
tracker.insert(*it);
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ void unique_emplace_tests1(X*, test::random_generator generator)
|
||||
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ void equivalent_emplace_tests1(X*, test::random_generator generator)
|
||||
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -382,7 +382,7 @@ void move_emplace_tests(X*, test::random_generator generator)
|
||||
tracker.insert(*it);
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
@ -445,7 +445,7 @@ void map_tests(X*, test::random_generator generator)
|
||||
|
||||
tracker.compare_key(x, *it);
|
||||
|
||||
if(static_cast<double>(x.size()) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(x.size()) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ void insert_test(X*, float mlf, test::random_generator generator)
|
||||
BOOST_DEDUCED_TYPENAME X::size_type old_size = x.size(),
|
||||
old_bucket_count = x.bucket_count();
|
||||
x.insert(*it);
|
||||
if(static_cast<double>(old_size + 1) < b * static_cast<double>(old_bucket_count))
|
||||
if(static_cast<double>(old_size + 1) <= b * static_cast<double>(old_bucket_count))
|
||||
BOOST_TEST(x.bucket_count() == old_bucket_count);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ test::seed_t initialize_seed(2974);
|
||||
template <class X>
|
||||
bool postcondition(X const& x, BOOST_DEDUCED_TYPENAME X::size_type n)
|
||||
{
|
||||
return static_cast<double>(x.bucket_count()) >
|
||||
return static_cast<double>(x.bucket_count()) >=
|
||||
static_cast<double>(x.size()) / x.max_load_factor() &&
|
||||
x.bucket_count() >= n;
|
||||
}
|
||||
@ -149,9 +149,6 @@ void reserve_test1(X*, test::random_generator generator)
|
||||
X x;
|
||||
x.max_load_factor(random_mlf ?
|
||||
static_cast<float>(std::rand() % 1000) / 500.0f + 0.5f : 1.0f);
|
||||
// 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(test::has_unique_keys<X>::value ? i : v.size());
|
||||
|
||||
// Insert an element before the range insert, otherwise there are
|
||||
|
Loading…
x
Reference in New Issue
Block a user