• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
tests(X *,test::random_generator generator)28   template <class X> void tests(X*, test::random_generator generator)
29   {
30     test::check_instances check_;
31 
32     typedef typename X::size_type size_type;
33     typedef 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 (typename test::random_values<X>::const_iterator it = v.begin(),
45                                                          end = v.end();
46          it != end; ++it) {
47       size_type bucket = x.bucket(test::get_key<X>(*it));
48 
49       BOOST_TEST(bucket < x.bucket_count());
50       if (bucket < x.bucket_count()) {
51         // lit? lend?? I need a new naming scheme.
52         const_local_iterator lit = x.begin(bucket), lend = x.end(bucket);
53         while (lit != lend && test::get_key<X>(*it) != test::get_key<X>(*lit)) {
54           ++lit;
55         }
56         BOOST_TEST(lit != lend);
57       }
58     }
59 
60     for (size_type i = 0; i < x.bucket_count(); ++i) {
61       BOOST_TEST(x.bucket_size(i) ==
62                  static_cast<size_type>(std::distance(x.begin(i), x.end(i))));
63       BOOST_TEST(x.bucket_size(i) ==
64                  static_cast<size_type>(std::distance(x.cbegin(i), x.cend(i))));
65       X const& x_ref = x;
66       BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(std::distance(
67                                        x_ref.begin(i), x_ref.end(i))));
68       BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(std::distance(
69                                        x_ref.cbegin(i), x_ref.cend(i))));
70     }
71   }
72 
73   boost::unordered_multimap<test::object, test::object, test::hash,
74     test::equal_to, std::allocator<test::object> >* test_multimap_std_alloc;
75 
76   boost::unordered_set<test::object, test::hash, test::equal_to,
77     test::allocator2<test::object> >* test_set;
78   boost::unordered_multiset<test::object, test::hash, test::equal_to,
79     test::allocator1<test::object> >* test_multiset;
80   boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
81     test::allocator1<test::object> >* test_map;
82   boost::unordered_multimap<test::object, test::object, test::hash,
83     test::equal_to, test::allocator2<test::object> >* test_multimap;
84 
85   using test::default_generator;
86   using test::generate_collisions;
87   using test::limited_range;
88 
89   UNORDERED_TEST(tests,
90     ((test_multimap_std_alloc)(test_set)(test_multiset)(test_map)(
91       test_multimap))((default_generator)(generate_collisions)(limited_range)))
92 }
93 
94 RUN_TESTS()
95