15 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_CONSTRUCTOR_TEST_H_ 16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_CONSTRUCTOR_TEST_H_ 19 #include <unordered_set> 22 #include "gmock/gmock.h" 23 #include "gtest/gtest.h" 29 namespace container_internal {
31 template <
class UnordMap>
32 class ConstructorTest :
public ::testing::Test {};
38 EXPECT_TRUE(m.empty());
39 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
44 EXPECT_TRUE(m.empty());
45 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
46 EXPECT_GE(m.bucket_count(), 123);
52 TypeParam m(123, hasher);
53 EXPECT_EQ(m.hash_function(),
hasher);
54 EXPECT_TRUE(m.empty());
55 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
56 EXPECT_GE(m.bucket_count(), 123);
61 using E =
typename TypeParam::key_equal;
64 TypeParam m(123, hasher, equal);
65 EXPECT_EQ(m.hash_function(),
hasher);
66 EXPECT_EQ(m.key_eq(), equal);
67 EXPECT_TRUE(m.empty());
68 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
69 EXPECT_GE(m.bucket_count(), 123);
72 TYPED_TEST_P(ConstructorTest, BucketCountHashEqualAlloc) {
74 using E =
typename TypeParam::key_equal;
75 using A =
typename TypeParam::allocator_type;
79 TypeParam m(123, hasher, equal,
alloc);
80 EXPECT_EQ(m.hash_function(),
hasher);
81 EXPECT_EQ(m.key_eq(), equal);
82 EXPECT_EQ(m.get_allocator(),
alloc);
83 EXPECT_TRUE(m.empty());
84 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
85 EXPECT_GE(m.bucket_count(), 123);
88 EXPECT_EQ(cm.hash_function(),
hasher);
89 EXPECT_EQ(cm.key_eq(), equal);
90 EXPECT_EQ(cm.get_allocator(),
alloc);
91 EXPECT_TRUE(cm.empty());
92 EXPECT_THAT(
keys(cm), ::testing::UnorderedElementsAre());
93 EXPECT_GE(cm.bucket_count(), 123);
99 template <
typename... T>
102 #if defined(UNORDERED_SET_CXX14) || defined(UNORDERED_SET_CXX17) 108 template <
typename T>
113 template <
typename TypeParam>
116 template <
typename TypeParam>
118 using A =
typename TypeParam::allocator_type;
120 TypeParam m(123, alloc);
121 EXPECT_EQ(m.get_allocator(),
alloc);
122 EXPECT_TRUE(m.empty());
123 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
124 EXPECT_GE(m.bucket_count(), 123);
131 template <
typename TypeParam>
134 template <
typename TypeParam>
137 using A =
typename TypeParam::allocator_type;
140 TypeParam m(123, hasher, alloc);
141 EXPECT_EQ(m.hash_function(),
hasher);
142 EXPECT_EQ(m.get_allocator(),
alloc);
143 EXPECT_TRUE(m.empty());
144 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
145 EXPECT_GE(m.bucket_count(), 123);
152 #if ABSL_UNORDERED_SUPPORTS_ALLOC_CTORS 158 template <
typename T>
163 template <
typename TypeParam>
166 template <
typename TypeParam>
168 using A =
typename TypeParam::allocator_type;
171 EXPECT_EQ(m.get_allocator(),
alloc);
172 EXPECT_TRUE(m.empty());
173 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
183 using E =
typename TypeParam::key_equal;
184 using A =
typename TypeParam::allocator_type;
188 std::vector<T> values;
189 for (
size_t i = 0;
i != 10; ++
i)
191 TypeParam m(values.begin(), values.end(), 123,
hasher, equal,
alloc);
192 EXPECT_EQ(m.hash_function(),
hasher);
193 EXPECT_EQ(m.key_eq(), equal);
194 EXPECT_EQ(m.get_allocator(),
alloc);
195 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
196 EXPECT_GE(m.bucket_count(), 123);
199 template <
typename TypeParam>
202 template <
typename TypeParam>
205 using A =
typename TypeParam::allocator_type;
207 std::vector<T> values;
208 for (
size_t i = 0;
i != 10; ++
i)
210 TypeParam m(values.begin(), values.end(), 123,
alloc);
211 EXPECT_EQ(m.get_allocator(),
alloc);
212 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
213 EXPECT_GE(m.bucket_count(), 123);
220 template <
typename TypeParam>
223 template <
typename TypeParam>
227 using A =
typename TypeParam::allocator_type;
230 std::vector<T> values;
231 for (
size_t i = 0;
i != 10; ++
i)
233 TypeParam m(values.begin(), values.end(), 123,
hasher,
alloc);
234 EXPECT_EQ(m.hash_function(),
hasher);
235 EXPECT_EQ(m.get_allocator(),
alloc);
236 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
237 EXPECT_GE(m.bucket_count(), 123);
247 using E =
typename TypeParam::key_equal;
248 using A =
typename TypeParam::allocator_type;
252 TypeParam m(123, hasher, equal, alloc);
255 EXPECT_EQ(m.hash_function(), n.hash_function());
256 EXPECT_EQ(m.key_eq(), n.key_eq());
257 EXPECT_EQ(m.get_allocator(), n.get_allocator());
259 EXPECT_NE(TypeParam(0, hasher, equal, alloc), n);
262 template <
typename TypeParam>
265 template <
typename TypeParam>
269 using E =
typename TypeParam::key_equal;
270 using A =
typename TypeParam::allocator_type;
274 TypeParam m(123, hasher, equal, alloc);
276 TypeParam
n(m, A(11));
277 EXPECT_EQ(m.hash_function(), n.hash_function());
278 EXPECT_EQ(m.key_eq(), n.key_eq());
279 EXPECT_NE(m.get_allocator(), n.get_allocator());
292 using E =
typename TypeParam::key_equal;
293 using A =
typename TypeParam::allocator_type;
297 TypeParam m(123, hasher, equal, alloc);
301 EXPECT_EQ(m.hash_function(), n.hash_function());
302 EXPECT_EQ(m.key_eq(), n.key_eq());
303 EXPECT_EQ(m.get_allocator(), n.get_allocator());
307 template <
typename TypeParam>
310 template <
typename TypeParam>
314 using E =
typename TypeParam::key_equal;
315 using A =
typename TypeParam::allocator_type;
319 TypeParam m(123, hasher, equal, alloc);
323 EXPECT_EQ(m.hash_function(), n.hash_function());
324 EXPECT_EQ(m.key_eq(), n.key_eq());
325 EXPECT_NE(m.get_allocator(), n.get_allocator());
338 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
340 using E =
typename TypeParam::key_equal;
341 using A =
typename TypeParam::allocator_type;
345 TypeParam m(values, 123, hasher, equal, alloc);
346 EXPECT_EQ(m.hash_function(),
hasher);
347 EXPECT_EQ(m.key_eq(), equal);
348 EXPECT_EQ(m.get_allocator(),
alloc);
349 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
350 EXPECT_GE(m.bucket_count(), 123);
353 template <
typename TypeParam>
356 template <
typename TypeParam>
359 using A =
typename TypeParam::allocator_type;
361 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
363 TypeParam m(values, 123, alloc);
364 EXPECT_EQ(m.get_allocator(),
alloc);
365 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
366 EXPECT_GE(m.bucket_count(), 123);
373 template <
typename TypeParam>
376 template <
typename TypeParam>
380 using A =
typename TypeParam::allocator_type;
384 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
385 TypeParam m(values, 123, hasher, alloc);
386 EXPECT_EQ(m.hash_function(),
hasher);
387 EXPECT_EQ(m.get_allocator(),
alloc);
388 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
389 EXPECT_GE(m.bucket_count(), 123);
399 using E =
typename TypeParam::key_equal;
400 using A =
typename TypeParam::allocator_type;
405 TypeParam m({gen(), gen(), gen()}, 123,
hasher, equal,
alloc);
408 EXPECT_EQ(m.hash_function(), n.hash_function());
409 EXPECT_EQ(m.key_eq(), n.key_eq());
419 using E =
typename TypeParam::key_equal;
420 using A =
typename TypeParam::allocator_type;
425 TypeParam m({gen(), gen(), gen()}, 123,
hasher, equal,
alloc);
429 EXPECT_EQ(m.hash_function(), n.hash_function());
430 EXPECT_EQ(m.key_eq(), n.key_eq());
437 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
440 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
446 TypeParam m({gen(), gen(), gen()});
447 TypeParam
n({gen()});
455 TypeParam m({gen(), gen(), gen()});
457 TypeParam
n({gen()});
465 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
468 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
474 std::initializer_list<T> values = {gen(), gen(), gen(), gen(), gen()};
477 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
481 ConstructorTest, NoArgs, BucketCount, BucketCountHash, BucketCountHashEqual,
482 BucketCountHashEqualAlloc, BucketCountAlloc, BucketCountHashAlloc,
Alloc,
483 InputIteratorBucketHashEqualAlloc, InputIteratorBucketAlloc,
484 InputIteratorBucketHashAlloc, CopyConstructor, CopyConstructorAlloc,
485 MoveConstructor, MoveConstructorAlloc, InitializerListBucketHashEqualAlloc,
486 InitializerListBucketAlloc, InitializerListBucketHashAlloc, CopyAssignment,
487 MoveAssignment, AssignmentFromInitializerList, AssignmentOverwritesExisting,
488 MoveAssignmentOverwritesExisting,
489 AssignmentFromInitializerListOverwritesExisting, AssignmentOnSelf);
494 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_CONSTRUCTOR_TEST_H_
std::false_type has_cxx14_std_apis
void InitializerListBucketHashAllocTest(std::false_type)
auto keys(const Set &s) -> std::vector< typename std::decay< typename Set::key_type >::type >
void MoveConstructorAllocTest(std::false_type)
void InputIteratorBucketHashAllocTest(std::false_type)
TYPED_TEST_SUITE_P(ConstructorTest)
void InitializerListBucketAllocTest(std::false_type)
void AllocTest(std::false_type)
hash_default_hash< T > hasher
std::false_type has_alloc_std_constructors
bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Pred &&pred)
void InputIteratorBucketAllocTest(std::false_type)
TYPED_TEST_P(ConstructorTest, NoArgs)
void BucketCountAllocTest(std::false_type)
decltype(std::declval< const Generator< typename std::conditional< generator_internal::IsMap< Container >::value, typename Container::value_type, typename Container::key_type >::type > & >()()) GeneratedType
std::allocator< int > alloc
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
void CopyConstructorAllocTest(std::false_type)
REGISTER_TYPED_TEST_CASE_P(ConstructorTest, NoArgs, BucketCount, BucketCountHash, BucketCountHashEqual, BucketCountHashEqualAlloc, BucketCountAlloc, BucketCountHashAlloc, Alloc, InputIteratorBucketHashEqualAlloc, InputIteratorBucketAlloc, InputIteratorBucketHashAlloc, CopyConstructor, CopyConstructorAlloc, MoveConstructor, MoveConstructorAlloc, InitializerListBucketHashEqualAlloc, InitializerListBucketAlloc, InitializerListBucketHashAlloc, Assignment, MoveAssignment, AssignmentFromInitializerList, AssignmentOverwritesExisting, MoveAssignmentOverwritesExisting, AssignmentFromInitializerListOverwritesExisting, AssignmentOnSelf)
void BucketCountHashAllocTest(std::false_type)