PageRenderTime 38ms CodeModel.GetById 15ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 151 lines | 119 code | 24 blank | 8 comment | 3 complexity | a349fa63ef9ff2af66960585c65b5640 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 "../objects/test.hpp"
 12#include "../helpers/random_values.hpp"
 13#include "../helpers/tracker.hpp"
 14#include "../helpers/equivalent.hpp"
 15#include "../helpers/invariants.hpp"
 16
 17test::seed_t seed(9063);
 18
 19namespace copy_tests
 20{
 21
 22template <class T>
 23void copy_construct_tests1(T*,
 24    test::random_generator const& generator = test::default_generator)
 25{
 26    BOOST_DEDUCED_TYPENAME T::hasher hf;
 27    BOOST_DEDUCED_TYPENAME T::key_equal eq;
 28    BOOST_DEDUCED_TYPENAME T::allocator_type al;
 29
 30    {
 31        T x;
 32        T y(x);
 33        BOOST_TEST(y.empty());
 34        BOOST_TEST(test::equivalent(y.hash_function(), hf));
 35        BOOST_TEST(test::equivalent(y.key_eq(), eq));
 36        BOOST_TEST(test::equivalent(y.get_allocator(), al));
 37        BOOST_TEST(x.max_load_factor() == y.max_load_factor());
 38        test::check_equivalent_keys(y);
 39    }
 40
 41    {
 42        test::random_values<T> v(1000, generator);
 43
 44        T x(v.begin(), v.end());
 45        T y(x);
 46        test::unordered_equivalence_tester<T> equivalent(x);
 47        BOOST_TEST(equivalent(y));
 48        test::check_equivalent_keys(y);
 49    }
 50
 51    {
 52        // In this test I drop the original containers max load factor, so it
 53        // is much lower than the load factor. The hash table is not allowed
 54        // to rehash, but the destination container should probably allocate
 55        // enough buckets to decrease the load factor appropriately.
 56        test::random_values<T> v(1000, generator);
 57        T x(v.begin(), v.end());
 58        x.max_load_factor(x.load_factor() / 4);
 59        T y(x);
 60        test::unordered_equivalence_tester<T> equivalent(x);
 61        BOOST_TEST(equivalent(y));
 62        // This isn't guaranteed:
 63        BOOST_TEST(y.load_factor() < y.max_load_factor());
 64        test::check_equivalent_keys(y);
 65    }
 66}
 67
 68template <class T>
 69void copy_construct_tests2(T* ptr,
 70    test::random_generator const& generator = test::default_generator)
 71{
 72    copy_construct_tests1(ptr);
 73
 74    BOOST_DEDUCED_TYPENAME T::hasher hf(1);
 75    BOOST_DEDUCED_TYPENAME T::key_equal eq(1);
 76    BOOST_DEDUCED_TYPENAME T::allocator_type al(1);
 77    BOOST_DEDUCED_TYPENAME T::allocator_type al2(2);
 78
 79    {
 80        T x(10000, hf, eq, al);
 81        T y(x);
 82        BOOST_TEST(y.empty());
 83        BOOST_TEST(test::equivalent(y.hash_function(), hf));
 84        BOOST_TEST(test::equivalent(y.key_eq(), eq));
 85        BOOST_TEST(test::equivalent(y.get_allocator(), al));
 86        BOOST_TEST(x.max_load_factor() == y.max_load_factor());
 87        test::check_equivalent_keys(y);
 88    }
 89
 90    {
 91        T x(1000, hf, eq, al);
 92        T y(x, al2);
 93        BOOST_TEST(y.empty());
 94        BOOST_TEST(test::equivalent(y.hash_function(), hf));
 95        BOOST_TEST(test::equivalent(y.key_eq(), eq));
 96        BOOST_TEST(test::equivalent(y.get_allocator(), al2));
 97        BOOST_TEST(x.max_load_factor() == y.max_load_factor());
 98        test::check_equivalent_keys(y);
 99    }
100
101    {
102        test::random_values<T> v(1000, generator);
103
104        T x(v.begin(), v.end(), 0, hf, eq, al);
105        T y(x);
106        test::unordered_equivalence_tester<T> equivalent(x);
107        BOOST_TEST(equivalent(y));
108        test::check_equivalent_keys(y);
109        BOOST_TEST(test::equivalent(y.get_allocator(), al));
110    }
111
112    {
113        test::random_values<T> v(500, generator);
114
115        T x(v.begin(), v.end(), 0, hf, eq, al);
116        T y(x, al2);
117        test::unordered_equivalence_tester<T> equivalent(x);
118        BOOST_TEST(equivalent(y));
119        test::check_equivalent_keys(y);
120        BOOST_TEST(test::equivalent(y.get_allocator(), al2));
121    }
122}
123
124boost::unordered_set<test::object,
125    test::hash, test::equal_to,
126    test::allocator<test::object> >* test_set;
127boost::unordered_multiset<test::object,
128    test::hash, test::equal_to,
129    test::allocator<test::object> >* test_multiset;
130boost::unordered_map<test::object, test::object,
131    test::hash, test::equal_to,
132    test::allocator<test::object> >* test_map;
133boost::unordered_multimap<test::object, test::object,
134    test::hash, test::equal_to,
135    test::allocator<test::object> >* test_multimap;
136
137using test::default_generator;
138using test::generate_collisions;
139
140UNORDERED_TEST(copy_construct_tests1,
141    ((test_set)(test_multiset)(test_map)(test_multimap))
142)
143
144UNORDERED_TEST(copy_construct_tests2,
145    ((test_set)(test_multiset)(test_map)(test_multimap))
146    ((default_generator)(generate_collisions))
147)
148
149}
150
151RUN_TESTS()