mirror of
https://github.com/boostorg/container_hash.git
synced 2026-02-23 15:42:18 +00:00
Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
// Copyright Daniel James 2005-2006. Use, modification, and distribution are
|
||||
// subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Copyright 2005-2007 Daniel James.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "./config.hpp"
|
||||
|
||||
@@ -21,6 +21,13 @@
|
||||
|
||||
#include "./compile_time.hpp"
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127) // conditional expression is constant
|
||||
#pragma warning(disable:4309) // truncation of constant value
|
||||
#pragma warning(disable:4310) // cast truncates constant value
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
void numeric_test(T*)
|
||||
{
|
||||
@@ -31,7 +38,7 @@ void numeric_test(T*)
|
||||
HASH_NAMESPACE::hash<T> x1;
|
||||
HASH_NAMESPACE::hash<T> x2;
|
||||
|
||||
T v1 = -5;
|
||||
T v1 = (T) -5;
|
||||
BOOST_TEST(x1(v1) == x2(v1));
|
||||
BOOST_TEST(x1(T(-5)) == x2(T(-5)));
|
||||
BOOST_TEST(x1(T(0)) == x2(T(0)));
|
||||
@@ -48,7 +55,8 @@ void numeric_test(T*)
|
||||
|
||||
if (limits::is_integer)
|
||||
{
|
||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(-5)) == (std::size_t)T(-5));
|
||||
if(limits::is_signed || limits::digits <= std::numeric_limits<std::size_t>::digits)
|
||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(-5)) == (std::size_t)T(-5));
|
||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(0)) == (std::size_t)T(0u));
|
||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(10)) == (std::size_t)T(10u));
|
||||
BOOST_TEST(HASH_NAMESPACE::hash_value(T(25)) == (std::size_t)T(25u));
|
||||
@@ -105,16 +113,29 @@ void poor_quality_tests(T*)
|
||||
BOOST_TEST(x1((limits::max)()) != x2((limits::max)() - 1));
|
||||
}
|
||||
|
||||
void bool_test()
|
||||
{
|
||||
HASH_NAMESPACE::hash<bool> x1;
|
||||
HASH_NAMESPACE::hash<bool> x2;
|
||||
|
||||
BOOST_TEST(x1(true) == x2(true));
|
||||
BOOST_TEST(x1(false) == x2(false));
|
||||
BOOST_TEST(x1(true) != x2(false));
|
||||
BOOST_TEST(x1(false) != x2(true));
|
||||
}
|
||||
|
||||
#define NUMERIC_TEST(type, name) \
|
||||
std::cerr<<"Testing: " BOOST_STRINGIZE(name) "\n"; \
|
||||
numeric_test((type*) 0); \
|
||||
limits_test((type*) 0); \
|
||||
poor_quality_tests((type*) 0);
|
||||
#define NUMERIC_TEST_NO_LIMITS(type, name) \
|
||||
std::cerr<<"Testing: " BOOST_STRINGIZE(name) "\n"; \
|
||||
numeric_test((type*) 0); \
|
||||
poor_quality_tests((type*) 0);
|
||||
|
||||
int main()
|
||||
{
|
||||
NUMERIC_TEST(bool, bool)
|
||||
NUMERIC_TEST(char, char)
|
||||
NUMERIC_TEST(signed char, schar)
|
||||
NUMERIC_TEST(unsigned char, uchar)
|
||||
@@ -128,11 +149,19 @@ int main()
|
||||
NUMERIC_TEST(long, hash_long)
|
||||
NUMERIC_TEST(unsigned long, ulong)
|
||||
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
NUMERIC_TEST_NO_LIMITS(long long, hash_longlong)
|
||||
NUMERIC_TEST_NO_LIMITS(unsigned long long, ulonglong)
|
||||
#endif
|
||||
|
||||
NUMERIC_TEST(float, float)
|
||||
NUMERIC_TEST(double, double)
|
||||
NUMERIC_TEST(long double, ldouble)
|
||||
|
||||
bool_test();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user