unordered_set_lookup_test.h
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
17 
18 #include "gmock/gmock.h"
19 #include "gtest/gtest.h"
22 
23 namespace absl {
24 namespace container_internal {
25 
26 template <class UnordSet>
27 class LookupTest : public ::testing::Test {};
28 
29 TYPED_TEST_SUITE_P(LookupTest);
30 
31 TYPED_TEST_P(LookupTest, Count) {
32  using T = hash_internal::GeneratedType<TypeParam>;
33  std::vector<T> values;
34  std::generate_n(std::back_inserter(values), 10,
35  hash_internal::Generator<T>());
36  TypeParam m;
37  for (const auto& v : values)
38  EXPECT_EQ(0, m.count(v)) << ::testing::PrintToString(v);
39  m.insert(values.begin(), values.end());
40  for (const auto& v : values)
41  EXPECT_EQ(1, m.count(v)) << ::testing::PrintToString(v);
42 }
43 
44 TYPED_TEST_P(LookupTest, Find) {
45  using T = hash_internal::GeneratedType<TypeParam>;
46  std::vector<T> values;
47  std::generate_n(std::back_inserter(values), 10,
48  hash_internal::Generator<T>());
49  TypeParam m;
50  for (const auto& v : values)
51  EXPECT_TRUE(m.end() == m.find(v)) << ::testing::PrintToString(v);
52  m.insert(values.begin(), values.end());
53  for (const auto& v : values) {
54  typename TypeParam::iterator it = m.find(v);
55  static_assert(std::is_same<const typename TypeParam::value_type&,
56  decltype(*it)>::value,
57  "");
58  static_assert(std::is_same<const typename TypeParam::value_type*,
59  decltype(it.operator->())>::value,
60  "");
61  EXPECT_TRUE(m.end() != it) << ::testing::PrintToString(v);
62  EXPECT_EQ(v, *it) << ::testing::PrintToString(v);
63  }
64 }
65 
66 TYPED_TEST_P(LookupTest, EqualRange) {
67  using T = hash_internal::GeneratedType<TypeParam>;
68  std::vector<T> values;
69  std::generate_n(std::back_inserter(values), 10,
70  hash_internal::Generator<T>());
71  TypeParam m;
72  for (const auto& v : values) {
73  auto r = m.equal_range(v);
74  ASSERT_EQ(0, std::distance(r.first, r.second));
75  }
76  m.insert(values.begin(), values.end());
77  for (const auto& v : values) {
78  auto r = m.equal_range(v);
79  ASSERT_EQ(1, std::distance(r.first, r.second));
80  EXPECT_EQ(v, *r.first);
81  }
82 }
83 
84 REGISTER_TYPED_TEST_CASE_P(LookupTest, Count, Find, EqualRange);
85 
86 } // namespace container_internal
87 } // namespace absl
88 
89 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
int v
Definition: variant_test.cc:81
constexpr size_t Find(Needle, Needle, Ts...)
Definition: layout.h:266
TYPED_TEST_SUITE_P(ConstructorTest)
Definition: algorithm.h:29
size_t value
TYPED_TEST_P(ConstructorTest, NoArgs)
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)


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:37