2
// Copyright 2006-2009 Daniel James.
3
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
#include "../helpers/prefix.hpp"
8
#include <boost/unordered_set.hpp>
9
#include <boost/unordered_map.hpp>
10
#include "../helpers/test.hpp"
12
#include "../objects/test.hpp"
13
#include "../helpers/random_values.hpp"
14
#include "../helpers/helpers.hpp"
16
#if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
17
#pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int',
18
// possible loss of data.
21
namespace bucket_tests {
23
test::seed_t seed(54635);
26
void tests(X* = 0, test::random_generator generator = test::default_generator)
28
test::check_instances check_;
30
typedef BOOST_DEDUCED_TYPENAME X::size_type size_type;
31
typedef BOOST_DEDUCED_TYPENAME X::const_local_iterator const_local_iterator;
32
test::random_values<X> v(1000, generator);
34
X x(v.begin(), v.end());
36
BOOST_TEST(x.bucket_count() < x.max_bucket_count());
37
std::cerr<<x.bucket_count()<<"<"<<x.max_bucket_count()<<"\n";
39
for(BOOST_DEDUCED_TYPENAME test::random_values<X>::const_iterator
40
it = v.begin(), end = v.end(); it != end; ++it)
42
size_type bucket = x.bucket(test::get_key<X>(*it));
44
BOOST_TEST(bucket < x.bucket_count());
45
if(bucket < x.max_bucket_count()) {
46
// lit? lend?? I need a new naming scheme.
47
const_local_iterator lit = x.begin(bucket), lend = x.end(bucket);
49
&& test::get_key<X>(*it) != test::get_key<X>(*lit))
53
BOOST_TEST(lit != lend);
57
for(size_type i = 0; i < x.bucket_count(); ++i) {
58
BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
59
std::distance(x.begin(i), x.end(i))));
60
BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
61
std::distance(x.cbegin(i), x.cend(i))));
63
BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
64
std::distance(x_ref.begin(i), x_ref.end(i))));
65
BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
66
std::distance(x_ref.cbegin(i), x_ref.cend(i))));
70
boost::unordered_set<test::object,
71
test::hash, test::equal_to,
72
test::allocator<test::object> >* test_set;
73
boost::unordered_multiset<test::object,
74
test::hash, test::equal_to,
75
test::allocator<test::object> >* test_multiset;
76
boost::unordered_map<test::object, test::object,
77
test::hash, test::equal_to,
78
test::allocator<test::object> >* test_map;
79
boost::unordered_multimap<test::object, test::object,
80
test::hash, test::equal_to,
81
test::allocator<test::object> >* test_multimap;
83
UNORDERED_TEST(tests, ((test_set)(test_multiset)(test_map)(test_multimap)))