proxygen
F14MapTest.cpp File Reference
#include <folly/container/F14Map.h>
#include <algorithm>
#include <unordered_map>
#include <folly/Conv.h>
#include <folly/FBString.h>
#include <folly/container/test/F14TestUtil.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Functions

template<template< typename, typename, typename, typename, typename > class TMap>
void testCustomSwap ()
 
 TEST (F14Map, customSwap)
 
 TEST (F14Map, getAllocatedMemorySize)
 
template<typename M >
void runVisitContiguousRangesTest (int n)
 
template<typename M >
void runVisitContiguousRangesTest ()
 
 TEST (F14ValueMap, visitContiguousRanges)
 
 TEST (F14NodeMap, visitContiguousRanges)
 
 TEST (F14VectorMap, visitContiguousRanges)
 
 TEST (F14FastMap, visitContiguousRanges)
 

Function Documentation

template<typename M >
void runVisitContiguousRangesTest ( int  n)

Definition at line 132 of file F14MapTest.cpp.

References ASSERT_TRUE, b, EXPECT_FALSE, EXPECT_TRUE, i, M, and map().

132  {
133  M map;
134 
135  for (int i = 0; i < n; ++i) {
136  map[i] = i;
137  map.erase(i / 2);
138  }
139 
140  std::unordered_map<uintptr_t, bool> visited;
141  for (auto& entry : map) {
142  visited[reinterpret_cast<uintptr_t>(&entry)] = false;
143  }
144 
145  map.visitContiguousRanges([&](auto b, auto e) {
146  for (auto i = b; i != e; ++i) {
147  auto iter = visited.find(reinterpret_cast<uintptr_t>(i));
148  ASSERT_TRUE(iter != visited.end());
149  EXPECT_FALSE(iter->second);
150  iter->second = true;
151  }
152  });
153 
154  // ensure no entries were skipped
155  for (auto& e : visited) {
156  EXPECT_TRUE(e.second);
157  }
158 }
char b
static Map map(mapCap)
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
template<typename M >
void runVisitContiguousRangesTest ( )

Definition at line 161 of file F14MapTest.cpp.

161  {
162  runVisitContiguousRangesTest<M>(0); // empty
163  runVisitContiguousRangesTest<M>(5); // single chunk
164  runVisitContiguousRangesTest<M>(1000); // many chunks
165 }
TEST ( F14Map  ,
customSwap   
)

Definition at line 46 of file F14MapTest.cpp.

References count, EXPECT_EQ, EXPECT_GE, EXPECT_GT, folly::f14::detail::getF14IntrinsicsMode(), i, m, folly::f14::detail::None, folly::f14::resetTracking(), folly::size(), folly::f14::testAllocatedBlockCount, and folly::f14::testAllocatedMemorySize.

46  {
47  testCustomSwap<folly::F14ValueMap>();
48  testCustomSwap<folly::F14NodeMap>();
49  testCustomSwap<folly::F14VectorMap>();
50  testCustomSwap<folly::F14FastMap>();
51 }
TEST ( F14Map  ,
getAllocatedMemorySize   
)

Definition at line 121 of file F14MapTest.cpp.

121  {
122  runAllocatedMemorySizeTests<bool, bool>();
123  runAllocatedMemorySizeTests<int, int>();
124  runAllocatedMemorySizeTests<bool, std::string>();
125  runAllocatedMemorySizeTests<double, std::string>();
126  runAllocatedMemorySizeTests<std::string, int>();
127  runAllocatedMemorySizeTests<std::string, std::string>();
128  runAllocatedMemorySizeTests<folly::fbstring, long>();
129 }
TEST ( F14ValueMap  ,
visitContiguousRanges   
)

Definition at line 167 of file F14MapTest.cpp.

167  {
168  runVisitContiguousRangesTest<folly::F14ValueMap<int, int>>();
169 }
TEST ( F14NodeMap  ,
visitContiguousRanges   
)

Definition at line 171 of file F14MapTest.cpp.

171  {
172  runVisitContiguousRangesTest<folly::F14NodeMap<int, int>>();
173 }
TEST ( F14VectorMap  ,
visitContiguousRanges   
)

Definition at line 175 of file F14MapTest.cpp.

175  {
176  runVisitContiguousRangesTest<folly::F14VectorMap<int, int>>();
177 }
template<template< typename, typename, typename, typename, typename > class TMap>
void testCustomSwap ( )

Definition at line 29 of file F14MapTest.cpp.

References dist, EXPECT_EQ, folly::f14::resetTracking(), and folly::f14::swap().

29  {
30  using std::swap;
31 
32  TMap<
33  int,
34  int,
38  m0, m1;
40  swap(m0, m1);
41 
42  EXPECT_EQ(
44 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void resetTracking()
Definition: F14TestUtil.h:336
std::uniform_int_distribution< milliseconds::rep > dist
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414