proxygen
PerfectIndexMapTest.cpp File Reference

Go to the source code of this file.

Classes

struct  PerfectIndexMapTestsTemplateParams< Key, OtherKey, NoneKey, PerfectHashStrToKey, AllowDuplicates, CaseInsensitive, KeyCommonOffset, NumKeys >
 
class  PerfectIndexMapTests< T >
 

Typedefs

typedef testing::Types< PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes >, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes > > TestTypes
 

Functions

 TYPED_TEST_CASE (PerfectIndexMapTests, TestTypes)
 
 TYPED_TEST (PerfectIndexMapTests, BasicKeySetAddRemoveGetSingleOrNone)
 
 TYPED_TEST (PerfectIndexMapTests, BasicOtherKeySetAddRemoveGetSingleOrNone)
 
 TYPED_TEST (PerfectIndexMapTests, OtherStringCaseSensitivity)
 

Typedef Documentation

typedef testing::Types< PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes>, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, true, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes>, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, true, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes>, PerfectIndexMapTestsTemplateParams< HTTPHeaderCode, HTTP_HEADER_OTHER, HTTP_HEADER_NONE, HTTPCommonHeaders::hash, false, false, HTTPHeaderCodeCommonOffset, HTTPCommonHeaders::num_header_codes> > TestTypes

Definition at line 102 of file PerfectIndexMapTest.cpp.

Function Documentation

TYPED_TEST ( PerfectIndexMapTests  ,
BasicKeySetAddRemoveGetSingleOrNone   
)

Definition at line 105 of file PerfectIndexMapTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, EXPECT_EQ, testing::Key(), and uint64_t.

105  {
106  typedef typename TypeParam::TKey Key;
107 
108  EXPECT_EQ(this->testMap_.size(), 0);
109 
110  // Insert numInserted distinct keys and duplicate values into the map.
111  auto numInserted = TypeParam::TNumKeys - TypeParam::TKeyCommonOffset;
112  for (uint64_t j = TypeParam::TKeyCommonOffset; j < TypeParam::TNumKeys; ++j) {
113  this->testMap_.set(static_cast<Key>(j), std::to_string(j));
114  }
115  EXPECT_EQ(this->testMap_.size(), numInserted);
116 
117  // Setting a duplicate should not increase the size of the map, regardless
118  // of whether duplicates are supported
119  Key key = static_cast<Key>(TypeParam::TKeyCommonOffset);
120  this->testMap_.set(key, std::to_string(TypeParam::TKeyCommonOffset));
121  EXPECT_EQ(this->testMap_.size(), numInserted);
122 
123  // Adding is only allowed when duplicates are and so here we expect the size
124  // of the map to change.
125  if (TypeParam::TAllowDuplicates) {
126  this->testMap_.add(key, std::to_string(TypeParam::TKeyCommonOffset));
127  EXPECT_EQ(this->testMap_.size(), numInserted + 1);
128  }
129 
130  // Remove the last added element in the map (and its duplicate if applicable)
131  // Adjusts numInserted as appropriate
132  this->testMap_.remove(key);
133  EXPECT_EQ(this->testMap_.size(), --numInserted);
134 
135  // Verify the integrity of the map
136  for (uint64_t j = TypeParam::TKeyCommonOffset + 1;
137  j < TypeParam::TNumKeys; ++j) {
138  key = static_cast<Key>(j);
139  auto optional = this->testMap_.getSingleOrNone(key);
140  ASSERT_TRUE(optional.hasValue());
141  ASSERT_EQ(optional.value(), std::to_string(j));
142  }
143 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
internal::KeyMatcher< M > Key(M inner_matcher)
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TYPED_TEST ( PerfectIndexMapTests  ,
BasicOtherKeySetAddRemoveGetSingleOrNone   
)

Definition at line 145 of file PerfectIndexMapTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, EXPECT_EQ, string, and val.

145  {
146  EXPECT_EQ(this->testMap_.size(), 0);
147 
148  // Insert numInserted distinct keys and values in to the map
149  int numInserted = 10;
151  for (int num = 0; num < numInserted; ++num) {
152  val = std::to_string(num);
153  this->testMap_.set(val, val);
154  }
155  EXPECT_EQ(this->testMap_.size(), numInserted);
156 
157  // Setting a duplicate should not increase the size of the map, regardless
158  // of whether duplicates are supported
159  this->testMap_.set(val, val);
160  EXPECT_EQ(this->testMap_.size(), numInserted);
161 
162  // Adding is only allowed when duplicates are and so here we expect the size
163  // of the map to change.
164  if (TypeParam::TAllowDuplicates) {
165  this->testMap_.add(val, val);
166  EXPECT_EQ(this->testMap_.size(), numInserted + 1);
167  }
168 
169  // Remove the last added element in the map (and its duplicate if applicable)
170  // Adjusts numInserted as appropriate
171  this->testMap_.remove(val);
172  EXPECT_EQ(this->testMap_.size(), --numInserted);
173 
174  // Verify the integrity of the map
175  for (int num = 0; num < numInserted; ++num) {
176  val = std::to_string(num);
177  auto optional = this->testMap_.getSingleOrNone(val);
178  ASSERT_TRUE(optional.hasValue());
179  ASSERT_EQ(optional.value(), val);
180  }
181 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
double val
Definition: String.cpp:273
const char * string
Definition: Conv.cpp:212
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TYPED_TEST ( PerfectIndexMapTests  ,
OtherStringCaseSensitivity   
)

Definition at line 188 of file PerfectIndexMapTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::Optional< Value >::has_value(), folly::Optional< Value >::hasValue(), string, and folly::Optional< Value >::value().

188  {
189  std::string testString = "test";
190  std::string modTestString = "tEsT";
191  std::string addModTestString = "TeSt";
192  this->testMap_.set(testString, testString);
193 
194  auto currentCount = this->testMap_.size();
196  if (TypeParam::TCaseInsensitive) {
197  optional = this->testMap_.getSingleOrNone(modTestString);
198  ASSERT_TRUE(optional.hasValue());
199  ASSERT_EQ(optional.value(), testString);
200 
201  this->testMap_.set(modTestString, modTestString);
202  EXPECT_EQ(this->testMap_.size(), currentCount);
203 
204  optional = this->testMap_.getSingleOrNone(testString);
205  ASSERT_TRUE(optional.hasValue());
206  ASSERT_EQ(optional.value(), modTestString);
207  } else {
208  this->testMap_.set(modTestString, modTestString);
209  EXPECT_EQ(this->testMap_.size(), ++currentCount);
210 
211  this->testMap_.set(testString, testString);
212  EXPECT_EQ(this->testMap_.size(), currentCount);
213 
214  optional = this->testMap_.getSingleOrNone(testString);
215  ASSERT_TRUE(optional.hasValue());
216  ASSERT_EQ(optional.value(), testString);
217 
218  optional = this->testMap_.getSingleOrNone(modTestString);
219  ASSERT_TRUE(optional.hasValue());
220  ASSERT_EQ(optional.value(), modTestString);
221  }
222 
223  if (TypeParam::TAllowDuplicates) {
224  // Finally verify that two exact same keys are treated as duplicates.
225  this->testMap_.add(addModTestString, addModTestString);
226  optional = this->testMap_.getSingleOrNone(testString);
227  if (TypeParam::TCaseInsensitive) {
228  EXPECT_FALSE(optional.hasValue());
229  } else {
230  EXPECT_TRUE(optional.has_value());
231  }
232  }
233 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TYPED_TEST_CASE ( PerfectIndexMapTests  ,
TestTypes   
)