]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
b32b8144 | 6 | // clang-format off |
7c673cae FG |
7 | #include "../helpers/prefix.hpp" |
8 | #include <boost/unordered_set.hpp> | |
9 | #include <boost/unordered_map.hpp> | |
10 | #include "../helpers/postfix.hpp" | |
b32b8144 | 11 | // clang-format on |
7c673cae FG |
12 | |
13 | #include "../helpers/test.hpp" | |
14 | #include "../objects/test.hpp" | |
15 | #include "../objects/cxx11_allocator.hpp" | |
16 | #include "../helpers/random_values.hpp" | |
17 | #include "../helpers/tracker.hpp" | |
18 | #include "../helpers/equivalent.hpp" | |
19 | #include "../helpers/invariants.hpp" | |
20 | ||
21 | test::seed_t initialize_seed(9063); | |
22 | ||
b32b8144 | 23 | namespace copy_tests { |
7c673cae | 24 | |
b32b8144 FG |
25 | template <class T> |
26 | void copy_construct_tests1(T*, test::random_generator const& generator) | |
27 | { | |
7c673cae FG |
28 | typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type; |
29 | ||
30 | BOOST_DEDUCED_TYPENAME T::hasher hf; | |
31 | BOOST_DEDUCED_TYPENAME T::key_equal eq; | |
b32b8144 | 32 | BOOST_DEDUCED_TYPENAME T::allocator_type al; |
7c673cae FG |
33 | |
34 | { | |
b32b8144 FG |
35 | test::check_instances check_; |
36 | ||
37 | T x; | |
38 | T y(x); | |
39 | BOOST_TEST(y.empty()); | |
40 | BOOST_TEST(test::equivalent(y.hash_function(), hf)); | |
41 | BOOST_TEST(test::equivalent(y.key_eq(), eq)); | |
42 | BOOST_TEST(test::equivalent(y.get_allocator(), al)); | |
43 | BOOST_TEST(x.max_load_factor() == y.max_load_factor()); | |
44 | BOOST_TEST(test::selected_count(y.get_allocator()) == | |
45 | (allocator_type::is_select_on_copy)); | |
46 | test::check_equivalent_keys(y); | |
7c673cae FG |
47 | } |
48 | ||
49 | { | |
b32b8144 | 50 | test::check_instances check_; |
7c673cae | 51 | |
b32b8144 | 52 | test::random_values<T> v(1000, generator); |
7c673cae | 53 | |
b32b8144 FG |
54 | T x(v.begin(), v.end()); |
55 | T y(x); | |
56 | test::unordered_equivalence_tester<T> equivalent(x); | |
57 | BOOST_TEST(equivalent(y)); | |
58 | BOOST_TEST(test::selected_count(y.get_allocator()) == | |
59 | (allocator_type::is_select_on_copy)); | |
60 | test::check_equivalent_keys(y); | |
7c673cae FG |
61 | } |
62 | ||
63 | { | |
b32b8144 FG |
64 | test::check_instances check_; |
65 | ||
66 | // In this test I drop the original containers max load factor, so it | |
67 | // is much lower than the load factor. The hash table is not allowed | |
68 | // to rehash, but the destination container should probably allocate | |
69 | // enough buckets to decrease the load factor appropriately. | |
70 | test::random_values<T> v(1000, generator); | |
71 | T x(v.begin(), v.end()); | |
72 | x.max_load_factor(x.load_factor() / 4); | |
73 | T y(x); | |
74 | test::unordered_equivalence_tester<T> equivalent(x); | |
75 | BOOST_TEST(equivalent(y)); | |
76 | // This isn't guaranteed: | |
77 | BOOST_TEST(y.load_factor() < y.max_load_factor()); | |
78 | BOOST_TEST(test::selected_count(y.get_allocator()) == | |
79 | (allocator_type::is_select_on_copy)); | |
80 | test::check_equivalent_keys(y); | |
7c673cae | 81 | } |
b32b8144 | 82 | } |
7c673cae | 83 | |
b32b8144 FG |
84 | template <class T> |
85 | void copy_construct_tests2(T*, test::random_generator const& generator) | |
86 | { | |
7c673cae FG |
87 | BOOST_DEDUCED_TYPENAME T::hasher hf(1); |
88 | BOOST_DEDUCED_TYPENAME T::key_equal eq(1); | |
89 | BOOST_DEDUCED_TYPENAME T::allocator_type al(1); | |
90 | BOOST_DEDUCED_TYPENAME T::allocator_type al2(2); | |
b32b8144 | 91 | |
7c673cae FG |
92 | typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type; |
93 | ||
94 | { | |
b32b8144 FG |
95 | test::check_instances check_; |
96 | ||
97 | T x(10000, hf, eq, al); | |
98 | T y(x); | |
99 | BOOST_TEST(y.empty()); | |
100 | BOOST_TEST(test::equivalent(y.hash_function(), hf)); | |
101 | BOOST_TEST(test::equivalent(y.key_eq(), eq)); | |
102 | BOOST_TEST(test::equivalent(y.get_allocator(), al)); | |
103 | BOOST_TEST(x.max_load_factor() == y.max_load_factor()); | |
104 | BOOST_TEST(test::selected_count(y.get_allocator()) == | |
105 | (allocator_type::is_select_on_copy)); | |
106 | test::check_equivalent_keys(y); | |
7c673cae FG |
107 | } |
108 | ||
109 | { | |
b32b8144 FG |
110 | test::check_instances check_; |
111 | ||
112 | T x(1000, hf, eq, al); | |
113 | T y(x, al2); | |
114 | BOOST_TEST(y.empty()); | |
115 | BOOST_TEST(test::equivalent(y.hash_function(), hf)); | |
116 | BOOST_TEST(test::equivalent(y.key_eq(), eq)); | |
117 | BOOST_TEST(test::equivalent(y.get_allocator(), al2)); | |
118 | BOOST_TEST(x.max_load_factor() == y.max_load_factor()); | |
119 | BOOST_TEST(test::selected_count(y.get_allocator()) == 0); | |
120 | test::check_equivalent_keys(y); | |
7c673cae FG |
121 | } |
122 | ||
123 | { | |
b32b8144 FG |
124 | test::check_instances check_; |
125 | ||
126 | test::random_values<T> v(1000, generator); | |
127 | ||
128 | T x(v.begin(), v.end(), 0, hf, eq, al); | |
129 | T y(x); | |
130 | test::unordered_equivalence_tester<T> equivalent(x); | |
131 | BOOST_TEST(equivalent(y)); | |
132 | test::check_equivalent_keys(y); | |
133 | BOOST_TEST(test::selected_count(y.get_allocator()) == | |
134 | (allocator_type::is_select_on_copy)); | |
135 | BOOST_TEST(test::equivalent(y.get_allocator(), al)); | |
7c673cae FG |
136 | } |
137 | ||
138 | { | |
b32b8144 | 139 | test::check_instances check_; |
7c673cae | 140 | |
b32b8144 | 141 | test::random_values<T> v(500, generator); |
7c673cae | 142 | |
b32b8144 FG |
143 | T x(v.begin(), v.end(), 0, hf, eq, al); |
144 | T y(x, al2); | |
145 | test::unordered_equivalence_tester<T> equivalent(x); | |
146 | BOOST_TEST(equivalent(y)); | |
147 | test::check_equivalent_keys(y); | |
148 | BOOST_TEST(test::selected_count(y.get_allocator()) == 0); | |
149 | BOOST_TEST(test::equivalent(y.get_allocator(), al2)); | |
7c673cae | 150 | } |
b32b8144 | 151 | } |
7c673cae | 152 | |
b32b8144 | 153 | boost::unordered_set<test::object, test::hash, test::equal_to, |
7c673cae | 154 | test::allocator1<test::object> >* test_set; |
b32b8144 | 155 | boost::unordered_multiset<test::object, test::hash, test::equal_to, |
7c673cae | 156 | test::allocator2<test::object> >* test_multiset; |
b32b8144 | 157 | boost::unordered_map<test::object, test::object, test::hash, test::equal_to, |
7c673cae | 158 | test::allocator1<test::object> >* test_map; |
b32b8144 FG |
159 | boost::unordered_multimap<test::object, test::object, test::hash, |
160 | test::equal_to, test::allocator2<test::object> >* test_multimap; | |
7c673cae | 161 | |
b32b8144 FG |
162 | boost::unordered_set<test::object, test::hash, test::equal_to, |
163 | test::cxx11_allocator<test::object, test::select_copy> >* | |
7c673cae | 164 | test_set_select_copy; |
b32b8144 FG |
165 | boost::unordered_multiset<test::object, test::hash, test::equal_to, |
166 | test::cxx11_allocator<test::object, test::select_copy> >* | |
7c673cae | 167 | test_multiset_select_copy; |
b32b8144 FG |
168 | boost::unordered_map<test::object, test::object, test::hash, test::equal_to, |
169 | test::cxx11_allocator<test::object, test::select_copy> >* | |
7c673cae | 170 | test_map_select_copy; |
b32b8144 FG |
171 | boost::unordered_multimap<test::object, test::object, test::hash, |
172 | test::equal_to, test::cxx11_allocator<test::object, test::select_copy> >* | |
7c673cae FG |
173 | test_multimap_select_copy; |
174 | ||
b32b8144 FG |
175 | boost::unordered_set<test::object, test::hash, test::equal_to, |
176 | test::cxx11_allocator<test::object, test::no_select_copy> >* | |
7c673cae | 177 | test_set_no_select_copy; |
b32b8144 FG |
178 | boost::unordered_multiset<test::object, test::hash, test::equal_to, |
179 | test::cxx11_allocator<test::object, test::no_select_copy> >* | |
7c673cae | 180 | test_multiset_no_select_copy; |
b32b8144 FG |
181 | boost::unordered_map<test::object, test::object, test::hash, test::equal_to, |
182 | test::cxx11_allocator<test::object, test::no_select_copy> >* | |
7c673cae | 183 | test_map_no_select_copy; |
b32b8144 FG |
184 | boost::unordered_multimap<test::object, test::object, test::hash, |
185 | test::equal_to, test::cxx11_allocator<test::object, test::no_select_copy> >* | |
7c673cae FG |
186 | test_multimap_no_select_copy; |
187 | ||
b32b8144 FG |
188 | using test::default_generator; |
189 | using test::generate_collisions; | |
190 | using test::limited_range; | |
191 | ||
192 | UNORDERED_TEST(copy_construct_tests1, | |
193 | ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_select_copy)( | |
194 | test_multiset_select_copy)(test_map_select_copy)( | |
195 | test_multimap_select_copy)(test_set_no_select_copy)( | |
196 | test_multiset_no_select_copy)(test_map_no_select_copy)( | |
197 | test_multimap_no_select_copy))( | |
198 | (default_generator)(generate_collisions)(limited_range))) | |
199 | ||
200 | UNORDERED_TEST(copy_construct_tests2, | |
201 | ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_select_copy)( | |
202 | test_multiset_select_copy)(test_map_select_copy)( | |
203 | test_multimap_select_copy)(test_set_no_select_copy)( | |
204 | test_multiset_no_select_copy)(test_map_no_select_copy)( | |
205 | test_multimap_no_select_copy))( | |
206 | (default_generator)(generate_collisions)(limited_range))) | |
7c673cae FG |
207 | } |
208 | ||
209 | RUN_TESTS() |