diff --git a/tests/googletest/include/absl/container/internal/unordered_map_constructor_test.h b/tests/googletest/include/absl/container/internal/unordered_map_constructor_test.h deleted file mode 100644 index 7e84dc25..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_map_constructor_test.h +++ /dev/null @@ -1,494 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_CONSTRUCTOR_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_CONSTRUCTOR_TEST_H_ - -#include -#include -#include - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/container/internal/hash_generator_testing.h" -#include "absl/container/internal/hash_policy_testing.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class ConstructorTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(ConstructorTest); - -TYPED_TEST_P(ConstructorTest, NoArgs) { - TypeParam m; - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); -} - -TYPED_TEST_P(ConstructorTest, BucketCount) { - TypeParam m(123); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHash) { - using H = typename TypeParam::hasher; - H hasher; - TypeParam m(123, hasher); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHashEqual) { - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - H hasher; - E equal; - TypeParam m(123, hasher, equal); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHashEqualAlloc) { - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(123, hasher, equal, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -template -struct is_std_unordered_map : std::false_type {}; - -template -struct is_std_unordered_map> : std::true_type {}; - -#if defined(UNORDERED_MAP_CXX14) || defined(UNORDERED_MAP_CXX17) -using has_cxx14_std_apis = std::true_type; -#else -using has_cxx14_std_apis = std::false_type; -#endif - -template -using expect_cxx14_apis = - absl::disjunction>, - has_cxx14_std_apis>; - -template -void BucketCountAllocTest(std::false_type) {} - -template -void BucketCountAllocTest(std::true_type) { - using A = typename TypeParam::allocator_type; - A alloc(0); - TypeParam m(123, alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountAlloc) { - BucketCountAllocTest(expect_cxx14_apis()); -} - -template -void BucketCountHashAllocTest(std::false_type) {} - -template -void BucketCountHashAllocTest(std::true_type) { - using H = typename TypeParam::hasher; - using A = typename TypeParam::allocator_type; - H hasher; - A alloc(0); - TypeParam m(123, hasher, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHashAlloc) { - BucketCountHashAllocTest(expect_cxx14_apis()); -} - -#if ABSL_UNORDERED_SUPPORTS_ALLOC_CTORS -using has_alloc_std_constructors = std::true_type; -#else -using has_alloc_std_constructors = std::false_type; -#endif - -template -using expect_alloc_constructors = - absl::disjunction>, - has_alloc_std_constructors>; - -template -void AllocTest(std::false_type) {} - -template -void AllocTest(std::true_type) { - using A = typename TypeParam::allocator_type; - A alloc(0); - TypeParam m(alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(m, ::testing::UnorderedElementsAre()); -} - -TYPED_TEST_P(ConstructorTest, Alloc) { - AllocTest(expect_alloc_constructors()); -} - -TYPED_TEST_P(ConstructorTest, InputIteratorBucketHashEqualAlloc) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::UniqueGenerator()); - TypeParam m(values.begin(), values.end(), 123, hasher, equal, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -template -void InputIteratorBucketAllocTest(std::false_type) {} - -template -void InputIteratorBucketAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using A = typename TypeParam::allocator_type; - A alloc(0); - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::UniqueGenerator()); - TypeParam m(values.begin(), values.end(), 123, alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InputIteratorBucketAlloc) { - InputIteratorBucketAllocTest(expect_cxx14_apis()); -} - -template -void InputIteratorBucketHashAllocTest(std::false_type) {} - -template -void InputIteratorBucketHashAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using A = typename TypeParam::allocator_type; - H hasher; - A alloc(0); - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::UniqueGenerator()); - TypeParam m(values.begin(), values.end(), 123, hasher, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InputIteratorBucketHashAlloc) { - InputIteratorBucketHashAllocTest(expect_cxx14_apis()); -} - -TYPED_TEST_P(ConstructorTest, CopyConstructor) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::UniqueGenerator gen; - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(gen()); - TypeParam n(m); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -template -void CopyConstructorAllocTest(std::false_type) {} - -template -void CopyConstructorAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::UniqueGenerator gen; - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(gen()); - TypeParam n(m, A(11)); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_NE(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, CopyConstructorAlloc) { - CopyConstructorAllocTest(expect_alloc_constructors()); -} - -// TODO(alkis): Test non-propagating allocators on copy constructors. - -TYPED_TEST_P(ConstructorTest, MoveConstructor) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::UniqueGenerator gen; - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(gen()); - TypeParam t(m); - TypeParam n(std::move(t)); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -template -void MoveConstructorAllocTest(std::false_type) {} - -template -void MoveConstructorAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::UniqueGenerator gen; - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(gen()); - TypeParam t(m); - TypeParam n(std::move(t), A(1)); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_NE(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, MoveConstructorAlloc) { - MoveConstructorAllocTest(expect_alloc_constructors()); -} - -// TODO(alkis): Test non-propagating allocators on move constructors. - -TYPED_TEST_P(ConstructorTest, InitializerListBucketHashEqualAlloc) { - using T = hash_internal::GeneratedType; - hash_internal::UniqueGenerator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(values, 123, hasher, equal, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -template -void InitializerListBucketAllocTest(std::false_type) {} - -template -void InitializerListBucketAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using A = typename TypeParam::allocator_type; - hash_internal::UniqueGenerator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - A alloc(0); - TypeParam m(values, 123, alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InitializerListBucketAlloc) { - InitializerListBucketAllocTest(expect_cxx14_apis()); -} - -template -void InitializerListBucketHashAllocTest(std::false_type) {} - -template -void InitializerListBucketHashAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using A = typename TypeParam::allocator_type; - H hasher; - A alloc(0); - hash_internal::UniqueGenerator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m(values, 123, hasher, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InitializerListBucketHashAlloc) { - InitializerListBucketHashAllocTest(expect_cxx14_apis()); -} - -TYPED_TEST_P(ConstructorTest, Assignment) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::UniqueGenerator gen; - TypeParam m({gen(), gen(), gen()}, 123, hasher, equal, alloc); - TypeParam n; - n = m; - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m, n); -} - -// TODO(alkis): Test [non-]propagating allocators on move/copy assignments -// (it depends on traits). - -TYPED_TEST_P(ConstructorTest, MoveAssignment) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::UniqueGenerator gen; - TypeParam m({gen(), gen(), gen()}, 123, hasher, equal, alloc); - TypeParam t(m); - TypeParam n; - n = std::move(t); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, AssignmentFromInitializerList) { - using T = hash_internal::GeneratedType; - hash_internal::UniqueGenerator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m; - m = values; - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); -} - -TYPED_TEST_P(ConstructorTest, AssignmentOverwritesExisting) { - using T = hash_internal::GeneratedType; - hash_internal::UniqueGenerator gen; - TypeParam m({gen(), gen(), gen()}); - TypeParam n({gen()}); - n = m; - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, MoveAssignmentOverwritesExisting) { - using T = hash_internal::GeneratedType; - hash_internal::UniqueGenerator gen; - TypeParam m({gen(), gen(), gen()}); - TypeParam t(m); - TypeParam n({gen()}); - n = std::move(t); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, AssignmentFromInitializerListOverwritesExisting) { - using T = hash_internal::GeneratedType; - hash_internal::UniqueGenerator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m; - m = values; - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); -} - -TYPED_TEST_P(ConstructorTest, AssignmentOnSelf) { - using T = hash_internal::GeneratedType; - hash_internal::UniqueGenerator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m(values); - m = *&m; // Avoid -Wself-assign - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); -} - -// We cannot test self move as standard states that it leaves standard -// containers in unspecified state (and in practice in causes memory-leak -// according to heap-checker!). - -REGISTER_TYPED_TEST_SUITE_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); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_CONSTRUCTOR_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_map_lookup_test.h b/tests/googletest/include/absl/container/internal/unordered_map_lookup_test.h deleted file mode 100644 index 3713cd9a..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_map_lookup_test.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_LOOKUP_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_LOOKUP_TEST_H_ - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/container/internal/hash_generator_testing.h" -#include "absl/container/internal/hash_policy_testing.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class LookupTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(LookupTest); - -TYPED_TEST_P(LookupTest, At) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - for (const auto& p : values) { - const auto& val = m.at(p.first); - EXPECT_EQ(p.second, val) << ::testing::PrintToString(p.first); - } -} - -TYPED_TEST_P(LookupTest, OperatorBracket) { - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& p : values) { - auto& val = m[p.first]; - EXPECT_EQ(V(), val) << ::testing::PrintToString(p.first); - val = p.second; - } - for (const auto& p : values) - EXPECT_EQ(p.second, m[p.first]) << ::testing::PrintToString(p.first); -} - -TYPED_TEST_P(LookupTest, Count) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& p : values) - EXPECT_EQ(0, m.count(p.first)) << ::testing::PrintToString(p.first); - m.insert(values.begin(), values.end()); - for (const auto& p : values) - EXPECT_EQ(1, m.count(p.first)) << ::testing::PrintToString(p.first); -} - -TYPED_TEST_P(LookupTest, Find) { - using std::get; - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& p : values) - EXPECT_TRUE(m.end() == m.find(p.first)) - << ::testing::PrintToString(p.first); - m.insert(values.begin(), values.end()); - for (const auto& p : values) { - auto it = m.find(p.first); - EXPECT_TRUE(m.end() != it) << ::testing::PrintToString(p.first); - EXPECT_EQ(p.second, get<1>(*it)) << ::testing::PrintToString(p.first); - } -} - -TYPED_TEST_P(LookupTest, EqualRange) { - using std::get; - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& p : values) { - auto r = m.equal_range(p.first); - ASSERT_EQ(0, std::distance(r.first, r.second)); - } - m.insert(values.begin(), values.end()); - for (const auto& p : values) { - auto r = m.equal_range(p.first); - ASSERT_EQ(1, std::distance(r.first, r.second)); - EXPECT_EQ(p.second, get<1>(*r.first)) << ::testing::PrintToString(p.first); - } -} - -REGISTER_TYPED_TEST_SUITE_P(LookupTest, At, OperatorBracket, Count, Find, - EqualRange); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_LOOKUP_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_map_members_test.h b/tests/googletest/include/absl/container/internal/unordered_map_members_test.h deleted file mode 100644 index 7d48cdb8..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_map_members_test.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MEMBERS_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MEMBERS_TEST_H_ - -#include -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/meta/type_traits.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class MembersTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(MembersTest); - -template -void UseType() {} - -TYPED_TEST_P(MembersTest, Typedefs) { - EXPECT_TRUE((std::is_same, - typename TypeParam::value_type>())); - EXPECT_TRUE((absl::conjunction< - absl::negation>, - std::is_integral>())); - EXPECT_TRUE((absl::conjunction< - std::is_signed, - std::is_integral>())); - EXPECT_TRUE((std::is_convertible< - decltype(std::declval()( - std::declval())), - size_t>())); - EXPECT_TRUE((std::is_convertible< - decltype(std::declval()( - std::declval(), - std::declval())), - bool>())); - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((std::is_same::pointer, - typename TypeParam::pointer>())); - EXPECT_TRUE( - (std::is_same::const_pointer, - typename TypeParam::const_pointer>())); -} - -TYPED_TEST_P(MembersTest, SimpleFunctions) { - EXPECT_GT(TypeParam().max_size(), 0); -} - -TYPED_TEST_P(MembersTest, BeginEnd) { - TypeParam t = {typename TypeParam::value_type{}}; - EXPECT_EQ(t.begin(), t.cbegin()); - EXPECT_EQ(t.end(), t.cend()); - EXPECT_NE(t.begin(), t.end()); - EXPECT_NE(t.cbegin(), t.cend()); -} - -REGISTER_TYPED_TEST_SUITE_P(MembersTest, Typedefs, SimpleFunctions, BeginEnd); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MEMBERS_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_map_modifiers_test.h b/tests/googletest/include/absl/container/internal/unordered_map_modifiers_test.h deleted file mode 100644 index 4d9ab30f..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_map_modifiers_test.h +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MODIFIERS_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MODIFIERS_TEST_H_ - -#include - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/container/internal/hash_generator_testing.h" -#include "absl/container/internal/hash_policy_testing.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class ModifiersTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(ModifiersTest); - -TYPED_TEST_P(ModifiersTest, Clear) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - m.clear(); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAre()); - EXPECT_TRUE(m.empty()); -} - -TYPED_TEST_P(ModifiersTest, Insert) { - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - auto p = m.insert(val); - EXPECT_TRUE(p.second); - EXPECT_EQ(val, *p.first); - T val2 = {val.first, hash_internal::Generator()()}; - p = m.insert(val2); - EXPECT_FALSE(p.second); - EXPECT_EQ(val, *p.first); -} - -TYPED_TEST_P(ModifiersTest, InsertHint) { - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - auto it = m.insert(m.end(), val); - EXPECT_TRUE(it != m.end()); - EXPECT_EQ(val, *it); - T val2 = {val.first, hash_internal::Generator()()}; - it = m.insert(it, val2); - EXPECT_TRUE(it != m.end()); - EXPECT_EQ(val, *it); -} - -TYPED_TEST_P(ModifiersTest, InsertRange) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - m.insert(values.begin(), values.end()); - ASSERT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); -} - -TYPED_TEST_P(ModifiersTest, InsertWithinCapacity) { - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - m.reserve(10); - const size_t original_capacity = m.bucket_count(); - m.insert(val); - EXPECT_EQ(m.bucket_count(), original_capacity); - T val2 = {val.first, hash_internal::Generator()()}; - m.insert(val2); - EXPECT_EQ(m.bucket_count(), original_capacity); -} - -TYPED_TEST_P(ModifiersTest, InsertRangeWithinCapacity) { -#if !defined(__GLIBCXX__) - using T = hash_internal::GeneratedType; - std::vector base_values; - std::generate_n(std::back_inserter(base_values), 10, - hash_internal::Generator()); - std::vector values; - while (values.size() != 100) { - std::copy_n(base_values.begin(), 10, std::back_inserter(values)); - } - TypeParam m; - m.reserve(10); - const size_t original_capacity = m.bucket_count(); - m.insert(values.begin(), values.end()); - EXPECT_EQ(m.bucket_count(), original_capacity); -#endif -} - -TYPED_TEST_P(ModifiersTest, InsertOrAssign) { -#ifdef UNORDERED_MAP_CXX17 - using std::get; - using K = typename TypeParam::key_type; - using V = typename TypeParam::mapped_type; - K k = hash_internal::Generator()(); - V val = hash_internal::Generator()(); - TypeParam m; - auto p = m.insert_or_assign(k, val); - EXPECT_TRUE(p.second); - EXPECT_EQ(k, get<0>(*p.first)); - EXPECT_EQ(val, get<1>(*p.first)); - V val2 = hash_internal::Generator()(); - p = m.insert_or_assign(k, val2); - EXPECT_FALSE(p.second); - EXPECT_EQ(k, get<0>(*p.first)); - EXPECT_EQ(val2, get<1>(*p.first)); -#endif -} - -TYPED_TEST_P(ModifiersTest, InsertOrAssignHint) { -#ifdef UNORDERED_MAP_CXX17 - using std::get; - using K = typename TypeParam::key_type; - using V = typename TypeParam::mapped_type; - K k = hash_internal::Generator()(); - V val = hash_internal::Generator()(); - TypeParam m; - auto it = m.insert_or_assign(m.end(), k, val); - EXPECT_TRUE(it != m.end()); - EXPECT_EQ(k, get<0>(*it)); - EXPECT_EQ(val, get<1>(*it)); - V val2 = hash_internal::Generator()(); - it = m.insert_or_assign(it, k, val2); - EXPECT_EQ(k, get<0>(*it)); - EXPECT_EQ(val2, get<1>(*it)); -#endif -} - -TYPED_TEST_P(ModifiersTest, Emplace) { - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - // TODO(alkis): We need a way to run emplace in a more meaningful way. Perhaps - // with test traits/policy. - auto p = m.emplace(val); - EXPECT_TRUE(p.second); - EXPECT_EQ(val, *p.first); - T val2 = {val.first, hash_internal::Generator()()}; - p = m.emplace(val2); - EXPECT_FALSE(p.second); - EXPECT_EQ(val, *p.first); -} - -TYPED_TEST_P(ModifiersTest, EmplaceHint) { - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - // TODO(alkis): We need a way to run emplace in a more meaningful way. Perhaps - // with test traits/policy. - auto it = m.emplace_hint(m.end(), val); - EXPECT_EQ(val, *it); - T val2 = {val.first, hash_internal::Generator()()}; - it = m.emplace_hint(it, val2); - EXPECT_EQ(val, *it); -} - -TYPED_TEST_P(ModifiersTest, TryEmplace) { -#ifdef UNORDERED_MAP_CXX17 - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - // TODO(alkis): We need a way to run emplace in a more meaningful way. Perhaps - // with test traits/policy. - auto p = m.try_emplace(val.first, val.second); - EXPECT_TRUE(p.second); - EXPECT_EQ(val, *p.first); - T val2 = {val.first, hash_internal::Generator()()}; - p = m.try_emplace(val2.first, val2.second); - EXPECT_FALSE(p.second); - EXPECT_EQ(val, *p.first); -#endif -} - -TYPED_TEST_P(ModifiersTest, TryEmplaceHint) { -#ifdef UNORDERED_MAP_CXX17 - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - // TODO(alkis): We need a way to run emplace in a more meaningful way. Perhaps - // with test traits/policy. - auto it = m.try_emplace(m.end(), val.first, val.second); - EXPECT_EQ(val, *it); - T val2 = {val.first, hash_internal::Generator()()}; - it = m.try_emplace(it, val2.first, val2.second); - EXPECT_EQ(val, *it); -#endif -} - -template -using IfNotVoid = typename std::enable_if::value, V>::type; - -// In openmap we chose not to return the iterator from erase because that's -// more expensive. As such we adapt erase to return an iterator here. -struct EraseFirst { - template - auto operator()(Map* m, int) const - -> IfNotVoiderase(m->begin()))> { - return m->erase(m->begin()); - } - template - typename Map::iterator operator()(Map* m, ...) const { - auto it = m->begin(); - m->erase(it++); - return it; - } -}; - -TYPED_TEST_P(ModifiersTest, Erase) { - using T = hash_internal::GeneratedType; - using std::get; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - auto& first = *m.begin(); - std::vector values2; - for (const auto& val : values) - if (get<0>(val) != get<0>(first)) values2.push_back(val); - auto it = EraseFirst()(&m, 0); - ASSERT_TRUE(it != m.end()); - EXPECT_EQ(1, std::count(values2.begin(), values2.end(), *it)); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values2.begin(), - values2.end())); -} - -TYPED_TEST_P(ModifiersTest, EraseRange) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - auto it = m.erase(m.begin(), m.end()); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAre()); - EXPECT_TRUE(it == m.end()); -} - -TYPED_TEST_P(ModifiersTest, EraseKey) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(items(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_EQ(1, m.erase(values[0].first)); - EXPECT_EQ(0, std::count(m.begin(), m.end(), values[0])); - EXPECT_THAT(items(m), ::testing::UnorderedElementsAreArray(values.begin() + 1, - values.end())); -} - -TYPED_TEST_P(ModifiersTest, Swap) { - using T = hash_internal::GeneratedType; - std::vector v1; - std::vector v2; - std::generate_n(std::back_inserter(v1), 5, hash_internal::Generator()); - std::generate_n(std::back_inserter(v2), 5, hash_internal::Generator()); - TypeParam m1(v1.begin(), v1.end()); - TypeParam m2(v2.begin(), v2.end()); - EXPECT_THAT(items(m1), ::testing::UnorderedElementsAreArray(v1)); - EXPECT_THAT(items(m2), ::testing::UnorderedElementsAreArray(v2)); - m1.swap(m2); - EXPECT_THAT(items(m1), ::testing::UnorderedElementsAreArray(v2)); - EXPECT_THAT(items(m2), ::testing::UnorderedElementsAreArray(v1)); -} - -// TODO(alkis): Write tests for extract. -// TODO(alkis): Write tests for merge. - -REGISTER_TYPED_TEST_SUITE_P(ModifiersTest, Clear, Insert, InsertHint, - InsertRange, InsertWithinCapacity, - InsertRangeWithinCapacity, InsertOrAssign, - InsertOrAssignHint, Emplace, EmplaceHint, - TryEmplace, TryEmplaceHint, Erase, EraseRange, - EraseKey, Swap); - -template -struct is_unique_ptr : std::false_type {}; - -template -struct is_unique_ptr> : std::true_type {}; - -template -class UniquePtrModifiersTest : public ::testing::Test { - protected: - UniquePtrModifiersTest() { - static_assert(is_unique_ptr::value, - "UniquePtrModifiersTyest may only be called with a " - "std::unique_ptr value type."); - } -}; - -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(UniquePtrModifiersTest); - -TYPED_TEST_SUITE_P(UniquePtrModifiersTest); - -// Test that we do not move from rvalue arguments if an insertion does not -// happen. -TYPED_TEST_P(UniquePtrModifiersTest, TryEmplace) { -#ifdef UNORDERED_MAP_CXX17 - using T = hash_internal::GeneratedType; - using V = typename TypeParam::mapped_type; - T val = hash_internal::Generator()(); - TypeParam m; - auto p = m.try_emplace(val.first, std::move(val.second)); - EXPECT_TRUE(p.second); - // A moved from std::unique_ptr is guaranteed to be nullptr. - EXPECT_EQ(val.second, nullptr); - T val2 = {val.first, hash_internal::Generator()()}; - p = m.try_emplace(val2.first, std::move(val2.second)); - EXPECT_FALSE(p.second); - EXPECT_NE(val2.second, nullptr); -#endif -} - -REGISTER_TYPED_TEST_SUITE_P(UniquePtrModifiersTest, TryEmplace); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MODIFIERS_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_set_constructor_test.h b/tests/googletest/include/absl/container/internal/unordered_set_constructor_test.h deleted file mode 100644 index af1116e6..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_set_constructor_test.h +++ /dev/null @@ -1,496 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_CONSTRUCTOR_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_CONSTRUCTOR_TEST_H_ - -#include -#include -#include - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/container/internal/hash_generator_testing.h" -#include "absl/container/internal/hash_policy_testing.h" -#include "absl/meta/type_traits.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class ConstructorTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(ConstructorTest); - -TYPED_TEST_P(ConstructorTest, NoArgs) { - TypeParam m; - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); -} - -TYPED_TEST_P(ConstructorTest, BucketCount) { - TypeParam m(123); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHash) { - using H = typename TypeParam::hasher; - H hasher; - TypeParam m(123, hasher); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHashEqual) { - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - H hasher; - E equal; - TypeParam m(123, hasher, equal); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHashEqualAlloc) { - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(123, hasher, equal, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); - - const auto& cm = m; - EXPECT_EQ(cm.hash_function(), hasher); - EXPECT_EQ(cm.key_eq(), equal); - EXPECT_EQ(cm.get_allocator(), alloc); - EXPECT_TRUE(cm.empty()); - EXPECT_THAT(keys(cm), ::testing::UnorderedElementsAre()); - EXPECT_GE(cm.bucket_count(), 123); -} - -template -struct is_std_unordered_set : std::false_type {}; - -template -struct is_std_unordered_set> : std::true_type {}; - -#if defined(UNORDERED_SET_CXX14) || defined(UNORDERED_SET_CXX17) -using has_cxx14_std_apis = std::true_type; -#else -using has_cxx14_std_apis = std::false_type; -#endif - -template -using expect_cxx14_apis = - absl::disjunction>, - has_cxx14_std_apis>; - -template -void BucketCountAllocTest(std::false_type) {} - -template -void BucketCountAllocTest(std::true_type) { - using A = typename TypeParam::allocator_type; - A alloc(0); - TypeParam m(123, alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountAlloc) { - BucketCountAllocTest(expect_cxx14_apis()); -} - -template -void BucketCountHashAllocTest(std::false_type) {} - -template -void BucketCountHashAllocTest(std::true_type) { - using H = typename TypeParam::hasher; - using A = typename TypeParam::allocator_type; - H hasher; - A alloc(0); - TypeParam m(123, hasher, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, BucketCountHashAlloc) { - BucketCountHashAllocTest(expect_cxx14_apis()); -} - -#if ABSL_UNORDERED_SUPPORTS_ALLOC_CTORS -using has_alloc_std_constructors = std::true_type; -#else -using has_alloc_std_constructors = std::false_type; -#endif - -template -using expect_alloc_constructors = - absl::disjunction>, - has_alloc_std_constructors>; - -template -void AllocTest(std::false_type) {} - -template -void AllocTest(std::true_type) { - using A = typename TypeParam::allocator_type; - A alloc(0); - TypeParam m(alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_TRUE(m.empty()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); -} - -TYPED_TEST_P(ConstructorTest, Alloc) { - AllocTest(expect_alloc_constructors()); -} - -TYPED_TEST_P(ConstructorTest, InputIteratorBucketHashEqualAlloc) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - std::vector values; - for (size_t i = 0; i != 10; ++i) - values.push_back(hash_internal::Generator()()); - TypeParam m(values.begin(), values.end(), 123, hasher, equal, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -template -void InputIteratorBucketAllocTest(std::false_type) {} - -template -void InputIteratorBucketAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using A = typename TypeParam::allocator_type; - A alloc(0); - std::vector values; - for (size_t i = 0; i != 10; ++i) - values.push_back(hash_internal::Generator()()); - TypeParam m(values.begin(), values.end(), 123, alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InputIteratorBucketAlloc) { - InputIteratorBucketAllocTest(expect_cxx14_apis()); -} - -template -void InputIteratorBucketHashAllocTest(std::false_type) {} - -template -void InputIteratorBucketHashAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using A = typename TypeParam::allocator_type; - H hasher; - A alloc(0); - std::vector values; - for (size_t i = 0; i != 10; ++i) - values.push_back(hash_internal::Generator()()); - TypeParam m(values.begin(), values.end(), 123, hasher, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InputIteratorBucketHashAlloc) { - InputIteratorBucketHashAllocTest(expect_cxx14_apis()); -} - -TYPED_TEST_P(ConstructorTest, CopyConstructor) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(hash_internal::Generator()()); - TypeParam n(m); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); - EXPECT_NE(TypeParam(0, hasher, equal, alloc), n); -} - -template -void CopyConstructorAllocTest(std::false_type) {} - -template -void CopyConstructorAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(hash_internal::Generator()()); - TypeParam n(m, A(11)); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_NE(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, CopyConstructorAlloc) { - CopyConstructorAllocTest(expect_alloc_constructors()); -} - -// TODO(alkis): Test non-propagating allocators on copy constructors. - -TYPED_TEST_P(ConstructorTest, MoveConstructor) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(hash_internal::Generator()()); - TypeParam t(m); - TypeParam n(std::move(t)); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -template -void MoveConstructorAllocTest(std::false_type) {} - -template -void MoveConstructorAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(123, hasher, equal, alloc); - for (size_t i = 0; i != 10; ++i) m.insert(hash_internal::Generator()()); - TypeParam t(m); - TypeParam n(std::move(t), A(1)); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_NE(m.get_allocator(), n.get_allocator()); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, MoveConstructorAlloc) { - MoveConstructorAllocTest(expect_alloc_constructors()); -} - -// TODO(alkis): Test non-propagating allocators on move constructors. - -TYPED_TEST_P(ConstructorTest, InitializerListBucketHashEqualAlloc) { - using T = hash_internal::GeneratedType; - hash_internal::Generator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - TypeParam m(values, 123, hasher, equal, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.key_eq(), equal); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -template -void InitializerListBucketAllocTest(std::false_type) {} - -template -void InitializerListBucketAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using A = typename TypeParam::allocator_type; - hash_internal::Generator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - A alloc(0); - TypeParam m(values, 123, alloc); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InitializerListBucketAlloc) { - InitializerListBucketAllocTest(expect_cxx14_apis()); -} - -template -void InitializerListBucketHashAllocTest(std::false_type) {} - -template -void InitializerListBucketHashAllocTest(std::true_type) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using A = typename TypeParam::allocator_type; - H hasher; - A alloc(0); - hash_internal::Generator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m(values, 123, hasher, alloc); - EXPECT_EQ(m.hash_function(), hasher); - EXPECT_EQ(m.get_allocator(), alloc); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_GE(m.bucket_count(), 123); -} - -TYPED_TEST_P(ConstructorTest, InitializerListBucketHashAlloc) { - InitializerListBucketHashAllocTest(expect_cxx14_apis()); -} - -TYPED_TEST_P(ConstructorTest, CopyAssignment) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::Generator gen; - TypeParam m({gen(), gen(), gen()}, 123, hasher, equal, alloc); - TypeParam n; - n = m; - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m, n); -} - -// TODO(alkis): Test [non-]propagating allocators on move/copy assignments -// (it depends on traits). - -TYPED_TEST_P(ConstructorTest, MoveAssignment) { - using T = hash_internal::GeneratedType; - using H = typename TypeParam::hasher; - using E = typename TypeParam::key_equal; - using A = typename TypeParam::allocator_type; - H hasher; - E equal; - A alloc(0); - hash_internal::Generator gen; - TypeParam m({gen(), gen(), gen()}, 123, hasher, equal, alloc); - TypeParam t(m); - TypeParam n; - n = std::move(t); - EXPECT_EQ(m.hash_function(), n.hash_function()); - EXPECT_EQ(m.key_eq(), n.key_eq()); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, AssignmentFromInitializerList) { - using T = hash_internal::GeneratedType; - hash_internal::Generator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m; - m = values; - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); -} - -TYPED_TEST_P(ConstructorTest, AssignmentOverwritesExisting) { - using T = hash_internal::GeneratedType; - hash_internal::Generator gen; - TypeParam m({gen(), gen(), gen()}); - TypeParam n({gen()}); - n = m; - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, MoveAssignmentOverwritesExisting) { - using T = hash_internal::GeneratedType; - hash_internal::Generator gen; - TypeParam m({gen(), gen(), gen()}); - TypeParam t(m); - TypeParam n({gen()}); - n = std::move(t); - EXPECT_EQ(m, n); -} - -TYPED_TEST_P(ConstructorTest, AssignmentFromInitializerListOverwritesExisting) { - using T = hash_internal::GeneratedType; - hash_internal::Generator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m; - m = values; - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); -} - -TYPED_TEST_P(ConstructorTest, AssignmentOnSelf) { - using T = hash_internal::GeneratedType; - hash_internal::Generator gen; - std::initializer_list values = {gen(), gen(), gen(), gen(), gen()}; - TypeParam m(values); - m = *&m; // Avoid -Wself-assign. - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); -} - -REGISTER_TYPED_TEST_SUITE_P( - ConstructorTest, NoArgs, BucketCount, BucketCountHash, BucketCountHashEqual, - BucketCountHashEqualAlloc, BucketCountAlloc, BucketCountHashAlloc, Alloc, - InputIteratorBucketHashEqualAlloc, InputIteratorBucketAlloc, - InputIteratorBucketHashAlloc, CopyConstructor, CopyConstructorAlloc, - MoveConstructor, MoveConstructorAlloc, InitializerListBucketHashEqualAlloc, - InitializerListBucketAlloc, InitializerListBucketHashAlloc, CopyAssignment, - MoveAssignment, AssignmentFromInitializerList, AssignmentOverwritesExisting, - MoveAssignmentOverwritesExisting, - AssignmentFromInitializerListOverwritesExisting, AssignmentOnSelf); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_CONSTRUCTOR_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_set_lookup_test.h b/tests/googletest/include/absl/container/internal/unordered_set_lookup_test.h deleted file mode 100644 index b35f766e..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_set_lookup_test.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_ - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/container/internal/hash_generator_testing.h" -#include "absl/container/internal/hash_policy_testing.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class LookupTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(LookupTest); - -TYPED_TEST_P(LookupTest, Count) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& v : values) - EXPECT_EQ(0, m.count(v)) << ::testing::PrintToString(v); - m.insert(values.begin(), values.end()); - for (const auto& v : values) - EXPECT_EQ(1, m.count(v)) << ::testing::PrintToString(v); -} - -TYPED_TEST_P(LookupTest, Find) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& v : values) - EXPECT_TRUE(m.end() == m.find(v)) << ::testing::PrintToString(v); - m.insert(values.begin(), values.end()); - for (const auto& v : values) { - typename TypeParam::iterator it = m.find(v); - static_assert(std::is_same::value, - ""); - static_assert(std::is_same())>::value, - ""); - EXPECT_TRUE(m.end() != it) << ::testing::PrintToString(v); - EXPECT_EQ(v, *it) << ::testing::PrintToString(v); - } -} - -TYPED_TEST_P(LookupTest, EqualRange) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - for (const auto& v : values) { - auto r = m.equal_range(v); - ASSERT_EQ(0, std::distance(r.first, r.second)); - } - m.insert(values.begin(), values.end()); - for (const auto& v : values) { - auto r = m.equal_range(v); - ASSERT_EQ(1, std::distance(r.first, r.second)); - EXPECT_EQ(v, *r.first); - } -} - -REGISTER_TYPED_TEST_SUITE_P(LookupTest, Count, Find, EqualRange); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_set_members_test.h b/tests/googletest/include/absl/container/internal/unordered_set_members_test.h deleted file mode 100644 index 4c5e104a..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_set_members_test.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2019 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MEMBERS_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MEMBERS_TEST_H_ - -#include -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/meta/type_traits.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class MembersTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(MembersTest); - -template -void UseType() {} - -TYPED_TEST_P(MembersTest, Typedefs) { - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((absl::conjunction< - absl::negation>, - std::is_integral>())); - EXPECT_TRUE((absl::conjunction< - std::is_signed, - std::is_integral>())); - EXPECT_TRUE((std::is_convertible< - decltype(std::declval()( - std::declval())), - size_t>())); - EXPECT_TRUE((std::is_convertible< - decltype(std::declval()( - std::declval(), - std::declval())), - bool>())); - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((std::is_same())); - EXPECT_TRUE((std::is_same::pointer, - typename TypeParam::pointer>())); - EXPECT_TRUE( - (std::is_same::const_pointer, - typename TypeParam::const_pointer>())); -} - -TYPED_TEST_P(MembersTest, SimpleFunctions) { - EXPECT_GT(TypeParam().max_size(), 0); -} - -TYPED_TEST_P(MembersTest, BeginEnd) { - TypeParam t = {typename TypeParam::value_type{}}; - EXPECT_EQ(t.begin(), t.cbegin()); - EXPECT_EQ(t.end(), t.cend()); - EXPECT_NE(t.begin(), t.end()); - EXPECT_NE(t.cbegin(), t.cend()); -} - -REGISTER_TYPED_TEST_SUITE_P(MembersTest, Typedefs, SimpleFunctions, BeginEnd); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MEMBERS_TEST_H_ diff --git a/tests/googletest/include/absl/container/internal/unordered_set_modifiers_test.h b/tests/googletest/include/absl/container/internal/unordered_set_modifiers_test.h deleted file mode 100644 index d8864bb2..00000000 --- a/tests/googletest/include/absl/container/internal/unordered_set_modifiers_test.h +++ /dev/null @@ -1,221 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MODIFIERS_TEST_H_ -#define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MODIFIERS_TEST_H_ - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/container/internal/hash_generator_testing.h" -#include "absl/container/internal/hash_policy_testing.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN -namespace container_internal { - -template -class ModifiersTest : public ::testing::Test {}; - -TYPED_TEST_SUITE_P(ModifiersTest); - -TYPED_TEST_P(ModifiersTest, Clear) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - m.clear(); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_TRUE(m.empty()); -} - -TYPED_TEST_P(ModifiersTest, Insert) { - using T = hash_internal::GeneratedType; - T val = hash_internal::Generator()(); - TypeParam m; - auto p = m.insert(val); - EXPECT_TRUE(p.second); - EXPECT_EQ(val, *p.first); - p = m.insert(val); - EXPECT_FALSE(p.second); -} - -TYPED_TEST_P(ModifiersTest, InsertHint) { - using T = hash_internal::GeneratedType; - T val = hash_internal::Generator()(); - TypeParam m; - auto it = m.insert(m.end(), val); - EXPECT_TRUE(it != m.end()); - EXPECT_EQ(val, *it); - it = m.insert(it, val); - EXPECT_TRUE(it != m.end()); - EXPECT_EQ(val, *it); -} - -TYPED_TEST_P(ModifiersTest, InsertRange) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m; - m.insert(values.begin(), values.end()); - ASSERT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); -} - -TYPED_TEST_P(ModifiersTest, InsertWithinCapacity) { - using T = hash_internal::GeneratedType; - T val = hash_internal::Generator()(); - TypeParam m; - m.reserve(10); - const size_t original_capacity = m.bucket_count(); - m.insert(val); - EXPECT_EQ(m.bucket_count(), original_capacity); - m.insert(val); - EXPECT_EQ(m.bucket_count(), original_capacity); -} - -TYPED_TEST_P(ModifiersTest, InsertRangeWithinCapacity) { -#if !defined(__GLIBCXX__) - using T = hash_internal::GeneratedType; - std::vector base_values; - std::generate_n(std::back_inserter(base_values), 10, - hash_internal::Generator()); - std::vector values; - while (values.size() != 100) { - values.insert(values.end(), base_values.begin(), base_values.end()); - } - TypeParam m; - m.reserve(10); - const size_t original_capacity = m.bucket_count(); - m.insert(values.begin(), values.end()); - EXPECT_EQ(m.bucket_count(), original_capacity); -#endif -} - -TYPED_TEST_P(ModifiersTest, Emplace) { - using T = hash_internal::GeneratedType; - T val = hash_internal::Generator()(); - TypeParam m; - // TODO(alkis): We need a way to run emplace in a more meaningful way. Perhaps - // with test traits/policy. - auto p = m.emplace(val); - EXPECT_TRUE(p.second); - EXPECT_EQ(val, *p.first); - p = m.emplace(val); - EXPECT_FALSE(p.second); - EXPECT_EQ(val, *p.first); -} - -TYPED_TEST_P(ModifiersTest, EmplaceHint) { - using T = hash_internal::GeneratedType; - T val = hash_internal::Generator()(); - TypeParam m; - // TODO(alkis): We need a way to run emplace in a more meaningful way. Perhaps - // with test traits/policy. - auto it = m.emplace_hint(m.end(), val); - EXPECT_EQ(val, *it); - it = m.emplace_hint(it, val); - EXPECT_EQ(val, *it); -} - -template -using IfNotVoid = typename std::enable_if::value, V>::type; - -// In openmap we chose not to return the iterator from erase because that's -// more expensive. As such we adapt erase to return an iterator here. -struct EraseFirst { - template - auto operator()(Map* m, int) const - -> IfNotVoiderase(m->begin()))> { - return m->erase(m->begin()); - } - template - typename Map::iterator operator()(Map* m, ...) const { - auto it = m->begin(); - m->erase(it++); - return it; - } -}; - -TYPED_TEST_P(ModifiersTest, Erase) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - std::vector values2; - for (const auto& val : values) - if (val != *m.begin()) values2.push_back(val); - auto it = EraseFirst()(&m, 0); - ASSERT_TRUE(it != m.end()); - EXPECT_EQ(1, std::count(values2.begin(), values2.end(), *it)); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values2.begin(), - values2.end())); -} - -TYPED_TEST_P(ModifiersTest, EraseRange) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - auto it = m.erase(m.begin(), m.end()); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAre()); - EXPECT_TRUE(it == m.end()); -} - -TYPED_TEST_P(ModifiersTest, EraseKey) { - using T = hash_internal::GeneratedType; - std::vector values; - std::generate_n(std::back_inserter(values), 10, - hash_internal::Generator()); - TypeParam m(values.begin(), values.end()); - ASSERT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values)); - EXPECT_EQ(1, m.erase(values[0])); - EXPECT_EQ(0, std::count(m.begin(), m.end(), values[0])); - EXPECT_THAT(keys(m), ::testing::UnorderedElementsAreArray(values.begin() + 1, - values.end())); -} - -TYPED_TEST_P(ModifiersTest, Swap) { - using T = hash_internal::GeneratedType; - std::vector v1; - std::vector v2; - std::generate_n(std::back_inserter(v1), 5, hash_internal::Generator()); - std::generate_n(std::back_inserter(v2), 5, hash_internal::Generator()); - TypeParam m1(v1.begin(), v1.end()); - TypeParam m2(v2.begin(), v2.end()); - EXPECT_THAT(keys(m1), ::testing::UnorderedElementsAreArray(v1)); - EXPECT_THAT(keys(m2), ::testing::UnorderedElementsAreArray(v2)); - m1.swap(m2); - EXPECT_THAT(keys(m1), ::testing::UnorderedElementsAreArray(v2)); - EXPECT_THAT(keys(m2), ::testing::UnorderedElementsAreArray(v1)); -} - -// TODO(alkis): Write tests for extract. -// TODO(alkis): Write tests for merge. - -REGISTER_TYPED_TEST_SUITE_P(ModifiersTest, Clear, Insert, InsertHint, - InsertRange, InsertWithinCapacity, - InsertRangeWithinCapacity, Emplace, EmplaceHint, - Erase, EraseRange, EraseKey, Swap); - -} // namespace container_internal -ABSL_NAMESPACE_END -} // namespace absl - -#endif // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_MODIFIERS_TEST_H_ diff --git a/tests/googletest/include/absl/hash/hash_testing.h b/tests/googletest/include/absl/hash/hash_testing.h deleted file mode 100644 index 1e1c5741..00000000 --- a/tests/googletest/include/absl/hash/hash_testing.h +++ /dev/null @@ -1,378 +0,0 @@ -// Copyright 2018 The Abseil Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ABSL_HASH_HASH_TESTING_H_ -#define ABSL_HASH_HASH_TESTING_H_ - -#include -#include -#include -#include - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "absl/hash/internal/spy_hash_state.h" -#include "absl/meta/type_traits.h" -#include "absl/strings/str_cat.h" -#include "absl/types/variant.h" - -namespace absl { -ABSL_NAMESPACE_BEGIN - -// Run the absl::Hash algorithm over all the elements passed in and verify that -// their hash expansion is congruent with their `==` operator. -// -// It is used in conjunction with EXPECT_TRUE. Failures will output information -// on what requirement failed and on which objects. -// -// Users should pass a collection of types as either an initializer list or a -// container of cases. -// -// EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly( -// {v1, v2, ..., vN})); -// -// std::vector cases; -// // Fill cases... -// EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly(cases)); -// -// Users can pass a variety of types for testing heterogeneous lookup with -// `std::make_tuple`: -// -// EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly( -// std::make_tuple(v1, v2, ..., vN))); -// -// -// Ideally, the values passed should provide enough coverage of the `==` -// operator and the AbslHashValue implementations. -// For dynamically sized types, the empty state should usually be included in -// the values. -// -// The function accepts an optional comparator function, in case that `==` is -// not enough for the values provided. -// -// Usage: -// -// EXPECT_TRUE(absl::VerifyTypeImplementsAbslHashCorrectly( -// std::make_tuple(v1, v2, ..., vN), MyCustomEq{})); -// -// It checks the following requirements: -// 1. The expansion for a value is deterministic. -// 2. For any two objects `a` and `b` in the sequence, if `a == b` evaluates -// to true, then their hash expansion must be equal. -// 3. If `a == b` evaluates to false their hash expansion must be unequal. -// 4. If `a == b` evaluates to false neither hash expansion can be a -// suffix of the other. -// 5. AbslHashValue overloads should not be called by the user. They are only -// meant to be called by the framework. Users should call H::combine() and -// H::combine_contiguous(). -// 6. No moved-from instance of the hash state is used in the implementation -// of AbslHashValue. -// -// The values do not have to have the same type. This can be useful for -// equivalent types that support heterogeneous lookup. -// -// A possible reason for breaking (2) is combining state in the hash expansion -// that was not used in `==`. -// For example: -// -// struct Bad2 { -// int a, b; -// template -// friend H AbslHashValue(H state, Bad2 x) { -// // Uses a and b. -// return H::combine(std::move(state), x.a, x.b); -// } -// friend bool operator==(Bad2 x, Bad2 y) { -// // Only uses a. -// return x.a == y.a; -// } -// }; -// -// As for (3), breaking this usually means that there is state being passed to -// the `==` operator that is not used in the hash expansion. -// For example: -// -// struct Bad3 { -// int a, b; -// template -// friend H AbslHashValue(H state, Bad3 x) { -// // Only uses a. -// return H::combine(std::move(state), x.a); -// } -// friend bool operator==(Bad3 x, Bad3 y) { -// // Uses a and b. -// return x.a == y.a && x.b == y.b; -// } -// }; -// -// Finally, a common way to break 4 is by combining dynamic ranges without -// combining the size of the range. -// For example: -// -// struct Bad4 { -// int *p, size; -// template -// friend H AbslHashValue(H state, Bad4 x) { -// return H::combine_contiguous(std::move(state), x.p, x.p + x.size); -// } -// friend bool operator==(Bad4 x, Bad4 y) { -// // Compare two ranges for equality. C++14 code can instead use std::equal. -// return absl::equal(x.p, x.p + x.size, y.p, y.p + y.size); -// } -// }; -// -// An easy solution to this is to combine the size after combining the range, -// like so: -// template -// friend H AbslHashValue(H state, Bad4 x) { -// return H::combine( -// H::combine_contiguous(std::move(state), x.p, x.p + x.size), x.size); -// } -// -template -ABSL_MUST_USE_RESULT testing::AssertionResult -VerifyTypeImplementsAbslHashCorrectly(const Container& values); - -template -ABSL_MUST_USE_RESULT testing::AssertionResult -VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals); - -template -ABSL_MUST_USE_RESULT testing::AssertionResult -VerifyTypeImplementsAbslHashCorrectly(std::initializer_list values); - -template -ABSL_MUST_USE_RESULT testing::AssertionResult -VerifyTypeImplementsAbslHashCorrectly(std::initializer_list values, - Eq equals); - -namespace hash_internal { - -struct PrintVisitor { - size_t index; - template - std::string operator()(const T* value) const { - return absl::StrCat("#", index, "(", testing::PrintToString(*value), ")"); - } -}; - -template -struct EqVisitor { - Eq eq; - template - bool operator()(const T* t, const U* u) const { - return eq(*t, *u); - } -}; - -struct ExpandVisitor { - template - SpyHashState operator()(const T* value) const { - return SpyHashState::combine(SpyHashState(), *value); - } -}; - -template -ABSL_MUST_USE_RESULT testing::AssertionResult -VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals) { - using V = typename Container::value_type; - - struct Info { - const V& value; - size_t index; - std::string ToString() const { - return absl::visit(PrintVisitor{index}, value); - } - SpyHashState expand() const { return absl::visit(ExpandVisitor{}, value); } - }; - - using EqClass = std::vector; - std::vector classes; - - // Gather the values in equivalence classes. - size_t i = 0; - for (const auto& value : values) { - EqClass* c = nullptr; - for (auto& eqclass : classes) { - if (absl::visit(EqVisitor{equals}, value, eqclass[0].value)) { - c = &eqclass; - break; - } - } - if (c == nullptr) { - classes.emplace_back(); - c = &classes.back(); - } - c->push_back({value, i}); - ++i; - - // Verify potential errors captured by SpyHashState. - if (auto error = c->back().expand().error()) { - return testing::AssertionFailure() << *error; - } - } - - if (classes.size() < 2) { - return testing::AssertionFailure() - << "At least two equivalence classes are expected."; - } - - // We assume that equality is correctly implemented. - // Now we verify that AbslHashValue is also correctly implemented. - - for (const auto& c : classes) { - // All elements of the equivalence class must have the same hash - // expansion. - const SpyHashState expected = c[0].expand(); - for (const Info& v : c) { - if (v.expand() != v.expand()) { - return testing::AssertionFailure() - << "Hash expansion for " << v.ToString() - << " is non-deterministic."; - } - if (v.expand() != expected) { - return testing::AssertionFailure() - << "Values " << c[0].ToString() << " and " << v.ToString() - << " evaluate as equal but have an unequal hash expansion."; - } - } - - // Elements from other classes must have different hash expansion. - for (const auto& c2 : classes) { - if (&c == &c2) continue; - const SpyHashState c2_hash = c2[0].expand(); - switch (SpyHashState::Compare(expected, c2_hash)) { - case SpyHashState::CompareResult::kEqual: - return testing::AssertionFailure() - << "Values " << c[0].ToString() << " and " << c2[0].ToString() - << " evaluate as unequal but have an equal hash expansion."; - case SpyHashState::CompareResult::kBSuffixA: - return testing::AssertionFailure() - << "Hash expansion of " << c2[0].ToString() - << " is a suffix of the hash expansion of " << c[0].ToString() - << "."; - case SpyHashState::CompareResult::kASuffixB: - return testing::AssertionFailure() - << "Hash expansion of " << c[0].ToString() - << " is a suffix of the hash expansion of " << c2[0].ToString() - << "."; - case SpyHashState::CompareResult::kUnequal: - break; - } - } - } - return testing::AssertionSuccess(); -} - -template -struct TypeSet { - template ...>::value> - struct Insert { - using type = TypeSet; - }; - template - struct Insert { - using type = TypeSet; - }; - - template