Files
boost_container_hash/test/hash_custom_test.cpp
Daniel James bd9c0e53d7 Use Boost.Test's minimal test library for unordered & hash. It's closer to
Boster.Test which makes it easier to switch to take advantage of Boost.Test's
extra testing facilities.

Merged revisions 44420 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk

........
  r44420 | danieljames | 2008-04-14 19:02:03 +0100 (Mon, 14 Apr 2008) | 1 line
  
  Use Boost.Test's minimal test library.
........


[SVN r44487]
2008-04-17 07:39:24 +00:00

100 lines
2.1 KiB
C++

// Copyright 2005-2008 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 <boost/config.hpp>
#include <cstddef>
namespace test
{
struct custom
{
int value_;
std::size_t hash() const
{
return value_ * 10;
}
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
friend std::size_t hash_value(custom const& x )
{
return x.hash();
}
#endif
custom(int x) : value_(x) {}
};
}
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace boost
{
std::size_t hash_value(test::custom x)
{
return x.hash();
}
}
#endif
#include "./config.hpp"
#ifdef TEST_EXTENSIONS
# ifdef TEST_STD_INCLUDES
# include <functional>
# else
# include <boost/functional/hash.hpp>
# endif
#endif
#include <boost/test/minimal.hpp>
#ifdef TEST_EXTENSIONS
#include <vector>
#include <string>
#include <cctype>
void custom_tests()
{
HASH_NAMESPACE::hash<test::custom> custom_hasher;
BOOST_CHECK(custom_hasher(10) == 100u);
test::custom x(55);
BOOST_CHECK(custom_hasher(x) == 550u);
{
using namespace HASH_NAMESPACE;
BOOST_CHECK(custom_hasher(x) == hash_value(x));
}
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;
HASH_NAMESPACE::hash_combine(seed, test::custom(5));
HASH_NAMESPACE::hash_combine(seed, test::custom(25));
HASH_NAMESPACE::hash_combine(seed, test::custom(35));
std::size_t seed2 = 0;
HASH_NAMESPACE::hash_combine(seed2, 50u);
HASH_NAMESPACE::hash_combine(seed2, 250u);
HASH_NAMESPACE::hash_combine(seed2, 350u);
BOOST_CHECK(seed ==
HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end()));
BOOST_CHECK(seed == seed2);
}
#endif // TEST_EXTENSIONS
int test_main(int, char**)
{
#ifdef TEST_EXTENSIONS
custom_tests();
#endif
return 0;
}