diff --git a/test/Jamfile b/test/Jamfile index 9be1e18..df6197b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -35,6 +35,7 @@ run has_constant_size.cpp ; run get_integral_result.cpp ; run get_integral_result_2.cpp ; run get_integral_result_3.cpp ; +run get_integral_result_4.cpp ; # digest diff --git a/test/get_integral_result_4.cpp b/test/get_integral_result_4.cpp new file mode 100644 index 0000000..caa46c8 --- /dev/null +++ b/test/get_integral_result_4.cpp @@ -0,0 +1,86 @@ +// Copyright 2017, 2018, 2024 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +template void test_identity() +{ + using boost::hash2::get_integral_result; + + using R = T; + + for( unsigned i = 0; i <= std::numeric_limits::max(); ++i ) + { + R r = static_cast( i ); + T t = get_integral_result( r ); + + BOOST_TEST_EQ( t, r ); + } +} + +template void test_permutation( R offset = 0, R scale = 1 ) +{ + using boost::hash2::get_integral_result; + + std::set dist; + + for( unsigned i = 0; i <= std::numeric_limits::max(); ++i ) + { + R r = static_cast( i * scale + offset ); + T t = get_integral_result( r ); + + dist.insert( t ); + } + + BOOST_TEST_EQ( dist.size(), std::numeric_limits::max() + 1u ); +} + +template void test_roundtrip() +{ + using boost::hash2::get_integral_result; + + std::set dist; + + for( unsigned i = 0; i <= std::numeric_limits::max(); ++i ) + { + T t1 = static_cast( i ); + R r = get_integral_result( t1 ); + T t2 = get_integral_result( r ); + + dist.insert( t2 ); + } + + BOOST_TEST_EQ( dist.size(), std::numeric_limits::max() + 1u ); +} + +int main() +{ + test_identity(); + + test_permutation(); + test_permutation(); + test_permutation(); + test_permutation(); + + test_roundtrip(); + test_roundtrip(); + test_roundtrip(); + test_roundtrip(); + + test_identity(); + + test_permutation(); + test_permutation(); + test_permutation(); + + test_roundtrip(); + test_roundtrip(); + test_roundtrip(); + + return boost::report_errors(); +}