unordered_map_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_MAP_LOOKUP_TEST_H_
16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_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 UnordMap>
27 class LookupTest : public ::testing::Test {};
28 
30 
33  std::vector<T> values;
34  std::generate_n(std::back_inserter(values), 10,
36  TypeParam m(values.begin(), values.end());
37  for (const auto& p : values) {
38  const auto& val = m.at(p.first);
39  EXPECT_EQ(p.second, val) << ::testing::PrintToString(p.first);
40  }
41 }
42 
43 TYPED_TEST_P(LookupTest, OperatorBracket) {
45  using V = typename TypeParam::mapped_type;
46  std::vector<T> values;
47  std::generate_n(std::back_inserter(values), 10,
49  TypeParam m;
50  for (const auto& p : values) {
51  auto& val = m[p.first];
52  EXPECT_EQ(V(), val) << ::testing::PrintToString(p.first);
53  val = p.second;
54  }
55  for (const auto& p : values)
56  EXPECT_EQ(p.second, m[p.first]) << ::testing::PrintToString(p.first);
57 }
58 
61  std::vector<T> values;
62  std::generate_n(std::back_inserter(values), 10,
64  TypeParam m;
65  for (const auto& p : values)
66  EXPECT_EQ(0, m.count(p.first)) << ::testing::PrintToString(p.first);
67  m.insert(values.begin(), values.end());
68  for (const auto& p : values)
69  EXPECT_EQ(1, m.count(p.first)) << ::testing::PrintToString(p.first);
70 }
71 
73  using std::get;
75  std::vector<T> values;
76  std::generate_n(std::back_inserter(values), 10,
78  TypeParam m;
79  for (const auto& p : values)
80  EXPECT_TRUE(m.end() == m.find(p.first))
81  << ::testing::PrintToString(p.first);
82  m.insert(values.begin(), values.end());
83  for (const auto& p : values) {
84  auto it = m.find(p.first);
85  EXPECT_TRUE(m.end() != it) << ::testing::PrintToString(p.first);
86  EXPECT_EQ(p.second, get<1>(*it)) << ::testing::PrintToString(p.first);
87  }
88 }
89 
90 TYPED_TEST_P(LookupTest, EqualRange) {
91  using std::get;
93  std::vector<T> values;
94  std::generate_n(std::back_inserter(values), 10,
96  TypeParam m;
97  for (const auto& p : values) {
98  auto r = m.equal_range(p.first);
99  ASSERT_EQ(0, std::distance(r.first, r.second));
100  }
101  m.insert(values.begin(), values.end());
102  for (const auto& p : values) {
103  auto r = m.equal_range(p.first);
104  ASSERT_EQ(1, std::distance(r.first, r.second));
105  EXPECT_EQ(p.second, get<1>(*r.first)) << ::testing::PrintToString(p.first);
106  }
107 }
108 
109 REGISTER_TYPED_TEST_CASE_P(LookupTest, At, OperatorBracket, Count, Find,
110  EqualRange);
111 
112 } // namespace container_internal
113 } // namespace absl
114 
115 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_LOOKUP_TEST_H_
constexpr size_t Find(Needle, Needle, Ts...)
Definition: layout.h:266
TYPED_TEST_SUITE_P(ConstructorTest)
Definition: algorithm.h:29
TYPED_TEST_P(ConstructorTest, NoArgs)
decltype(std::declval< const Generator< typename std::conditional< generator_internal::IsMap< Container >::value, typename Container::value_type, typename Container::key_type >::type > & >()()) GeneratedType
absl::string_view get(const Cont &c)
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 Wed Jun 19 2019 19:19:58