proxygen
F14SetTest.cpp File Reference
#include <folly/container/F14Set.h>
#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 > class TSet>
void testCustomSwap ()
 
 TEST (F14Set, customSwap)
 
 TEST (F14Set, getAllocatedMemorySize)
 
template<typename S >
void runVisitContiguousRangesTest (int n)
 
template<typename S >
void runVisitContiguousRangesTest ()
 
 TEST (F14ValueSet, visitContiguousRanges)
 
 TEST (F14NodeSet, visitContiguousRanges)
 
 TEST (F14VectorSet, visitContiguousRanges)
 
 TEST (F14FastSet, visitContiguousRanges)
 

Function Documentation

template<typename S >
void runVisitContiguousRangesTest ( int  n)

Definition at line 127 of file F14SetTest.cpp.

References ASSERT_TRUE, b, EXPECT_FALSE, EXPECT_TRUE, and i.

127  {
128  S set;
129 
130  for (int i = 0; i < n; ++i) {
131  set.insert(i);
132  set.erase(i / 2);
133  }
134 
135  std::unordered_map<uintptr_t, bool> visited;
136  for (auto& entry : set) {
137  visited[reinterpret_cast<uintptr_t>(&entry)] = false;
138  }
139 
140  set.visitContiguousRanges([&](auto b, auto e) {
141  for (auto i = b; i != e; ++i) {
142  auto iter = visited.find(reinterpret_cast<uintptr_t>(i));
143  ASSERT_TRUE(iter != visited.end());
144  EXPECT_FALSE(iter->second);
145  iter->second = true;
146  }
147  });
148 
149  // ensure no entries were skipped
150  for (auto& e : visited) {
151  EXPECT_TRUE(e.second);
152  }
153 }
char b
#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 S >
void runVisitContiguousRangesTest ( )

Definition at line 156 of file F14SetTest.cpp.

156  {
157  runVisitContiguousRangesTest<S>(0); // empty
158  runVisitContiguousRangesTest<S>(5); // single chunk
159  runVisitContiguousRangesTest<S>(1000); // many chunks
160 }
TEST ( F14Set  ,
customSwap   
)

Definition at line 43 of file F14SetTest.cpp.

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

43  {
44  testCustomSwap<folly::F14ValueSet>();
45  testCustomSwap<folly::F14NodeSet>();
46  testCustomSwap<folly::F14VectorSet>();
47  testCustomSwap<folly::F14FastSet>();
48 }
TEST ( F14Set  ,
getAllocatedMemorySize   
)

Definition at line 117 of file F14SetTest.cpp.

117  {
118  runAllocatedMemorySizeTests<bool>();
119  runAllocatedMemorySizeTests<int>();
120  runAllocatedMemorySizeTests<long>();
121  runAllocatedMemorySizeTests<double>();
122  runAllocatedMemorySizeTests<std::string>();
123  runAllocatedMemorySizeTests<folly::fbstring>();
124 }
TEST ( F14ValueSet  ,
visitContiguousRanges   
)

Definition at line 162 of file F14SetTest.cpp.

162  {
163  runVisitContiguousRangesTest<folly::F14ValueSet<int>>();
164 }
TEST ( F14NodeSet  ,
visitContiguousRanges   
)

Definition at line 166 of file F14SetTest.cpp.

166  {
167  runVisitContiguousRangesTest<folly::F14NodeSet<int>>();
168 }
TEST ( F14VectorSet  ,
visitContiguousRanges   
)

Definition at line 170 of file F14SetTest.cpp.

170  {
171  runVisitContiguousRangesTest<folly::F14VectorSet<int>>();
172 }
TEST ( F14FastSet  ,
visitContiguousRanges   
)

Definition at line 174 of file F14SetTest.cpp.

References folly::F14TableStats::compute(), EXPECT_EQ, EXPECT_FALSE, EXPECT_GT, EXPECT_NE, EXPECT_TRUE, h, i, k, folly::gen::move, populate(), s, simple, string, folly::f14::swap(), folly::pushmi::detail::t, folly::T, folly::TEST(), uint64_t, val, and verify().

174  {
175  runVisitContiguousRangesTest<folly::F14FastSet<int>>();
176 }
template<template< typename, typename, typename, typename > class TSet>
void testCustomSwap ( )

Definition at line 27 of file F14SetTest.cpp.

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

27  {
28  using std::swap;
29 
30  TSet<
31  int,
35  m0, m1;
37  swap(m0, m1);
38 
39  EXPECT_EQ(
41 }
#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