diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bd6efa0..85ca612 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -116,6 +116,8 @@ run described_class_test.cpp run hash_is_avalanching_test.cpp ; run hash_is_avalanching_test2.cpp ; +run hash_integral_test2.cpp ; + run hash_nullptr_test.cpp ; run is_tuple_like_test.cpp ; diff --git a/test/hash_integral_test.cpp b/test/hash_integral_test.cpp index dac6324..baa35d1 100644 --- a/test/hash_integral_test.cpp +++ b/test/hash_integral_test.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #if defined(BOOST_MSVC) #pragma warning(disable: 4127) // conditional expression is constant diff --git a/test/hash_integral_test2.cpp b/test/hash_integral_test2.cpp new file mode 100644 index 0000000..19ef99a --- /dev/null +++ b/test/hash_integral_test2.cpp @@ -0,0 +1,52 @@ +// Copyright 2005-2009 Daniel James. +// Copyright 2021 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include +#include + +// This test checks that values representable in a signed +// and the corresponding unsigned type hash to the same value + +template +void signed_unsigned_test() +{ + BOOST_STATIC_ASSERT( boost::is_signed::value ); + + typedef typename boost::make_unsigned::type U; + + T x = std::numeric_limits::max(); + + do + { + BOOST_TEST_EQ( boost::hash()( x ), boost::hash()( static_cast( x ) ) ); + x /= 3; + } + while( x > 0 ); +} + +#define TEST(type) std::cerr << "Testing: " #type " (" << boost::core::type_name() << ")\n"; signed_unsigned_test(); + +int main() +{ + TEST(signed char) + TEST(short) + TEST(int) + TEST(long) + +#if !defined(BOOST_NO_LONG_LONG) + TEST(boost::long_long_type) +#endif + +#if defined(BOOST_HAS_INT128) + TEST(boost::int128_type) +#endif + + return boost::report_errors(); +}