PageRenderTime 22ms CodeModel.GetById 1ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/unordered/test/unordered/bucket_tests.cpp

http://hadesmem.googlecode.com/
C++ | 85 lines | 64 code | 16 blank | 5 comment | 12 complexity | 33c62539c7b1ba069058d78f021d28b3 MD5 | raw file
 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#include "../helpers/prefix.hpp"
 7
 8#include <boost/unordered_set.hpp>
 9#include <boost/unordered_map.hpp>
10#include "../helpers/test.hpp"
11#include <algorithm>
12#include "../objects/test.hpp"
13#include "../helpers/random_values.hpp"
14#include "../helpers/helpers.hpp"
15
16#if BOOST_WORKAROUND(BOOST_MSVC, < 1400)
17#pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int',
18                              // possible loss of data.
19#endif
20
21namespace bucket_tests {
22
23test::seed_t seed(54635);
24
25template <class X>
26void tests(X* = 0, test::random_generator generator = test::default_generator)
27{
28    typedef BOOST_DEDUCED_TYPENAME X::size_type size_type;
29    typedef BOOST_DEDUCED_TYPENAME X::const_local_iterator const_local_iterator;
30    test::random_values<X> v(1000, generator);
31
32    X x(v.begin(), v.end());
33
34    BOOST_TEST(x.bucket_count() < x.max_bucket_count());
35    std::cerr<<x.bucket_count()<<"<"<<x.max_bucket_count()<<"\n";
36
37    for(BOOST_DEDUCED_TYPENAME test::random_values<X>::const_iterator
38            it = v.begin(), end = v.end(); it != end; ++it)
39    {
40        size_type bucket = x.bucket(test::get_key<X>(*it));
41
42        BOOST_TEST(bucket < x.bucket_count());
43        if(bucket < x.max_bucket_count()) {
44            // lit? lend?? I need a new naming scheme.
45            const_local_iterator lit = x.begin(bucket), lend = x.end(bucket);
46            while(lit != lend
47                && test::get_key<X>(*it) != test::get_key<X>(*lit))
48            {
49                ++lit;
50            }
51            BOOST_TEST(lit != lend);
52        }
53    }
54
55    for(size_type i = 0; i < x.bucket_count(); ++i) {
56        BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
57                std::distance(x.begin(i), x.end(i))));
58        BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
59                std::distance(x.cbegin(i), x.cend(i))));
60        X const& x_ref = x;
61        BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
62                std::distance(x_ref.begin(i), x_ref.end(i))));
63        BOOST_TEST(x.bucket_size(i) == static_cast<size_type>(
64                std::distance(x_ref.cbegin(i), x_ref.cend(i))));
65    }
66}
67
68boost::unordered_set<test::object,
69    test::hash, test::equal_to,
70    test::allocator<test::object> >* test_set;
71boost::unordered_multiset<test::object,
72    test::hash, test::equal_to,
73    test::allocator<test::object> >* test_multiset;
74boost::unordered_map<test::object, test::object,
75    test::hash, test::equal_to,
76    test::allocator<test::object> >* test_map;
77boost::unordered_multimap<test::object, test::object,
78    test::hash, test::equal_to,
79    test::allocator<test::object> >* test_multimap;
80
81UNORDERED_TEST(tests, ((test_set)(test_multiset)(test_map)(test_multimap)))
82
83}
84
85RUN_TESTS()