15 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MODIFIERS_TEST_H_ 16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MODIFIERS_TEST_H_ 18 #include "gmock/gmock.h" 19 #include "gtest/gtest.h" 24 namespace container_internal {
26 template <
class UnordMap>
33 std::vector<T> values;
34 std::generate_n(std::back_inserter(values), 10,
36 TypeParam m(values.begin(), values.end());
37 ASSERT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
39 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAre());
40 EXPECT_TRUE(m.empty());
45 using V =
typename TypeParam::mapped_type;
48 auto p = m.insert(val);
49 EXPECT_TRUE(p.second);
50 EXPECT_EQ(val, *p.first);
53 EXPECT_FALSE(p.second);
54 EXPECT_EQ(val, *p.first);
59 using V =
typename TypeParam::mapped_type;
62 auto it = m.insert(m.end(), val);
63 EXPECT_TRUE(it != m.end());
66 it = m.insert(it, val2);
67 EXPECT_TRUE(it != m.end());
73 std::vector<T> values;
74 std::generate_n(std::back_inserter(values), 10,
77 m.insert(values.begin(), values.end());
78 ASSERT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
82 #ifdef UNORDERED_MAP_CXX17 84 using K =
typename TypeParam::key_type;
85 using V =
typename TypeParam::mapped_type;
89 auto p = m.insert_or_assign(k, val);
90 EXPECT_TRUE(p.second);
91 EXPECT_EQ(k, get<0>(*p.first));
92 EXPECT_EQ(val, get<1>(*p.first));
94 p = m.insert_or_assign(k, val2);
95 EXPECT_FALSE(p.second);
96 EXPECT_EQ(k, get<0>(*p.first));
97 EXPECT_EQ(val2, get<1>(*p.first));
102 #ifdef UNORDERED_MAP_CXX17 104 using K =
typename TypeParam::key_type;
105 using V =
typename TypeParam::mapped_type;
109 auto it = m.insert_or_assign(m.end(), k, val);
110 EXPECT_TRUE(it != m.end());
111 EXPECT_EQ(k, get<0>(*it));
112 EXPECT_EQ(val, get<1>(*it));
114 it = m.insert_or_assign(it, k, val2);
115 EXPECT_EQ(k, get<0>(*it));
116 EXPECT_EQ(val2, get<1>(*it));
122 using V =
typename TypeParam::mapped_type;
127 auto p = m.emplace(val);
128 EXPECT_TRUE(p.second);
129 EXPECT_EQ(val, *p.first);
132 EXPECT_FALSE(p.second);
133 EXPECT_EQ(val, *p.first);
138 using V =
typename TypeParam::mapped_type;
143 auto it = m.emplace_hint(m.end(), val);
146 it = m.emplace_hint(it, val2);
151 #ifdef UNORDERED_MAP_CXX17 153 using V =
typename TypeParam::mapped_type;
158 auto p = m.try_emplace(val.first, val.second);
159 EXPECT_TRUE(p.second);
160 EXPECT_EQ(val, *p.first);
162 p = m.try_emplace(val2.first, val2.second);
163 EXPECT_FALSE(p.second);
164 EXPECT_EQ(val, *p.first);
169 #ifdef UNORDERED_MAP_CXX17 171 using V =
typename TypeParam::mapped_type;
176 auto it = m.try_emplace(m.end(), val.first, val.second);
179 it = m.try_emplace(it, val2.first, val2.second);
192 ->
IfNotVoid<decltype(m->erase(m->begin()))> {
193 return m->erase(m->begin());
197 auto it = m->begin();
206 std::vector<T> values;
207 std::generate_n(std::back_inserter(values), 10,
209 TypeParam m(values.begin(), values.end());
210 ASSERT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
211 auto& first = *m.begin();
212 std::vector<T> values2;
213 for (
const auto& val : values)
214 if (get<0>(val) != get<0>(first)) values2.push_back(val);
216 ASSERT_TRUE(it != m.end());
217 EXPECT_EQ(1, std::count(values2.begin(), values2.end(), *it));
218 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values2.begin(),
224 std::vector<T> values;
225 std::generate_n(std::back_inserter(values), 10,
227 TypeParam m(values.begin(), values.end());
228 ASSERT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
229 auto it = m.erase(m.begin(), m.end());
230 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAre());
231 EXPECT_TRUE(it == m.end());
236 std::vector<T> values;
237 std::generate_n(std::back_inserter(values), 10,
239 TypeParam m(values.begin(), values.end());
240 ASSERT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values));
241 EXPECT_EQ(1, m.erase(values[0].first));
242 EXPECT_EQ(0, std::count(m.begin(), m.end(), values[0]));
243 EXPECT_THAT(
items(m), ::testing::UnorderedElementsAreArray(values.begin() + 1,
253 TypeParam m1(v1.begin(), v1.end());
254 TypeParam m2(v2.begin(), v2.end());
255 EXPECT_THAT(
items(m1), ::testing::UnorderedElementsAreArray(v1));
256 EXPECT_THAT(
items(m2), ::testing::UnorderedElementsAreArray(v2));
258 EXPECT_THAT(
items(m1), ::testing::UnorderedElementsAreArray(v2));
259 EXPECT_THAT(
items(m2), ::testing::UnorderedElementsAreArray(v1));
266 InsertRange, InsertOrAssign, InsertOrAssignHint,
267 Emplace, EmplaceHint, TryEmplace, TryEmplaceHint,
268 Erase, EraseRange, EraseKey,
Swap);
273 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MODIFIERS_TEST_H_ auto items(const Map &m) -> std::vector< std::pair< typename Map::key_type, typename Map::mapped_type >>
typename std::enable_if<!std::is_void< V >::value, V >::type IfNotVoid
TYPED_TEST_SUITE_P(ConstructorTest)
void Swap(T &lhs, T &rhs) noexcept(IsNothrowSwappable< T >::value)
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)
auto operator()(Map *m, int) const -> IfNotVoid< decltype(m->erase(m->begin()))>
Map::iterator operator()(Map *m,...) const
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)