]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/unordered/test/unordered/bucket_tests.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / unordered / test / unordered / bucket_tests.cpp
1
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)
5
6 // clang-format off
7 #include "../helpers/prefix.hpp"
8 #include <boost/unordered_set.hpp>
9 #include <boost/unordered_map.hpp>
10 #include "../helpers/postfix.hpp"
11 // clang-format on
12
13 #include "../helpers/test.hpp"
14 #include <algorithm>
15 #include "../objects/test.hpp"
16 #include "../helpers/random_values.hpp"
17 #include "../helpers/helpers.hpp"
18
19 #if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
20 #pragma warning(disable : 4267) // conversion from 'size_t' to 'unsigned int',
21 // possible loss of data.
22 #endif
23
24 namespace bucket_tests {
25
26 test::seed_t initialize_seed(54635);
27
28 template <class X> void tests(X*, test::random_generator generator)
29 {
30 test::check_instances check_;
31
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);
35
36 X x(v.begin(), v.end());
37
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";
42 }
43
44 for (BOOST_DEDUCED_TYPENAME test::random_values<X>::const_iterator
45 it = v.begin(),
46 end = v.end();
47 it != end; ++it) {
48 size_type bucket = x.bucket(test::get_key<X>(*it));
49
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)) {
55 ++lit;
56 }
57 BOOST_TEST(lit != lend);
58 }
59 }
60
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))));
66 X const& x_ref = x;
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))));
71 }
72 }
73
74 boost::unordered_multimap<test::object, test::object, test::hash,
75 test::equal_to, std::allocator<test::object> >* test_multimap_std_alloc;
76
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;
85
86 using test::default_generator;
87 using test::generate_collisions;
88 using test::limited_range;
89
90 UNORDERED_TEST(tests,
91 ((test_multimap_std_alloc)(test_set)(test_multiset)(test_map)(
92 test_multimap))((default_generator)(generate_collisions)(limited_range)))
93 }
94
95 RUN_TESTS()