Files
boost_container_hash/test/hash_custom_test.cpp
T
Daniel James 2d91127422 Removes uses of BOOST_CHECK_EQUAL from the hash tests as they don't work on Borland.
Also force a failure on the float tests on borland as they are crashing horribly. Hopefully I should be able to fix this and remove this.

Also use pair's constructor in hash_map_test.hpp instead of make_pair so that the correct type is created.


[SVN r28049]
2005-04-07 20:53:20 +00:00

60 lines
1.3 KiB
C++

// (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)
#include <boost/functional/hash/hash.hpp>
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#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
{
std::size_t hash_value(test::custom x)
{
return x.hash();
}
}
BOOST_AUTO_UNIT_TEST(custom_tests)
{
boost::hash<test::custom> custom_hasher;
BOOST_CHECK(custom_hasher(10) == 100u);
test::custom x(55);
BOOST_CHECK(custom_hasher(x) == 550u);
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;
boost::hash_combine(seed, test::custom(5));
boost::hash_combine(seed, test::custom(25));
boost::hash_combine(seed, test::custom(35));
BOOST_CHECK(seed ==
boost::hash_range(custom_vector.begin(), custom_vector.end()));
}