Add test/unordered/mix_policy.cpp

This commit is contained in:
Peter Dimov
2022-01-18 20:17:31 +02:00
parent d6576ed2f1
commit 5c3576c7c6
2 changed files with 47 additions and 0 deletions

View File

@ -65,6 +65,7 @@ test-suite unordered
[ run unordered/transparent_tests.cpp ]
[ run unordered/reserve_tests.cpp ]
[ run unordered/contains_tests.cpp ]
[ run unordered/mix_policy.cpp ]
[ run unordered/compile_set.cpp : :
: <define>BOOST_UNORDERED_USE_MOVE

View File

@ -0,0 +1,46 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/unordered/detail/implementation.hpp>
#include <boost/core/bit.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/cstdint.hpp>
template<class Policy, class SizeT> void test( SizeT x )
{
if( x <= 4 )
{
BOOST_TEST_EQ( Policy::new_bucket_count( x ), 4 );
}
else
{
BOOST_TEST_EQ( Policy::new_bucket_count( x ), boost::core::bit_ceil( x ) );
}
BOOST_TEST_EQ( Policy::prev_bucket_count( x ), boost::core::bit_floor( x ) );
}
int main()
{
{
typedef boost::uint64_t SizeT;
typedef boost::unordered::detail::mix64_policy<SizeT> policy;
for( SizeT i = 1; i < 200; ++i )
{
test<policy>( i );
}
for( int i = 8; i < 64; ++i )
{
SizeT x = SizeT( 1 ) << i;
test<policy>( x - 1 );
test<policy>( x );
test<policy>( x + 1 );
}
}
return boost::report_errors();
}