unordered_set_lookup_test.h
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #ifndef ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
00016 #define ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_
00017 
00018 #include "gmock/gmock.h"
00019 #include "gtest/gtest.h"
00020 #include "absl/container/internal/hash_generator_testing.h"
00021 #include "absl/container/internal/hash_policy_testing.h"
00022 
00023 namespace absl {
00024 namespace container_internal {
00025 
00026 template <class UnordSet>
00027 class LookupTest : public ::testing::Test {};
00028 
00029 TYPED_TEST_SUITE_P(LookupTest);
00030 
00031 TYPED_TEST_P(LookupTest, Count) {
00032   using T = hash_internal::GeneratedType<TypeParam>;
00033   std::vector<T> values;
00034   std::generate_n(std::back_inserter(values), 10,
00035                   hash_internal::Generator<T>());
00036   TypeParam m;
00037   for (const auto& v : values)
00038     EXPECT_EQ(0, m.count(v)) << ::testing::PrintToString(v);
00039   m.insert(values.begin(), values.end());
00040   for (const auto& v : values)
00041     EXPECT_EQ(1, m.count(v)) << ::testing::PrintToString(v);
00042 }
00043 
00044 TYPED_TEST_P(LookupTest, Find) {
00045   using T = hash_internal::GeneratedType<TypeParam>;
00046   std::vector<T> values;
00047   std::generate_n(std::back_inserter(values), 10,
00048                   hash_internal::Generator<T>());
00049   TypeParam m;
00050   for (const auto& v : values)
00051     EXPECT_TRUE(m.end() == m.find(v)) << ::testing::PrintToString(v);
00052   m.insert(values.begin(), values.end());
00053   for (const auto& v : values) {
00054     typename TypeParam::iterator it = m.find(v);
00055     static_assert(std::is_same<const typename TypeParam::value_type&,
00056                                decltype(*it)>::value,
00057                   "");
00058     static_assert(std::is_same<const typename TypeParam::value_type*,
00059                                decltype(it.operator->())>::value,
00060                   "");
00061     EXPECT_TRUE(m.end() != it) << ::testing::PrintToString(v);
00062     EXPECT_EQ(v, *it) << ::testing::PrintToString(v);
00063   }
00064 }
00065 
00066 TYPED_TEST_P(LookupTest, EqualRange) {
00067   using T = hash_internal::GeneratedType<TypeParam>;
00068   std::vector<T> values;
00069   std::generate_n(std::back_inserter(values), 10,
00070                   hash_internal::Generator<T>());
00071   TypeParam m;
00072   for (const auto& v : values) {
00073     auto r = m.equal_range(v);
00074     ASSERT_EQ(0, std::distance(r.first, r.second));
00075   }
00076   m.insert(values.begin(), values.end());
00077   for (const auto& v : values) {
00078     auto r = m.equal_range(v);
00079     ASSERT_EQ(1, std::distance(r.first, r.second));
00080     EXPECT_EQ(v, *r.first);
00081   }
00082 }
00083 
00084 REGISTER_TYPED_TEST_CASE_P(LookupTest, Count, Find, EqualRange);
00085 
00086 }  // namespace container_internal
00087 }  // namespace absl
00088 
00089 #endif  // ABSL_CONTAINER_INTERNAL_UNORDERED_SET_LOOKUP_TEST_H_


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:16