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)
7 #include "../helpers/prefix.hpp"
8 #include <boost/unordered_set.hpp>
9 #include <boost/unordered_map.hpp>
10 #include "../helpers/postfix.hpp"
13 #include "../helpers/test.hpp"
15 #include "../objects/test.hpp"
16 #include "../helpers/random_values.hpp"
17 #include "../helpers/helpers.hpp"
19 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
20 #pragma warning(disable : 4267) // conversion from 'size_t' to 'unsigned int',
21 // possible loss of data.
24 namespace bucket_tests
{
26 test::seed_t
initialize_seed(54635);
28 template <class X
> void tests(X
*, test::random_generator generator
)
30 test::check_instances check_
;
32 typedef BOOST_DEDUCED_TYPENAME
X::size_type size_type
;
33 typedef BOOST_DEDUCED_TYPENAME
X::const_local_iterator const_local_iterator
;
34 test::random_values
<X
> v(1000, generator
);
36 X
x(v
.begin(), v
.end());
38 BOOST_TEST(x
.bucket_count() <= x
.max_bucket_count());
39 if (!(x
.bucket_count() <= x
.max_bucket_count())) {
40 BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< x
.bucket_count()
41 << "<=" << x
.max_bucket_count() << "\n";
44 for (BOOST_DEDUCED_TYPENAME
test::random_values
<X
>::const_iterator
48 size_type bucket
= x
.bucket(test::get_key
<X
>(*it
));
50 BOOST_TEST(bucket
< x
.bucket_count());
51 if (bucket
< x
.bucket_count()) {
52 // lit? lend?? I need a new naming scheme.
53 const_local_iterator lit
= x
.begin(bucket
), lend
= x
.end(bucket
);
54 while (lit
!= lend
&& test::get_key
<X
>(*it
) != test::get_key
<X
>(*lit
)) {
57 BOOST_TEST(lit
!= lend
);
61 for (size_type i
= 0; i
< x
.bucket_count(); ++i
) {
62 BOOST_TEST(x
.bucket_size(i
) ==
63 static_cast<size_type
>(std::distance(x
.begin(i
), x
.end(i
))));
64 BOOST_TEST(x
.bucket_size(i
) ==
65 static_cast<size_type
>(std::distance(x
.cbegin(i
), x
.cend(i
))));
67 BOOST_TEST(x
.bucket_size(i
) == static_cast<size_type
>(std::distance(
68 x_ref
.begin(i
), x_ref
.end(i
))));
69 BOOST_TEST(x
.bucket_size(i
) == static_cast<size_type
>(std::distance(
70 x_ref
.cbegin(i
), x_ref
.cend(i
))));
74 boost::unordered_multimap
<test::object
, test::object
, test::hash
,
75 test::equal_to
, std::allocator
<test::object
> >* test_multimap_std_alloc
;
77 boost::unordered_set
<test::object
, test::hash
, test::equal_to
,
78 test::allocator2
<test::object
> >* test_set
;
79 boost::unordered_multiset
<test::object
, test::hash
, test::equal_to
,
80 test::allocator1
<test::object
> >* test_multiset
;
81 boost::unordered_map
<test::object
, test::object
, test::hash
, test::equal_to
,
82 test::allocator1
<test::object
> >* test_map
;
83 boost::unordered_multimap
<test::object
, test::object
, test::hash
,
84 test::equal_to
, test::allocator2
<test::object
> >* test_multimap
;
86 using test::default_generator
;
87 using test::generate_collisions
;
88 using test::limited_range
;
91 ((test_multimap_std_alloc
)(test_set
)(test_multiset
)(test_map
)(
92 test_multimap
))((default_generator
)(generate_collisions
)(limited_range
)))