2006-05-21 17:14:11 +00:00
|
|
|
|
2009-03-09 20:56:23 +00:00
|
|
|
// Copyright 2006-2009 Daniel James.
|
2006-07-01 22:31:26 +00:00
|
|
|
// 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)
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
// clang-format off
|
2009-11-26 23:15:30 +00:00
|
|
|
#include "../helpers/prefix.hpp"
|
2006-05-21 17:14:11 +00:00
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
|
#include <boost/unordered_map.hpp>
|
2012-04-08 15:29:15 +00:00
|
|
|
#include "../helpers/postfix.hpp"
|
2017-02-19 13:05:17 +00:00
|
|
|
// clang-format on
|
2012-04-08 15:29:15 +00:00
|
|
|
|
2008-03-24 17:03:15 +00:00
|
|
|
#include "../helpers/test.hpp"
|
2006-05-21 17:14:11 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include "../objects/test.hpp"
|
|
|
|
|
#include "../helpers/random_values.hpp"
|
|
|
|
|
#include "../helpers/helpers.hpp"
|
|
|
|
|
|
2009-11-26 23:14:53 +00:00
|
|
|
#if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
|
2017-02-19 13:05:17 +00:00
|
|
|
#pragma warning(disable : 4267) // conversion from 'size_t' to 'unsigned int',
|
|
|
|
|
// possible loss of data.
|
2009-11-25 09:14:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
2008-03-24 17:03:15 +00:00
|
|
|
namespace bucket_tests {
|
|
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
test::seed_t initialize_seed(54635);
|
2007-12-06 11:42:28 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
template <class X> void tests(X*, test::random_generator generator)
|
|
|
|
|
{
|
2011-08-14 18:52:43 +00:00
|
|
|
test::check_instances check_;
|
|
|
|
|
|
2018-01-27 09:39:59 +00:00
|
|
|
typedef typename X::size_type size_type;
|
|
|
|
|
typedef typename X::const_local_iterator const_local_iterator;
|
2008-06-01 18:00:53 +00:00
|
|
|
test::random_values<X> v(1000, generator);
|
2006-05-21 17:14:11 +00:00
|
|
|
|
|
|
|
|
X x(v.begin(), v.end());
|
|
|
|
|
|
2016-09-18 12:22:48 +01:00
|
|
|
BOOST_TEST(x.bucket_count() <= x.max_bucket_count());
|
|
|
|
|
if (!(x.bucket_count() <= x.max_bucket_count())) {
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << x.bucket_count()
|
|
|
|
|
<< "<=" << x.max_bucket_count() << "\n";
|
2016-09-18 12:22:48 +01:00
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2018-01-27 09:39:59 +00:00
|
|
|
for (typename test::random_values<X>::const_iterator it = v.begin(),
|
|
|
|
|
end = v.end();
|
2017-02-19 13:05:17 +00:00
|
|
|
it != end; ++it) {
|
2017-06-11 20:55:59 +01:00
|
|
|
size_type bucket = x.bucket(test::get_key<X>(*it));
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_TEST(bucket < x.bucket_count());
|
|
|
|
|
if (bucket < x.bucket_count()) {
|
|
|
|
|
// lit? lend?? I need a new naming scheme.
|
|
|
|
|
const_local_iterator lit = x.begin(bucket), lend = x.end(bucket);
|
|
|
|
|
while (lit != lend && test::get_key<X>(*it) != test::get_key<X>(*lit)) {
|
|
|
|
|
++lit;
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_TEST(lit != lend);
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
for (size_type i = 0; i < x.bucket_count(); ++i) {
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_TEST(x.bucket_size(i) ==
|
|
|
|
|
static_cast<size_type>(std::distance(x.begin(i), x.end(i))));
|
|
|
|
|
BOOST_TEST(x.bucket_size(i) ==
|
|
|
|
|
static_cast<size_type>(std::distance(x.cbegin(i), x.cend(i))));
|
|
|
|
|
X const& x_ref = x;
|
|
|
|
|
BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(std::distance(
|
|
|
|
|
x_ref.begin(i), x_ref.end(i))));
|
|
|
|
|
BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(std::distance(
|
|
|
|
|
x_ref.cbegin(i), x_ref.cend(i))));
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
2017-06-11 20:55:59 +01:00
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multimap<test::object, test::object, test::hash,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::equal_to, std::allocator<test::object> >* test_multimap_std_alloc;
|
2008-03-24 17:03:15 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_set<test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
test::allocator2<test::object> >* test_set;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multiset<test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
test::allocator1<test::object> >* test_multiset;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
|
2012-07-08 11:55:35 +00:00
|
|
|
test::allocator1<test::object> >* test_map;
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_multimap<test::object, test::object, test::hash,
|
2017-02-19 13:05:17 +00:00
|
|
|
test::equal_to, test::allocator2<test::object> >* test_multimap;
|
2012-07-08 11:55:35 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
using test::default_generator;
|
|
|
|
|
using test::generate_collisions;
|
|
|
|
|
using test::limited_range;
|
2012-09-05 23:33:22 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
UNORDERED_TEST(tests,
|
|
|
|
|
((test_multimap_std_alloc)(test_set)(test_multiset)(test_map)(
|
|
|
|
|
test_multimap))((default_generator)(generate_collisions)(limited_range)))
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
2008-03-24 17:03:15 +00:00
|
|
|
|
|
|
|
|
RUN_TESTS()
|