2005-04-01 16:58:09 +00:00
|
|
|
|
|
|
|
// (C) Copyright Daniel James 2005.
|
|
|
|
// 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)
|
|
|
|
|
2005-04-07 21:57:22 +00:00
|
|
|
#include "./config.hpp"
|
|
|
|
|
|
|
|
#ifdef TEST_EXTENSIONS
|
|
|
|
# ifdef TEST_STD_INCLUDES
|
|
|
|
# include <functional>
|
|
|
|
# else
|
|
|
|
# include <boost/functional/hash/hash.hpp>
|
|
|
|
# endif
|
|
|
|
#endif
|
2005-04-01 16:58:09 +00:00
|
|
|
|
|
|
|
#define BOOST_AUTO_TEST_MAIN
|
|
|
|
#include <boost/test/auto_unit_test.hpp>
|
|
|
|
|
2005-04-07 21:57:22 +00:00
|
|
|
#ifdef TEST_EXTENSIONS
|
|
|
|
|
2005-04-01 16:58:09 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <cctype>
|
|
|
|
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
struct custom
|
|
|
|
{
|
|
|
|
int value_;
|
|
|
|
|
|
|
|
custom(int x) : value_(x) {}
|
|
|
|
std::size_t hash() const { return value_ * 10; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
|
|
|
namespace test
|
|
|
|
#else
|
|
|
|
namespace boost
|
|
|
|
#endif
|
|
|
|
{
|
2005-04-01 22:47:36 +00:00
|
|
|
std::size_t hash_value(test::custom x)
|
2005-04-01 16:58:09 +00:00
|
|
|
{
|
|
|
|
return x.hash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_UNIT_TEST(custom_tests)
|
|
|
|
{
|
2005-04-07 21:57:22 +00:00
|
|
|
HASH_NAMESPACE::hash<test::custom> custom_hasher;
|
2005-04-07 20:53:20 +00:00
|
|
|
BOOST_CHECK(custom_hasher(10) == 100u);
|
2005-04-01 16:58:09 +00:00
|
|
|
test::custom x(55);
|
2005-04-07 20:53:20 +00:00
|
|
|
BOOST_CHECK(custom_hasher(x) == 550u);
|
2005-04-01 16:58:09 +00:00
|
|
|
|
|
|
|
std::vector<test::custom> custom_vector;
|
|
|
|
custom_vector.push_back(5);
|
|
|
|
custom_vector.push_back(25);
|
|
|
|
custom_vector.push_back(35);
|
|
|
|
|
|
|
|
std::size_t seed = 0;
|
2005-04-07 21:57:22 +00:00
|
|
|
HASH_NAMESPACE::hash_combine(seed, test::custom(5));
|
|
|
|
HASH_NAMESPACE::hash_combine(seed, test::custom(25));
|
|
|
|
HASH_NAMESPACE::hash_combine(seed, test::custom(35));
|
2005-04-01 16:58:09 +00:00
|
|
|
|
2005-04-07 20:53:20 +00:00
|
|
|
BOOST_CHECK(seed ==
|
2005-04-07 21:57:22 +00:00
|
|
|
HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end()));
|
2005-04-01 16:58:09 +00:00
|
|
|
}
|
|
|
|
|
2005-04-07 21:57:22 +00:00
|
|
|
#endif // TEST_EXTENSIONS
|