From 5c3576c7c6756b5791de0cb2dd4d7a9673a056ef Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 18 Jan 2022 20:17:31 +0200 Subject: [PATCH] Add test/unordered/mix_policy.cpp --- test/Jamfile.v2 | 1 + test/unordered/mix_policy.cpp | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/unordered/mix_policy.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d2573d20..560d92ad 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 : : : BOOST_UNORDERED_USE_MOVE diff --git a/test/unordered/mix_policy.cpp b/test/unordered/mix_policy.cpp new file mode 100644 index 00000000..87cd7b8c --- /dev/null +++ b/test/unordered/mix_policy.cpp @@ -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 +#include +#include +#include + +template 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 policy; + + for( SizeT i = 1; i < 200; ++i ) + { + test( i ); + } + + for( int i = 8; i < 64; ++i ) + { + SizeT x = SizeT( 1 ) << i; + + test( x - 1 ); + test( x ); + test( x + 1 ); + } + } + + return boost::report_errors(); +}