15 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MODIFIERS_TEST_H_ 16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MODIFIERS_TEST_H_ 18 #include "gmock/gmock.h" 19 #include "gtest/gtest.h" 24 namespace container_internal {
26 template <
class UnordSet>
27 class ModifiersTest :
public ::testing::Test {};
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(values.begin(), values.end());
37 ASSERT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
39 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
40 EXPECT_TRUE(m.empty());
44 using T = hash_internal::GeneratedType<TypeParam>;
45 T val = hash_internal::Generator<T>()();
47 auto p = m.insert(val);
48 EXPECT_TRUE(p.second);
49 EXPECT_EQ(val, *p.first);
51 EXPECT_FALSE(p.second);
55 using T = hash_internal::GeneratedType<TypeParam>;
56 T val = hash_internal::Generator<T>()();
58 auto it = m.insert(m.end(), val);
59 EXPECT_TRUE(it != m.end());
61 it = m.insert(it, val);
62 EXPECT_TRUE(it != m.end());
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>());
72 m.insert(values.begin(), values.end());
73 ASSERT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
77 using T = hash_internal::GeneratedType<TypeParam>;
78 T val = hash_internal::Generator<T>()();
82 auto p = m.emplace(val);
83 EXPECT_TRUE(p.second);
84 EXPECT_EQ(val, *p.first);
86 EXPECT_FALSE(p.second);
87 EXPECT_EQ(val, *p.first);
91 using T = hash_internal::GeneratedType<TypeParam>;
92 T val = hash_internal::Generator<T>()();
96 auto it = m.emplace_hint(m.end(), val);
98 it = m.emplace_hint(it, val);
111 return m->erase(m->begin());
115 auto it = m->begin();
123 std::vector<T> values;
124 std::generate_n(std::back_inserter(values), 10,
126 TypeParam m(values.begin(), values.end());
127 ASSERT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
128 std::vector<T> values2;
129 for (
const auto& val : values)
130 if (val != *m.begin()) values2.push_back(val);
132 ASSERT_TRUE(it != m.end());
133 EXPECT_EQ(1, std::count(values2.begin(), values2.end(), *it));
134 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values2.begin(),
140 std::vector<T> values;
141 std::generate_n(std::back_inserter(values), 10,
143 TypeParam m(values.begin(), values.end());
144 ASSERT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
145 auto it = m.erase(m.begin(), m.end());
146 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAre());
147 EXPECT_TRUE(it == m.end());
152 std::vector<T> values;
153 std::generate_n(std::back_inserter(values), 10,
155 TypeParam m(values.begin(), values.end());
156 ASSERT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values));
157 EXPECT_EQ(1, m.erase(values[0]));
158 EXPECT_EQ(0, std::count(m.begin(), m.end(), values[0]));
159 EXPECT_THAT(
keys(m), ::testing::UnorderedElementsAreArray(values.begin() + 1,
169 TypeParam m1(v1.begin(), v1.end());
170 TypeParam m2(v2.begin(), v2.end());
171 EXPECT_THAT(
keys(m1), ::testing::UnorderedElementsAreArray(v1));
172 EXPECT_THAT(
keys(m2), ::testing::UnorderedElementsAreArray(v2));
174 EXPECT_THAT(
keys(m1), ::testing::UnorderedElementsAreArray(v2));
175 EXPECT_THAT(
keys(m2), ::testing::UnorderedElementsAreArray(v1));
182 InsertRange, Emplace, EmplaceHint, Erase, EraseRange,
188 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MODIFIERS_TEST_H_
typename std::enable_if<!std::is_void< V >::value, V >::type IfNotVoid
auto keys(const Set &s) -> std::vector< typename std::decay< typename Set::key_type >::type >
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
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)