Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:31:40

0001 // Copyright 2018 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 
0015 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
0016 #define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
0017 
0018 #include "gmock/gmock.h"
0019 #include "gtest/gtest.h"
0020 #include "absl/container/internal/hash_generator_testing.h"
0021 #include "absl/container/internal/hash_policy_testing.h"
0022 
0023 namespace absl {
0024 ABSL_NAMESPACE_BEGIN
0025 namespace container_internal {
0026 
0027 template <class UnordSet>
0028 class LookupTest : public ::testing::Test {};
0029 
0030 TYPED_TEST_SUITE_P(LookupTest);
0031 
0032 TYPED_TEST_P(LookupTest, Count) {
0033   using T = hash_internal::GeneratedType<TypeParam>;
0034   std::vector<T> values;
0035   std::generate_n(std::back_inserter(values), 10,
0036                   hash_internal::Generator<T>());
0037   TypeParam m;
0038   for (const auto& v : values)
0039     EXPECT_EQ(0, m.count(v)) << ::testing::PrintToString(v);
0040   m.insert(values.begin(), values.end());
0041   for (const auto& v : values)
0042     EXPECT_EQ(1, m.count(v)) << ::testing::PrintToString(v);
0043 }
0044 
0045 TYPED_TEST_P(LookupTest, Find) {
0046   using T = hash_internal::GeneratedType<TypeParam>;
0047   std::vector<T> values;
0048   std::generate_n(std::back_inserter(values), 10,
0049                   hash_internal::Generator<T>());
0050   TypeParam m;
0051   for (const auto& v : values)
0052     EXPECT_TRUE(m.end() == m.find(v)) << ::testing::PrintToString(v);
0053   m.insert(values.begin(), values.end());
0054   for (const auto& v : values) {
0055     typename TypeParam::iterator it = m.find(v);
0056     static_assert(std::is_same<const typename TypeParam::value_type&,
0057                                decltype(*it)>::value,
0058                   "");
0059     static_assert(std::is_same<const typename TypeParam::value_type*,
0060                                decltype(it.operator->())>::value,
0061                   "");
0062     EXPECT_TRUE(m.end() != it) << ::testing::PrintToString(v);
0063     EXPECT_EQ(v, *it) << ::testing::PrintToString(v);
0064   }
0065 }
0066 
0067 TYPED_TEST_P(LookupTest, EqualRange) {
0068   using T = hash_internal::GeneratedType<TypeParam>;
0069   std::vector<T> values;
0070   std::generate_n(std::back_inserter(values), 10,
0071                   hash_internal::Generator<T>());
0072   TypeParam m;
0073   for (const auto& v : values) {
0074     auto r = m.equal_range(v);
0075     ASSERT_EQ(0, std::distance(r.first, r.second));
0076   }
0077   m.insert(values.begin(), values.end());
0078   for (const auto& v : values) {
0079     auto r = m.equal_range(v);
0080     ASSERT_EQ(1, std::distance(r.first, r.second));
0081     EXPECT_EQ(v, *r.first);
0082   }
0083 }
0084 
0085 REGISTER_TYPED_TEST_SUITE_P(LookupTest, Count, Find, EqualRange);
0086 
0087 }  // namespace container_internal
0088 ABSL_NAMESPACE_END
0089 }  // namespace absl
0090 
0091 #endif  // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_