proxygen
BaseTest.cpp File Reference
#include <glog/logging.h>
#include <iosfwd>
#include <memory>
#include <random>
#include <set>
#include <vector>
#include <folly/FBVector.h>
#include <folly/MapUtil.h>
#include <folly/Memory.h>
#include <folly/String.h>
#include <folly/dynamic.h>
#include <folly/experimental/TestUtil.h>
#include <folly/gen/Base.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Classes

struct  CopyCounter
 

Macros

#define EXPECT_SAME(A, B)   static_assert(std::is_same<A, B>::value, "Mismatched: " #A ", " #B)
 

Functions

template<typename T >
ostream & operator<< (ostream &os, const set< T > &values)
 
template<typename T >
ostream & operator<< (ostream &os, const vector< T > &values)
 
template<typename A , typename B >
ostream & operator<< (ostream &os, const pair< A, B > &pair)
 
 TEST (Gen, Count)
 
 TEST (Gen, Sum)
 
 TEST (Gen, Foreach)
 
 TEST (Gen, Map)
 
 TEST (Gen, Member)
 
 TEST (Gen, Field)
 
 TEST (Gen, Seq)
 
 TEST (Gen, SeqWithStep)
 
 TEST (Gen, SeqWithStepArray)
 
 TEST (Gen, Range)
 
 TEST (Gen, RangeWithStep)
 
 TEST (Gen, FromIterators)
 
 TEST (Gen, FromMap)
 
 TEST (Gen, Filter)
 
 TEST (Gen, FilterDefault)
 
 TEST (Gen, FilterSink)
 
 TEST (Gen, Contains)
 
 TEST (Gen, Take)
 
 TEST (Gen, Stride)
 
 TEST (Gen, Sample)
 
 TEST (Gen, Skip)
 
 TEST (Gen, Until)
 
 TEST (Gen, Visit)
 
 TEST (Gen, Composed)
 
 TEST (Gen, Chain)
 
 TEST (Gen, Concat)
 
 TEST (Gen, ConcatGen)
 
 TEST (Gen, ConcatAlt)
 
 TEST (Gen, Order)
 
 TEST (Gen, OrderMoved)
 
 TEST (Gen, OrderTake)
 
 TEST (Gen, Distinct)
 
 TEST (Gen, DistinctBy)
 
 TEST (Gen, DistinctMove)
 
 TEST (Gen, DistinctInfinite)
 
 TEST (Gen, DistinctByInfinite)
 
 TEST (Gen, MinBy)
 
 TEST (Gen, MaxBy)
 
 TEST (Gen, Min)
 
 TEST (Gen, Max)
 
 TEST (Gen, Append)
 
 TEST (Gen, FromRValue)
 
 TEST (Gen, OrderBy)
 
 TEST (Gen, Foldl)
 
 TEST (Gen, Reduce)
 
 TEST (Gen, ReduceBad)
 
 TEST (Gen, Moves)
 
 TEST (Gen, First)
 
 TEST (Gen, FromCopy)
 
 TEST (Gen, Get)
 
 TEST (Gen, notEmpty)
 
 TEST (Gen, isEmpty)
 
 TEST (Gen, Any)
 
 TEST (Gen, All)
 
 TEST (Gen, Yielders)
 
 TEST (Gen, NestedYield)
 
 TEST (Gen, MapYielders)
 
 TEST (Gen, VirtualGen)
 
 TEST (Gen, CustomType)
 
 TEST (Gen, NoNeedlessCopies)
 
 TEST (Gen, NoGeneratorCopies)
 
 TEST (Gen, FromArray)
 
 TEST (Gen, FromStdArray)
 
 TEST (Gen, StringConcat)
 
 TEST (Gen, CopyCount)
 
 TEST (Gen, Dynamic)
 
 TEST (Gen, DynamicObject)
 
 TEST (Gen, Collect)
 
 TEST (Gen, Cycle)
 
 TEST (Gen, Dereference)
 
 TEST (Gen, DereferenceWithLValueRef)
 
 TEST (Gen, DereferenceWithRValueRef)
 
 TEST (Gen, Indirect)
 
 TEST (Gen, Guard)
 
 TEST (Gen, eachTryTo)
 
 TEST (Gen, Batch)
 
 TEST (Gen, BatchMove)
 
 TEST (Gen, Window)
 
 TEST (Gen, Just)
 
 TEST (Gen, GroupBy)
 
 TEST (Gen, GroupByAdjacent)
 
 TEST (Gen, Unwrap)
 
int main (int argc, char *argv[])
 

Variables

auto square = [](int x) { return x * x; }
 
auto add = [](int a, int b) { return a + b; }
 
auto multiply = [](int a, int b) { return a * b; }
 
auto product = foldl(1, multiply)
 

Macro Definition Documentation

#define EXPECT_SAME (   A,
  B 
)    static_assert(std::is_same<A, B>::value, "Mismatched: " #A ", " #B)

Definition at line 45 of file BaseTest.cpp.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 1454 of file BaseTest.cpp.

References testing::InitGoogleTest(), and RUN_ALL_TESTS().

1454  {
1455  testing::InitGoogleTest(&argc, argv);
1456  gflags::ParseCommandLineFlags(&argc, &argv, true);
1457  return RUN_ALL_TESTS();
1458 }
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2232
char ** argv
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5370
template<typename T >
ostream& operator<< ( ostream &  os,
const set< T > &  values 
)

Definition at line 53 of file BaseTest.cpp.

References folly::gen::from(), and values().

53  {
54  return os << from(values);
55 }
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
template<typename T >
ostream& operator<< ( ostream &  os,
const vector< T > &  values 
)

Definition at line 58 of file BaseTest.cpp.

References folly::value(), and values().

58  {
59  os << "[";
60  for (auto& value : values) {
61  if (&value != &values.front()) {
62  os << " ";
63  }
64  os << value;
65  }
66  return os << "]";
67 }
static const char *const value
Definition: Conv.cpp:50
template<typename A , typename B >
ostream& operator<< ( ostream &  os,
const pair< A, B > &  pair 
)

Definition at line 76 of file BaseTest.cpp.

76  {
77  return os << "(" << pair.first << ", " << pair.second << ")";
78 }
TEST ( Gen  ,
Count   
)

Definition at line 80 of file BaseTest.cpp.

References folly::gen::count, EXPECT_EQ, folly::gen::seq(), and folly::gen::take().

80  {
81  auto gen = seq(1, 10);
82  EXPECT_EQ(10, gen | count);
83  EXPECT_EQ(5, gen | take(5) | count);
84 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
int * count
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Sum   
)

Definition at line 86 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::seq(), folly::gen::sum, and folly::gen::take().

86  {
87  auto gen = seq(1, 10);
88  EXPECT_EQ((1 + 10) * 10 / 2, gen | sum);
89  EXPECT_EQ((1 + 5) * 5 / 2, gen | take(5) | sum);
90 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Foreach   
)

Definition at line 92 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::seq(), folly::gen::take(), and x.

92  {
93  auto gen = seq(1, 4);
94  int accum = 0;
95  gen | [&](int x) { accum += x; };
96  EXPECT_EQ(10, accum);
97  int accum2 = 0;
98  gen | take(3) | [&](int x) { accum2 += x; };
99  EXPECT_EQ(6, accum2);
100 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Map   
)

Definition at line 102 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::map(), square, and folly::gen::take().

102  {
103  auto expected = vector<int>{4, 9, 16};
104  auto gen = from({2, 3, 4}) | map(square);
105  EXPECT_EQ((vector<int>{4, 9, 16}), gen | as<vector>());
106  EXPECT_EQ((vector<int>{4, 9}), gen | take(2) | as<vector>());
107 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto square
Definition: BaseTest.cpp:69
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Member   
)

Definition at line 109 of file BaseTest.cpp.

References c, count, folly::gen::count, EXPECT_EQ, folly::gen::from(), folly::fileutil_detail::incr(), folly::gen::indirect, m, folly::gen::member(), folly::gen::seq(), start, and folly::gen::sum.

109  {
110  struct Counter {
111  Counter(int start = 0) : c(start) {}
112 
113  int count() const {
114  return c;
115  }
116  int incr() {
117  return ++c;
118  }
119 
120  int& ref() {
121  return c;
122  }
123  const int& ref() const {
124  return c;
125  }
126 
127  private:
128  int c;
129  };
130  auto counters = seq(1, 10) | eachAs<Counter>() | as<vector>();
131  EXPECT_EQ(10 * (1 + 10) / 2, from(counters) | member(&Counter::count) | sum);
132  EXPECT_EQ(
133  10 * (1 + 10) / 2,
134  from(counters) | indirect | member(&Counter::count) | sum);
135  EXPECT_EQ(10 * (2 + 11) / 2, from(counters) | member(&Counter::incr) | sum);
136  EXPECT_EQ(
137  10 * (3 + 12) / 2,
138  from(counters) | indirect | member(&Counter::incr) | sum);
139  EXPECT_EQ(10 * (3 + 12) / 2, from(counters) | member(&Counter::count) | sum);
140 
141  // type-verifications
142  auto m = empty<Counter&>();
143  auto c = empty<const Counter&>();
144  m | member(&Counter::incr) | assert_type<int&&>();
145  m | member(&Counter::count) | assert_type<int&&>();
146  m | member(&Counter::count) | assert_type<int&&>();
147  m | member<Const>(&Counter::ref) | assert_type<const int&>();
148  m | member<Mutable>(&Counter::ref) | assert_type<int&>();
149  c | member<Const>(&Counter::ref) | assert_type<const int&>();
150 }
std::atomic< int64_t > sum(0)
Counter()
Definition: sample4.h:44
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
ThreadCachedInt< int64_t > Counter
constexpr detail::Indirect indirect
Definition: Base-inl.h:2577
static map< string, int > m
auto start
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int * count
std::enable_if< ExprIsConst< Constness >::value, Map >::type member(Return(Class::*member)() const)
Definition: Base.h:605
char c
TEST ( Gen  ,
Field   
)

Definition at line 152 of file BaseTest.cpp.

References a, b, c, EXPECT_EQ, folly::gen::field(), folly::gen::from(), folly::gen::seq(), folly::gen::sum, and X.

152  {
153  struct X {
154  X() : a(2), b(3), c(4), d(b) {}
155 
156  const int a;
157  int b;
158  mutable int c;
159  int& d; // can't access this with a field pointer.
160  };
161 
162  std::vector<X> xs(1);
163  EXPECT_EQ(2, from(xs) | field(&X::a) | sum);
164  EXPECT_EQ(3, from(xs) | field(&X::b) | sum);
165  EXPECT_EQ(4, from(xs) | field(&X::c) | sum);
166  EXPECT_EQ(2, seq(&xs[0], &xs[0]) | field(&X::a) | sum);
167  // type-verification
168  empty<X&>() | field(&X::a) | assert_type<const int&>();
169  empty<X*>() | field(&X::a) | assert_type<const int&>();
170  empty<X&>() | field(&X::b) | assert_type<int&>();
171  empty<X*>() | field(&X::b) | assert_type<int&>();
172  empty<X&>() | field(&X::c) | assert_type<int&>();
173  empty<X*>() | field(&X::c) | assert_type<int&>();
174 
175  empty<X&&>() | field(&X::a) | assert_type<const int&&>();
176  empty<X&&>() | field(&X::b) | assert_type<int&&>();
177  empty<X&&>() | field(&X::c) | assert_type<int&&>();
178  // references don't imply ownership so they're not moved
179 
180  empty<const X&>() | field(&X::a) | assert_type<const int&>();
181  empty<const X*>() | field(&X::a) | assert_type<const int&>();
182  empty<const X&>() | field(&X::b) | assert_type<const int&>();
183  empty<const X*>() | field(&X::b) | assert_type<const int&>();
184  // 'mutable' has no effect on field pointers, by C++ spec
185  empty<const X&>() | field(&X::c) | assert_type<const int&>();
186  empty<const X*>() | field(&X::c) | assert_type<const int&>();
187 
188  // can't form pointer-to-reference field: empty<X&>() | field(&X::d)
189 }
std::atomic< int64_t > sum(0)
char b
Map field(FieldType Class::*field)
Definition: Base.h:641
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
char a
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
char c
TEST ( Gen  ,
Seq   
)

Definition at line 191 of file BaseTest.cpp.

References folly::gen::count, EXPECT_EQ, folly::gen::seq(), and folly::gen::take().

191  {
192  // cover the fenceposts of the loop unrolling
193  for (int n = 1; n < 100; ++n) {
194  EXPECT_EQ(n, seq(1, n) | count);
195  EXPECT_EQ(n + 1, seq(1) | take(n + 1) | count);
196  }
197 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
int * count
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
SeqWithStep   
)

Definition at line 199 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::seq(), and folly::gen::sum.

199  {
200  EXPECT_EQ(75, seq(5, 25, 5) | sum);
201 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
TEST ( Gen  ,
SeqWithStepArray   
)

Definition at line 203 of file BaseTest.cpp.

References EXPECT_EQ, i, folly::gen::map(), folly::gen::seq(), and folly::gen::sum.

203  {
204  const std::array<int, 6> arr{{1, 2, 3, 4, 5, 6}};
205  EXPECT_EQ(
206  9, seq(&arr[0], &arr[5], 2) | map([](const int* i) { return *i; }) | sum);
207 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
static Map map(mapCap)
TEST ( Gen  ,
Range   
)

Definition at line 209 of file BaseTest.cpp.

References folly::gen::count, EXPECT_EQ, and folly::gen::range().

209  {
210  // cover the fenceposts of the loop unrolling
211  for (int n = 1; n < 100; ++n) {
212  EXPECT_EQ(gen::range(0, n) | count, n);
213  }
214 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen range(Value begin, Value end)
Definition: Base.h:467
int * count
TEST ( Gen  ,
RangeWithStep   
)

Definition at line 216 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::range(), and folly::gen::sum.

216  {
217  EXPECT_EQ(50, range(5, 25, 5) | sum);
218 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen range(Value begin, Value end)
Definition: Base.h:467
TEST ( Gen  ,
FromIterators   
)

Definition at line 220 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), product, and folly::range().

220  {
221  vector<int> source{2, 3, 5, 7, 11};
222  auto gen = from(folly::range(source.begin() + 1, source.end() - 1));
223  EXPECT_EQ(3 * 5 * 7, gen | product);
224 }
auto product
Definition: BaseTest.cpp:73
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr Range< Iter > range(Iter first, Iter last)
Definition: Range.h:1114
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
FromMap   
)

Definition at line 226 of file BaseTest.cpp.

References folly::gen::as(), EXPECT_EQ, folly::gen::fromConst(), i, folly::gen::map(), folly::gen::seq(), and folly::gen::sum.

226  {
227  // clang-format off
228  auto source
229  = seq(0, 10)
230  | map([](int i) { return std::make_pair(i, i * i); })
231  | as<std::map<int, int>>();
232  auto gen
233  = fromConst(source)
234  | map([&](const std::pair<const int, int>& p) {
235  return p.second - p.first;
236  });
237  // clang-format on
238  EXPECT_EQ(330, gen | sum);
239 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
From fromConst(const Container &source)
Definition: Base.h:433
static Map map(mapCap)
Collect as()
Definition: Base.h:811
TEST ( Gen  ,
Filter   
)

Definition at line 241 of file BaseTest.cpp.

References folly::gen::as(), EXPECT_EQ, folly::gen::filter(), and folly::gen::seq().

241  {
242  const auto expected = vector<int>{1, 2, 4, 5, 7, 8};
243  auto actual =
244  seq(1, 9) | filter([](int x) { return x % 3; }) | as<vector<int>>();
245  EXPECT_EQ(expected, actual);
246 }
Definition: InvokeTest.cpp:58
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Collect as()
Definition: Base.h:811
TEST ( Gen  ,
FilterDefault   
)

Definition at line 248 of file BaseTest.cpp.

References a, b, c, EXPECT_EQ, folly::gen::filter(), and folly::gen::from().

248  {
249  {
250  // Default filter should remove 0s
251  const auto expected = vector<int>{1, 1, 2, 3};
252  auto actual = from({0, 1, 1, 0, 2, 3, 0}) | filter() | as<vector>();
253  EXPECT_EQ(expected, actual);
254  }
255  {
256  // Default filter should remove nullptrs
257  int a = 5;
258  int b = 3;
259  int c = 0;
260  const auto expected = vector<int*>{&a, &b, &c};
261  // clang-format off
262  auto actual = from({(int*)nullptr, &a, &b, &c, (int*)nullptr})
263  | filter()
264  | as<vector>();
265  // clang-format on
266  EXPECT_EQ(expected, actual);
267  }
268  {
269  // Default filter on Optionals should remove folly::null
270  const auto expected =
271  vector<Optional<int>>{Optional<int>(5), Optional<int>(0)};
272  // clang-format off
273  const auto actual = from(
275  | filter()
276  | as<vector>();
277  // clang-format on
278  EXPECT_EQ(expected, actual);
279  }
280 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
char a
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
char c
TEST ( Gen  ,
FilterSink   
)

Definition at line 282 of file BaseTest.cpp.

References EXPECT_FALSE, folly::gen::filter(), folly::gen::from(), folly::gen::isEmpty, folly::gen::map(), folly::gen::rconcat, and folly::gen::seq().

282  {
283  // clang-format off
284  auto actual = seq(1, 2)
285  | map([](int x) { return vector<int>{x}; })
286  | filter([](vector<int> v) { return !v.empty(); })
287  | as<vector>();
288  // clang-format on
289  EXPECT_FALSE(from(actual) | rconcat | isEmpty);
290 }
Definition: InvokeTest.cpp:58
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
Gen seq(Value first, Value last)
Definition: Base.h:484
constexpr detail::IsEmpty< true > isEmpty
Definition: Base-inl.h:2555
constexpr detail::RangeConcat rconcat
Definition: Base-inl.h:2571
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( Gen  ,
Contains   
)

Definition at line 292 of file BaseTest.cpp.

References folly::gen::contains(), EXPECT_FALSE, EXPECT_TRUE, folly::gen::map(), folly::gen::seq(), square, and folly::gen::take().

292  {
293  {
294  auto gen = seq(1, 9) | map(square);
295  EXPECT_TRUE(gen | contains(49));
296  EXPECT_FALSE(gen | contains(50));
297  }
298  {
299  // infinite, to prove laziness
300  auto gen = seq(1) | map(square) | eachTo<std::string>();
301 
302  // std::string gen, const char* needle
303  EXPECT_TRUE(gen | take(9999) | contains("49"));
304  }
305 }
Gen seq(Value first, Value last)
Definition: Base.h:484
auto square
Definition: BaseTest.cpp:69
Contains contains(Needle &&needle)
Definition: Base.h:831
static Map map(mapCap)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
detail::Take take(Number count)
Definition: Base-inl.h:2582
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( Gen  ,
Take   
)

Definition at line 307 of file BaseTest.cpp.

References folly::gen::concat, EXPECT_EQ, EXPECT_THROW, i, int64_t, folly::gen::mapped(), folly::gen::seq(), folly::gen::take(), and x.

307  {
308  {
309  auto expected = vector<int>{1, 4, 9, 16};
310  // clang-format off
311  auto actual =
312  seq(1, 1000)
313  | mapped([](int x) { return x * x; })
314  | take(4)
315  | as<vector<int>>();
316  // clang-format on
317  EXPECT_EQ(expected, actual);
318  }
319  {
320  auto expected = vector<int>{0, 1, 4, 5, 8};
321  // clang-format off
322  auto actual
323  = ((seq(0) | take(2)) +
324  (seq(4) | take(2)) +
325  (seq(8) | take(2)))
326  | take(5)
327  | as<vector>();
328  // clang-format on
329  EXPECT_EQ(expected, actual);
330  }
331  {
332  auto expected = vector<int>{0, 1, 4, 5, 8};
333  // clang-format off
334  auto actual
335  = seq(0)
336  | mapped([](int i) {
337  return seq(i * 4) | take(2);
338  })
339  | concat
340  | take(5)
341  | as<vector>();
342  // clang-format on
343  EXPECT_EQ(expected, actual);
344  }
345  {
346  int64_t limit = 5;
347  take(limit - 5);
348  EXPECT_THROW(take(limit - 6), std::invalid_argument);
349  }
350 }
Definition: InvokeTest.cpp:58
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
auto concat
Definition: set_done_2.cpp:45
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Take take(Number count)
Definition: Base-inl.h:2582
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
TEST ( Gen  ,
Stride   
)

Definition at line 352 of file BaseTest.cpp.

References folly::gen::count, EXPECT_EQ, EXPECT_THROW, folly::gen::seq(), folly::gen::stride(), and folly::gen::take().

352  {
353  EXPECT_THROW(stride(0), std::invalid_argument);
354  {
355  auto expected = vector<int>{1, 2, 3, 4};
356  auto actual = seq(1, 4) | stride(1) | as<vector<int>>();
357  EXPECT_EQ(expected, actual);
358  }
359  {
360  auto expected = vector<int>{1, 3, 5, 7};
361  auto actual = seq(1, 8) | stride(2) | as<vector<int>>();
362  EXPECT_EQ(expected, actual);
363  }
364  {
365  auto expected = vector<int>{1, 4, 7, 10};
366  auto actual = seq(1, 12) | stride(3) | as<vector<int>>();
367  EXPECT_EQ(expected, actual);
368  }
369  {
370  auto expected = vector<int>{1, 3, 5, 7, 9, 1, 4, 7, 10};
371  // clang-format off
372  auto actual
373  = ((seq(1, 10) | stride(2)) +
374  (seq(1, 10) | stride(3)))
375  | as<vector<int>>();
376  // clang-format on
377  EXPECT_EQ(expected, actual);
378  }
379  EXPECT_EQ(500, seq(1) | take(1000) | stride(2) | count);
380  EXPECT_EQ(10, seq(1) | take(1000) | stride(2) | take(10) | count);
381 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
int * count
detail::Take take(Number count)
Definition: Base-inl.h:2582
detail::Stride stride(size_t s)
Definition: Base-inl.h:2589
TEST ( Gen  ,
Sample   
)

Definition at line 383 of file BaseTest.cpp.

References folly::gen::count, EXPECT_EQ, EXPECT_GT, EXPECT_LT, folly::gen::fromConst(), i, folly::gen::sample(), folly::gen::seq(), small, folly::gen::sum, folly::gen::take(), and v.

383  {
384  std::mt19937 rnd(42);
385 
386  auto sampler = seq(1, 100) | sample(50, rnd);
387  std::unordered_map<int, int> hits;
388  const int kNumIters = 80;
389  for (int i = 0; i < kNumIters; i++) {
390  auto vec = sampler | as<vector<int>>();
391  EXPECT_EQ(vec.size(), 50);
392  auto uniq = fromConst(vec) | as<set<int>>();
393  EXPECT_EQ(uniq.size(), vec.size()); // sampling without replacement
394  for (auto v : vec) {
395  ++hits[v];
396  }
397  }
398 
399  // In 80 separate samples of our range, we should have seen every value
400  // at least once and no value all 80 times. (The odds of either of those
401  // events is 1/2^80).
402  EXPECT_EQ(hits.size(), 100);
403  for (auto hit : hits) {
404  EXPECT_GT(hit.second, 0);
405  EXPECT_LT(hit.second, kNumIters);
406  }
407 
408  auto small = seq(1, 5) | sample(10);
409  EXPECT_EQ((small | sum), 15);
410  EXPECT_EQ((small | take(3) | count), 3);
411 }
std::atomic< int64_t > sum(0)
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Sample< Random > sample(size_t count, Random rng=Random())
Definition: Base-inl.h:2594
auto small
From fromConst(const Container &source)
Definition: Base.h:433
Definition: Traits.h:588
int * count
detail::Take take(Number count)
Definition: Base-inl.h:2582
#define EXPECT_LT(val1, val2)
Definition: gtest.h:1930
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934
TEST ( Gen  ,
Skip   
)

Definition at line 413 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::mapped(), folly::gen::seq(), folly::gen::skip(), folly::gen::take(), and x.

413  {
414  auto gen =
415  seq(1, 1000) | mapped([](int x) { return x * x; }) | skip(4) | take(4);
416  EXPECT_EQ((vector<int>{25, 36, 49, 64}), gen | as<vector>());
417 }
Definition: InvokeTest.cpp:58
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Skip skip(size_t count)
Definition: Base-inl.h:2598
detail::Take take(Number count)
Definition: Base-inl.h:2582
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
TEST ( Gen  ,
Until   
)

Definition at line 419 of file BaseTest.cpp.

References folly::gen::as(), EXPECT_EQ, i, folly::gen::mapped(), folly::gen::seq(), folly::gen::until(), and x.

419  {
420  {
421  auto expected = vector<int>{1, 4, 9, 16};
422  // clang-format off
423  auto actual
424  = seq(1, 1000)
425  | mapped([](int x) { return x * x; })
426  | until([](int x) { return x > 20; })
427  | as<vector<int>>();
428  // clang-format on
429  EXPECT_EQ(expected, actual);
430  }
431  {
432  auto expected = vector<int>{0, 1, 4, 5, 8};
433  // clang-format off
434  auto actual
435  = ((seq(0) | until([](int i) { return i > 1; })) +
436  (seq(4) | until([](int i) { return i > 5; })) +
437  (seq(8) | until([](int i) { return i > 9; })))
438  | until([](int i) { return i > 8; })
439  | as<vector<int>>();
440  // clang-format on
441  EXPECT_EQ(expected, actual);
442  }
443  /*
444  {
445  auto expected = vector<int>{ 0, 1, 5, 6, 10 };
446  // clang-format off
447  auto actual
448  = seq(0)
449  | mapped([](int i) {
450  return seq(i * 5) | until([=](int j) { return j > i * 5 + 1; });
451  })
452  | concat
453  | until([](int i) { return i > 10; })
454  | as<vector<int>>();
455  // clang-format on
456  EXPECT_EQ(expected, actual);
457  }
458  */
459 }
Definition: InvokeTest.cpp:58
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
Until until(Predicate pred=Predicate())
Definition: Base.h:656
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
Collect as()
Definition: Base.h:811
TEST ( Gen  ,
Visit   
)

Definition at line 461 of file BaseTest.cpp.

References EXPECT_EQ, i, folly::gen::map(), folly::gen::seq(), square, folly::gen::sum, folly::gen::take(), folly::value(), and folly::gen::visit().

461  {
462  auto increment = [](int& i) { ++i; };
463  auto clone = map([](int i) { return i; });
464  { // apply()
465  auto expected = 10;
466  auto actual = seq(0) | clone | visit(increment) | take(4) | sum;
467  EXPECT_EQ(expected, actual);
468  }
469  { // foreach()
470  auto expected = 10;
471  auto actual = seq(0, 3) | clone | visit(increment) | sum;
472  EXPECT_EQ(expected, actual);
473  }
474  { // tee-like
475  std::vector<int> x2, x4;
476  std::vector<int> expected2{0, 1, 4, 9};
477  std::vector<int> expected4{0, 1, 16, 81};
478 
479  auto tee = [](std::vector<int>& container) {
480  return visit([&](int value) { container.push_back(value); });
481  };
482  EXPECT_EQ(
483  98, seq(0, 3) | map(square) | tee(x2) | map(square) | tee(x4) | sum);
484  EXPECT_EQ(expected2, x2);
485  EXPECT_EQ(expected4, x4);
486  }
487 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Visit visit(Visitor visitor=Visitor())
Definition: Base.h:651
auto square
Definition: BaseTest.cpp:69
static Map map(mapCap)
static const char *const value
Definition: Conv.cpp:50
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Composed   
)

Definition at line 489 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::filter(), folly::gen::from(), folly::Optional< Value >::hasValue(), folly::gen::map(), folly::none, square, folly::gen::sum, and folly::Optional< Value >::value().

489  {
490  // Operator, Operator
491  // clang-format off
492  auto valuesOf
493  = filter([](Optional<int>& o) { return o.hasValue(); })
494  | map([](Optional<int>& o) -> int& { return o.value(); });
495  // clang-format on
496  std::vector<Optional<int>> opts{none, 4, none, 6, none};
497  EXPECT_EQ(4 * 4 + 6 * 6, from(opts) | valuesOf | map(square) | sum);
498  // Operator, Sink
499  auto sumOpt = valuesOf | sum;
500  EXPECT_EQ(10, from(opts) | sumOpt);
501 }
std::atomic< int64_t > sum(0)
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto square
Definition: BaseTest.cpp:69
static Map map(mapCap)
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
constexpr None none
Definition: Optional.h:87
TEST ( Gen  ,
Chain   
)

Definition at line 503 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::sum, and folly::gen::take().

503  {
504  std::vector<int> nums{2, 3, 5, 7};
505  std::map<int, int> mappings{{3, 9}, {5, 25}};
506  auto gen = from(nums) + (from(mappings) | get<1>());
507  EXPECT_EQ(51, gen | sum);
508  EXPECT_EQ(5, gen | take(2) | sum);
509  EXPECT_EQ(26, gen | take(5) | sum);
510 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Concat   
)

Definition at line 512 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::rconcat, folly::gen::sum, and folly::gen::take().

512  {
513  std::vector<std::vector<int>> nums{{2, 3}, {5, 7}};
514  auto gen = from(nums) | rconcat;
515  EXPECT_EQ(17, gen | sum);
516  EXPECT_EQ(10, gen | take(3) | sum);
517 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::RangeConcat rconcat
Definition: Base-inl.h:2571
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
ConcatGen   
)

Definition at line 519 of file BaseTest.cpp.

References folly::gen::concat, EXPECT_EQ, i, folly::gen::map(), folly::gen::seq(), folly::gen::sum, and folly::gen::take().

519  {
520  auto gen = seq(1, 10) | map([](int i) { return seq(1, i); }) | concat;
521  EXPECT_EQ(220, gen | sum);
522  EXPECT_EQ(10, gen | take(6) | sum);
523 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto concat
Definition: set_done_2.cpp:45
Gen seq(Value first, Value last)
Definition: Base.h:484
static Map map(mapCap)
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
ConcatAlt   
)

Definition at line 525 of file BaseTest.cpp.

References folly::gen::concat, EXPECT_EQ, folly::gen::from(), folly::gen::map(), and folly::gen::sum.

525  {
526  std::vector<std::vector<int>> nums{{2, 3}, {5, 7}};
527  // clang-format off
528  auto actual
529  = from(nums)
530  | map([](std::vector<int>& v) { return from(v); })
531  | concat
532  | sum;
533  // clang-format on
534  auto expected = 17;
535  EXPECT_EQ(expected, actual);
536 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto concat
Definition: set_done_2.cpp:45
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
Order   
)

Definition at line 538 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), and folly::gen::order.

538  {
539  auto expected = vector<int>{0, 3, 5, 6, 7, 8, 9};
540  auto actual = from({8, 6, 7, 5, 3, 0, 9}) | order | as<vector>();
541  EXPECT_EQ(expected, actual);
542 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int order
TEST ( Gen  ,
OrderMoved   
)

Definition at line 544 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::map(), folly::gen::move, folly::gen::order, and square.

544  {
545  auto expected = vector<int>{0, 9, 25, 36, 49, 64, 81};
546  // clang-format off
547  auto actual
548  = from({8, 6, 7, 5, 3, 0, 9})
549  | move
550  | order
551  | map(square)
552  | as<vector>();
553  // clang-format on
554  EXPECT_EQ(expected, actual);
555 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto square
Definition: BaseTest.cpp:69
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int order
TEST ( Gen  ,
OrderTake   
)

Definition at line 557 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::orderByDescending(), square, and folly::gen::take().

557  {
558  auto expected = vector<int>{9, 8, 7};
559  // clang-format off
560  auto actual
561  = from({8, 6, 7, 5, 3, 0, 9})
563  | take(3)
564  | as<vector>();
565  // clang-format on
566  EXPECT_EQ(expected, actual);
567 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto square
Definition: BaseTest.cpp:69
Order orderByDescending(Selector selector=Selector())
Definition: Base.h:678
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Distinct   
)

Definition at line 569 of file BaseTest.cpp.

References folly::gen::distinct, EXPECT_EQ, and folly::gen::from().

569  {
570  auto expected = vector<int>{3, 1, 2};
571  auto actual = from({3, 1, 3, 2, 1, 2, 3}) | distinct | as<vector>();
572  EXPECT_EQ(expected, actual);
573 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Distinct< Identity > distinct
Definition: Base-inl.h:2565
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
DistinctBy   
)

Definition at line 575 of file BaseTest.cpp.

References folly::gen::distinctBy(), EXPECT_EQ, i, and folly::gen::seq().

575  { // 0 1 4 9 6 5 6 9 4 1 0
576  auto expected = vector<int>{0, 1, 2, 3, 4, 5};
577  auto actual =
578  seq(0, 100) | distinctBy([](int i) { return i * i % 10; }) | as<vector>();
579  EXPECT_EQ(expected, actual);
580 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Distinct distinctBy(Selector selector=Selector())
Definition: Base.h:697
TEST ( Gen  ,
DistinctMove   
)

Definition at line 582 of file BaseTest.cpp.

References folly::gen::distinctBy(), EXPECT_EQ, i, folly::gen::mapped(), and folly::gen::seq().

582  { // 0 1 4 9 6 5 6 9 4 1 0
583  auto expected = vector<int>{0, 1, 2, 3, 4, 5};
584  auto actual = seq(0, 100) |
585  mapped([](int i) { return std::make_unique<int>(i); })
586  // see comment below about selector parameters for Distinct
587  | distinctBy([](const std::unique_ptr<int>& pi) {
588  return *pi * *pi % 10;
589  }) |
590  mapped([](std::unique_ptr<int> pi) { return *pi; }) | as<vector>();
591 
592  // NOTE(tjackson): the following line intentionally doesn't work:
593  // | distinctBy([](std::unique_ptr<int> pi) { return *pi * *pi % 10; })
594  // This is because distinctBy because the selector intentionally requires a
595  // const reference. If it required a move-reference, the value might get
596  // gutted by the selector before said value could be passed to downstream
597  // operators.
598  EXPECT_EQ(expected, actual);
599 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Distinct distinctBy(Selector selector=Selector())
Definition: Base.h:697
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
TEST ( Gen  ,
DistinctInfinite   
)

Definition at line 601 of file BaseTest.cpp.

References folly::gen::distinct, EXPECT_EQ, i, folly::gen::mapped(), folly::gen::seq(), and folly::gen::take().

601  {
602  // distinct should be able to handle an infinite sequence, provided that, of
603  // of cource, is it eventually made finite before returning the result.
604  auto expected = seq(0) | take(5) | as<vector>(); // 0 1 2 3 4
605 
606  auto actual = seq(0) // 0 1 2 3 4 5 6 7 ...
607  | mapped([](int i) { return i / 2; }) // 0 0 1 1 2 2 3 3 ...
608  | distinct // 0 1 2 3 4 5 6 7 ...
609  | take(5) // 0 1 2 3 4
610  | as<vector>();
611 
612  EXPECT_EQ(expected, actual);
613 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Distinct< Identity > distinct
Definition: Base-inl.h:2565
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Take take(Number count)
Definition: Base-inl.h:2582
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
TEST ( Gen  ,
DistinctByInfinite   
)

Definition at line 615 of file BaseTest.cpp.

References folly::gen::distinctBy(), EXPECT_EQ, i, folly::gen::seq(), and folly::gen::take().

615  {
616  // Similarly to the DistinctInfinite test case, distinct by should be able to
617  // handle infinite sequences. Note that depending on how many values we take()
618  // at the end, the sequence may infinite loop. This is fine becasue we cannot
619  // solve the halting problem.
620  auto expected = vector<int>{1, 2};
621  auto actual = seq(1) // 1 2 3 4 5 6 7 8 ...
622  | distinctBy([](int i) { return i % 2; }) // 1 2 (but might by infinite)
623  | take(2) // 1 2
624  | as<vector>();
625  // Note that if we had take(3), this would infinite loop
626 
627  EXPECT_EQ(expected, actual);
628 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Distinct distinctBy(Selector selector=Selector())
Definition: Base.h:697
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
MinBy   
)

Definition at line 630 of file BaseTest.cpp.

References EXPECT_EQ, i, folly::gen::minBy(), folly::gen::seq(), and folly::gen::unwrap.

630  {
631  // clang-format off
632  EXPECT_EQ(
633  7,
634  seq(1, 10)
635  | minBy([](int i) -> double {
636  double d = i - 6.8;
637  return d * d;
638  })
639  | unwrap);
640  // clang-format on
641 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Min minBy(Selector selector=Selector())
Definition: Base.h:801
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
TEST ( Gen  ,
MaxBy   
)

Definition at line 643 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::maxBy(), and folly::gen::unwrap.

643  {
644  auto gen = from({"three", "eleven", "four"});
645 
646  EXPECT_EQ("eleven", gen | maxBy(&strlen) | unwrap);
647 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
MaxBy maxBy(Selector selector=Selector())
Definition: Base.h:806
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
TEST ( Gen  ,
Min   
)

Definition at line 649 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::filter(), i, folly::gen::min, and folly::gen::seq().

649  {
650  auto odds = seq(2, 10) | filter([](int i) { return i % 2; });
651 
652  EXPECT_EQ(3, odds | min);
653 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
LogLevel min
Definition: LogLevel.cpp:30
TEST ( Gen  ,
Max   
)

Definition at line 655 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::filter(), i, folly::gen::max, and folly::gen::seq().

655  {
656  auto odds = seq(2, 10) | filter([](int i) { return i % 2; });
657 
658  EXPECT_EQ(9, odds | max);
659 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
LogLevel max
Definition: LogLevel.cpp:31
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
TEST ( Gen  ,
Append   
)

Definition at line 661 of file BaseTest.cpp.

References folly::gen::appendTo(), EXPECT_EQ, and folly::gen::from().

661  {
662  string expected = "facebook";
663  string actual = "face";
664  from(StringPiece("book")) | appendTo(actual);
665  EXPECT_EQ(expected, actual);
666 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Append appendTo(Collection &collection)
Definition: Base.h:824
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
Range< const char * > StringPiece
TEST ( Gen  ,
FromRValue   
)

Definition at line 668 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::max, folly::gen::move, product, folly::size(), folly::gen::sum, and v.

668  {
669  {
670  // AFAICT The C++ Standard does not specify what happens to the rvalue
671  // reference of a std::vector when it is used as the 'other' for an rvalue
672  // constructor. Use fbvector because we're sure its size will be zero in
673  // this case.
674  fbvector<int> v({1, 2, 3, 4});
675  auto q1 = from(v);
676  EXPECT_EQ(v.size(), 4); // ensure that the lvalue version was called!
677  auto expected = 1 * 2 * 3 * 4;
678  EXPECT_EQ(expected, q1 | product);
679 
680  auto q2 = from(std::move(v));
681  EXPECT_EQ(v.size(), 0); // ensure that rvalue version was called
682  EXPECT_EQ(expected, q2 | product);
683  }
684  {
685  auto expected = 7;
686  auto q = from([] { return vector<int>({3, 7, 5}); }());
687  EXPECT_EQ(expected, q | max);
688  }
689  {
690  for (auto size : {5, 1024, 16384, 1 << 20}) {
691  auto q1 = from(vector<int>(size, 2));
692  auto q2 = from(vector<int>(size, 3));
693  // If the rvalue specialization is broken/gone, then the compiler will
694  // (disgustingly!) just store a *reference* to the temporary object,
695  // which is bad. Try to catch this by allocating two temporary vectors
696  // of the same size, so that they'll probably use the same underlying
697  // buffer if q1's vector is destructed before q2's vector is constructed.
698  EXPECT_EQ(size * 2 + size * 3, (q1 | sum) + (q2 | sum));
699  }
700  }
701  {
702  auto q = from(set<int>{1, 2, 3, 2, 1});
703  EXPECT_EQ(q | sum, 6);
704  }
705 }
std::atomic< int64_t > sum(0)
auto v
auto product
Definition: BaseTest.cpp:73
LogLevel max
Definition: LogLevel.cpp:31
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
OrderBy   
)

Definition at line 707 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::map(), folly::gen::orderBy(), folly::gen::seq(), and x.

707  {
708  auto expected = vector<int>{5, 6, 4, 7, 3, 8, 2, 9, 1, 10};
709  // clang-format off
710  auto actual
711  = seq(1, 10)
712  | orderBy([](int x) { return (5.1 - x) * (5.1 - x); })
713  | as<vector>();
714  // clang-format on
715  EXPECT_EQ(expected, actual);
716 
717  expected = seq(1, 10) | as<vector>();
718  // clang-format off
719  actual
720  = from(expected)
721  | map([] (int x) { return 11 - x; })
722  | orderBy()
723  | as<vector>();
724  // clang-format on
725  EXPECT_EQ(expected, actual);
726 }
Definition: InvokeTest.cpp:58
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
Order orderBy(Selector selector=Selector(), Comparer comparer=Comparer())
Definition: Base.h:671
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
Foldl   
)

Definition at line 728 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::foldl(), multiply, and folly::gen::seq().

728  {
729  int expected = 2 * 3 * 4 * 5;
730  auto actual = seq(2, 5) | foldl(1, multiply);
731  EXPECT_EQ(expected, actual);
732 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
FoldLeft foldl(Seed seed=Seed(), Fold fold=Fold())
Definition: Base.h:791
auto multiply
Definition: BaseTest.cpp:71
TEST ( Gen  ,
Reduce   
)

Definition at line 734 of file BaseTest.cpp.

References add, EXPECT_EQ, folly::gen::reduce(), folly::gen::seq(), and folly::gen::unwrap.

734  {
735  int expected = 2 + 3 + 4 + 5;
736  auto actual = seq(2, 5) | reduce(add);
737  EXPECT_EQ(expected, actual | unwrap);
738 }
auto add
Definition: BaseTest.cpp:70
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::reduce_fn reduce
TEST ( Gen  ,
ReduceBad   
)

Definition at line 740 of file BaseTest.cpp.

References add, EXPECT_FALSE, folly::gen::reduce(), folly::gen::seq(), and folly::gen::take().

740  {
741  auto gen = seq(1) | take(0);
742  auto actual = gen | reduce(add);
743  EXPECT_FALSE(actual); // Empty sequences are okay, they just yeild 'none'
744 }
auto add
Definition: BaseTest.cpp:70
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Take take(Number count)
Definition: Base-inl.h:2582
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::reduce_fn reduce
TEST ( Gen  ,
Moves   
)

Definition at line 746 of file BaseTest.cpp.

References EXPECT_EQ, EXPECT_NE, folly::gen::from(), and folly::gen::move.

746  {
747  std::vector<unique_ptr<int>> ptrs;
748  ptrs.emplace_back(new int(1));
749  EXPECT_NE(ptrs.front().get(), nullptr);
750  auto ptrs2 = from(ptrs) | move | as<vector>();
751  EXPECT_EQ(ptrs.front().get(), nullptr);
752  EXPECT_EQ(**ptrs2.data(), 1);
753 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST ( Gen  ,
First   
)

Definition at line 755 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::filter(), folly::gen::first, folly::gen::seq(), and folly::gen::unwrap.

755  {
756  auto gen = seq(0) | filter([](int x) { return x > 3; });
757  EXPECT_EQ(4, gen | first | unwrap);
758 }
Definition: InvokeTest.cpp:58
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
constexpr detail::First first
Definition: Base-inl.h:2553
TEST ( Gen  ,
FromCopy   
)

Definition at line 760 of file BaseTest.cpp.

References folly::copy(), EXPECT_EQ, folly::gen::from(), folly::gen::fromCopy(), and folly::gen::sum.

760  {
761  vector<int> v{3, 5};
762  auto src = from(v);
763  auto copy = fromCopy(v);
764  EXPECT_EQ(8, src | sum);
765  EXPECT_EQ(8, copy | sum);
766  v[1] = 7;
767  EXPECT_EQ(10, src | sum);
768  EXPECT_EQ(8, copy | sum);
769 }
CopyOf fromCopy(Container &&source)
Definition: Base.h:446
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
Get   
)

Definition at line 771 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), std::tr1::make_tuple(), folly::gen::map(), square, folly::gen::sum, and values().

771  {
772  std::map<int, int> pairs{
773  {1, 1},
774  {2, 4},
775  {3, 9},
776  {4, 16},
777  };
778  auto pairSrc = from(pairs);
779  auto keys = pairSrc | get<0>();
780  auto values = pairSrc | get<1>();
781  EXPECT_EQ(10, keys | sum);
782  EXPECT_EQ(30, values | sum);
783  EXPECT_EQ(30, keys | map(square) | sum);
784  pairs[5] = 25;
785  EXPECT_EQ(15, keys | sum);
786  EXPECT_EQ(55, values | sum);
787 
788  vector<tuple<int, int, int>> tuples{
789  make_tuple(1, 1, 1),
790  make_tuple(2, 4, 8),
791  make_tuple(3, 9, 27),
792  };
793  EXPECT_EQ(36, from(tuples) | get<2>() | sum);
794 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
tuple make_tuple()
Definition: gtest-tuple.h:675
auto square
Definition: BaseTest.cpp:69
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
std::vector< int > values(1'000)
TEST ( Gen  ,
notEmpty   
)

Definition at line 796 of file BaseTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, folly::gen::from(), folly::gen::just(), folly::gen::notEmpty, folly::gen::range(), folly::gen::seq(), and folly::gen::take().

796  {
797  EXPECT_TRUE(seq(0, 1) | notEmpty);
798  EXPECT_TRUE(just(1) | notEmpty);
800  EXPECT_FALSE(from({1}) | take(0) | notEmpty);
801 }
constexpr detail::IsEmpty< false > notEmpty
Definition: Base-inl.h:2557
Gen seq(Value first, Value last)
Definition: Base.h:484
Gen range(Value begin, Value end)
Definition: Base.h:467
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
detail::Take take(Number count)
Definition: Base-inl.h:2582
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::just_fn just
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( Gen  ,
isEmpty   
)

Definition at line 803 of file BaseTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, folly::gen::from(), folly::gen::isEmpty, folly::gen::just(), folly::gen::range(), folly::gen::seq(), and folly::gen::take().

803  {
804  EXPECT_FALSE(seq(0, 1) | isEmpty);
805  EXPECT_FALSE(just(1) | isEmpty);
806  EXPECT_TRUE(gen::range(0, 0) | isEmpty);
807  EXPECT_TRUE(from({1}) | take(0) | isEmpty);
808 }
Gen seq(Value first, Value last)
Definition: Base.h:484
Gen range(Value begin, Value end)
Definition: Base.h:467
constexpr detail::IsEmpty< true > isEmpty
Definition: Base-inl.h:2555
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
detail::Take take(Number count)
Definition: Base-inl.h:2582
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::just_fn just
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( Gen  ,
Any   
)

Definition at line 810 of file BaseTest.cpp.

References folly::gen::any(), EXPECT_FALSE, EXPECT_TRUE, i, and folly::gen::seq().

810  {
811  EXPECT_TRUE(seq(0, 10) | any([](int i) { return i == 7; }));
812  EXPECT_FALSE(seq(0, 10) | any([](int i) { return i == 11; }));
813 }
Gen seq(Value first, Value last)
Definition: Base.h:484
Composed any(Predicate pred=Predicate())
Definition: Base.h:758
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( Gen  ,
All   
)

Definition at line 815 of file BaseTest.cpp.

References folly::gen::all(), EXPECT_FALSE, EXPECT_TRUE, i, folly::gen::seq(), and folly::gen::take().

815  {
816  EXPECT_TRUE(seq(0, 10) | all([](int i) { return i < 11; }));
817  EXPECT_FALSE(seq(0, 10) | all([](int i) { return i < 5; }));
818  EXPECT_FALSE(seq(0) | take(9999) | all([](int i) { return i < 10; }));
819 
820  // empty lists satisfies all
821  EXPECT_TRUE(seq(0) | take(0) | all([](int i) { return i < 50; }));
822  EXPECT_TRUE(seq(0) | take(0) | all([](int i) { return i > 50; }));
823 }
Gen seq(Value first, Value last)
Definition: Base.h:484
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
detail::Take take(Number count)
Definition: Base-inl.h:2582
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Composed all(Predicate pred=Predicate())
Definition: Base.h:786
TEST ( Gen  ,
Yielders   
)

Definition at line 825 of file BaseTest.cpp.

References EXPECT_EQ, GENERATOR, i, folly::gen::take(), and folly::fibers::yield().

825  {
826  auto gen = GENERATOR(int) {
827  for (int i = 1; i <= 5; ++i) {
828  yield(i);
829  }
830  yield(7);
831  for (int i = 3;; ++i) {
832  yield(i * i);
833  }
834  };
835  vector<int> expected{1, 2, 3, 4, 5, 7, 9, 16, 25};
836  EXPECT_EQ(expected, gen | take(9) | as<vector>());
837 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define GENERATOR(TYPE)
Definition: Base.h:515
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
NestedYield   
)

Definition at line 839 of file BaseTest.cpp.

References EXPECT_EQ, GENERATOR, i, folly::gen::seq(), folly::gen::sum, folly::gen::take(), and folly::fibers::yield().

839  {
840  auto nums = GENERATOR(int) {
841  for (int i = 1;; ++i) {
842  yield(i);
843  }
844  };
845  auto gen = GENERATOR(int) {
846  nums | take(10) | yield;
847  seq(1, 5) | [&](int i) { yield(i); };
848  };
849  EXPECT_EQ(70, gen | sum);
850 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
#define GENERATOR(TYPE)
Definition: Base.h:515
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
MapYielders   
)

Definition at line 852 of file BaseTest.cpp.

References folly::gen::concat, EXPECT_EQ, GENERATOR, i, folly::gen::map(), folly::gen::seq(), and folly::fibers::yield().

852  {
853  // clang-format off
854  auto gen
855  = seq(1, 5)
856  | map([](int n) {
857  return GENERATOR(int) {
858  int i;
859  for (i = 1; i < n; ++i) {
860  yield(i);
861  }
862  for (; i >= 1; --i) {
863  yield(i);
864  }
865  };
866  })
867  | concat;
868  vector<int> expected {
869  1,
870  1, 2, 1,
871  1, 2, 3, 2, 1,
872  1, 2, 3, 4, 3, 2, 1,
873  1, 2, 3, 4, 5, 4, 3, 2, 1,
874  };
875  // clang-format on
876  EXPECT_EQ(expected, gen | as<vector>());
877 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
auto concat
Definition: set_done_2.cpp:45
Gen seq(Value first, Value last)
Definition: Base.h:484
#define GENERATOR(TYPE)
Definition: Base.h:515
static Map map(mapCap)
TEST ( Gen  ,
VirtualGen   
)

Definition at line 879 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::map(), folly::gen::seq(), square, folly::gen::sum, folly::gen::take(), and v.

879  {
880  VirtualGen<int> v(seq(1, 10));
881  EXPECT_EQ(55, v | sum);
882  v = v | map(square);
883  EXPECT_EQ(385, v | sum);
884  v = v | take(5);
885  EXPECT_EQ(55, v | sum);
886  EXPECT_EQ(30, v | take(4) | sum);
887 }
std::atomic< int64_t > sum(0)
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
auto square
Definition: BaseTest.cpp:69
static Map map(mapCap)
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
CustomType   
)

Definition at line 889 of file BaseTest.cpp.

References EXPECT_EQ, f, folly::gen::from(), folly::gen::map(), and folly::gen::sum.

889  {
890  struct Foo {
891  int y;
892  };
893  auto gen = from({Foo{2}, Foo{3}}) | map([](const Foo& f) { return f.y; });
894  EXPECT_EQ(5, gen | sum);
895 }
auto f
std::atomic< int64_t > sum(0)
Foo(std::atomic< int > &d)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static Map map(mapCap)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
Definition: InvokeTest.cpp:65
TEST ( Gen  ,
NoNeedlessCopies   
)

Definition at line 897 of file BaseTest.cpp.

References folly::apply(), EXPECT_EQ, i, folly::gen::map(), folly::gen::move, folly::pushmi::__adl::noexcept(), folly::gen::seq(), folly::gen::sum, folly::gen::take(), and x.

897  {
898  auto gen = seq(1, 5) | map([](int x) { return std::make_unique<int>(x); }) |
899  map([](unique_ptr<int> p) { return p; }) |
900  map([](unique_ptr<int>&& p) { return std::move(p); }) |
901  map([](const unique_ptr<int>& p) { return *p; });
902  EXPECT_EQ(15, gen | sum);
903  EXPECT_EQ(6, gen | take(3) | sum);
904 }
Definition: InvokeTest.cpp:58
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
Gen seq(Value first, Value last)
Definition: Base.h:484
static Map map(mapCap)
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
NoGeneratorCopies   
)

Definition at line 930 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::move, folly::gen::sum, and folly::gen::take().

930  {
931  EXPECT_EQ(15, TestIntSeq() | sum);
932  auto x = TestIntSeq() | take(3);
933  EXPECT_EQ(6, std::move(x) | sum);
934 }
Definition: InvokeTest.cpp:58
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
FromArray   
)

Definition at line 936 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), and product.

936  {
937  int source[] = {2, 3, 5, 7};
938  auto gen = from(source);
939  EXPECT_EQ(2 * 3 * 5 * 7, gen | product);
940 }
auto product
Definition: BaseTest.cpp:73
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
FromStdArray   
)

Definition at line 942 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), and product.

942  {
943  std::array<int, 4> source{{2, 3, 5, 7}};
944  auto gen = from(source);
945  EXPECT_EQ(2 * 3 * 5 * 7, gen | product);
946 }
auto product
Definition: BaseTest.cpp:73
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
StringConcat   
)

Definition at line 948 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::rconcat, and folly::gen::seq().

948  {
949  auto gen = seq(1, 10) | eachTo<string>() | rconcat;
950  EXPECT_EQ("12345678910", gen | as<string>());
951 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
constexpr detail::RangeConcat rconcat
Definition: Base-inl.h:2571
TEST ( Gen  ,
CopyCount   
)

Definition at line 991 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), and folly::gen::move.

991  {
992  vector<CopyCounter> originals;
993  originals.emplace_back();
994  EXPECT_EQ(1, originals.size());
995  EXPECT_EQ(0, originals.back().copies);
996 
997  vector<CopyCounter> copies = from(originals) | as<vector>();
998  EXPECT_EQ(1, copies.back().copies);
999  EXPECT_EQ(0, copies.back().moves);
1000 
1001  vector<CopyCounter> moves = from(originals) | move | as<vector>();
1002  EXPECT_EQ(0, moves.back().copies);
1003  EXPECT_EQ(1, moves.back().moves);
1004 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
Dynamic   
)

Definition at line 1007 of file BaseTest.cpp.

References folly::dynamic::array(), EXPECT_EQ, folly::gen::from(), folly::gen::rconcat, and folly::gen::sum.

1007  {
1008  dynamic array1 = dynamic::array(1, 2);
1009  EXPECT_EQ(dynamic(3), from(array1) | sum);
1010  dynamic array2 = folly::dynamic::array(
1012  EXPECT_EQ(dynamic(4), from(array2) | rconcat | sum);
1013  dynamic array3 = folly::dynamic::array(
1017  EXPECT_EQ(dynamic(5), from(array3) | rconcat | rconcat | sum);
1018 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::RangeConcat rconcat
Definition: Base-inl.h:2571
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
static void array(EmptyArrayTag)
Definition: dynamic-inl.h:233
TEST ( Gen  ,
DynamicObject   
)

Definition at line 1020 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::dynamic::items(), folly::dynamic::keys(), folly::dynamic::object(), folly::gen::sum, and folly::dynamic::values().

1020  {
1021  const dynamic obj = dynamic::object(1, 2)(3, 4);
1022  EXPECT_EQ(dynamic(4), from(obj.keys()) | sum);
1023  EXPECT_EQ(dynamic(6), from(obj.values()) | sum);
1024  EXPECT_EQ(dynamic(4), from(obj.items()) | get<0>() | sum);
1025  EXPECT_EQ(dynamic(6), from(obj.items()) | get<1>() | sum);
1026 }
IterableProxy< const_value_iterator > values() const
Definition: dynamic-inl.h:471
void * object
Definition: AtFork.cpp:32
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
IterableProxy< const_key_iterator > keys() const
Definition: dynamic-inl.h:466
IterableProxy< const_item_iterator > items() const
Definition: dynamic-inl.h:476
TEST ( Gen  ,
Collect   
)

Definition at line 1028 of file BaseTest.cpp.

References folly::gen::as(), EXPECT_EQ, folly::gen::from(), and s.

1028  {
1029  auto s = from({7, 6, 5, 4, 3}) | as<set<int>>();
1030  EXPECT_EQ(s.size(), 5);
1031 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
static set< string > s
Collect as()
Definition: Base.h:811
TEST ( Gen  ,
Cycle   
)

Definition at line 1033 of file BaseTest.cpp.

References ASSERT_GE, c, folly::gen::cycle, EXPECT_EQ, folly::gen::from(), GENERATOR, i, s, folly::gen::take(), and folly::fibers::yield().

1033  {
1034  {
1035  auto s = from({1, 2});
1036  EXPECT_EQ((vector<int>{1, 2, 1, 2, 1}), s | cycle | take(5) | as<vector>());
1037  }
1038  {
1039  auto s = from({1, 2});
1040  EXPECT_EQ((vector<int>{1, 2, 1, 2}), s | cycle(2) | as<vector>());
1041  }
1042  {
1043  auto s = from({1, 2, 3});
1044  EXPECT_EQ(
1045  (vector<int>{1, 2, 1, 2, 1}),
1046  s | take(2) | cycle | take(5) | as<vector>());
1047  }
1048  {
1049  auto s = empty<int>();
1050  EXPECT_EQ((vector<int>{}), s | cycle | take(4) | as<vector>());
1051  }
1052  {
1053  int c = 3;
1054  int* pcount = &c;
1055  auto countdown = GENERATOR(int) {
1056  ASSERT_GE(*pcount, 0)
1057  << "Cycle should have stopped when it didnt' get values!";
1058  for (int i = 1; i <= *pcount; ++i) {
1059  yield(i);
1060  }
1061  --*pcount;
1062  };
1063  auto s = countdown;
1064  EXPECT_EQ(
1065  (vector<int>{1, 2, 3, 1, 2, 1}), s | cycle | take(7) | as<vector>());
1066  // take necessary as cycle returns an infinite generator
1067  }
1068 }
#define ASSERT_GE(val1, val2)
Definition: gtest.h:1972
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define GENERATOR(TYPE)
Definition: Base.h:515
constexpr detail::Cycle< true > cycle
Definition: Base-inl.h:2573
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
static set< string > s
detail::Take take(Number count)
Definition: Base-inl.h:2582
char c
TEST ( Gen  ,
Dereference   
)

Definition at line 1070 of file BaseTest.cpp.

References a, b, folly::data(), folly::gen::dereference, EXPECT_EQ, folly::gen::from(), folly::get_ptr(), m, folly::gen::map(), folly::gen::move, folly::operator==(), folly::PrintTo(), s, folly::gen::sum, v, and x.

1070  {
1071  {
1072  const int x = 4, y = 2;
1073  auto s = from(std::initializer_list<const int*>({&x, nullptr, &y}));
1074  EXPECT_EQ(6, s | dereference | sum);
1075  }
1076  {
1077  vector<int> a{1, 2};
1078  vector<int> b{3, 4};
1079  vector<vector<int>*> pv{&a, nullptr, &b};
1080  from(pv) | dereference | [&](vector<int>& v) { v.push_back(5); };
1081  EXPECT_EQ(3, a.size());
1082  EXPECT_EQ(3, b.size());
1083  EXPECT_EQ(5, a.back());
1084  EXPECT_EQ(5, b.back());
1085  }
1086  {
1087  vector<std::map<int, int>> maps{
1088  {
1089  {2, 31},
1090  {3, 41},
1091  },
1092  {
1093  {3, 52},
1094  {4, 62},
1095  },
1096  {
1097  {4, 73},
1098  {5, 83},
1099  },
1100  };
1101  // clang-format off
1102  EXPECT_EQ(
1103  93,
1104  from(maps)
1105  | map([](std::map<int, int>& m) {
1106  return get_ptr(m, 3);
1107  })
1108  | dereference
1109  | sum);
1110  // clang-format on
1111  }
1112  {
1113  vector<unique_ptr<int>> ups;
1114  ups.emplace_back(new int(3));
1115  ups.emplace_back();
1116  ups.emplace_back(new int(7));
1117  EXPECT_EQ(10, from(ups) | dereference | sum);
1118  EXPECT_EQ(10, from(ups) | move | dereference | sum);
1119  }
1120 }
const Map::mapped_type * get_ptr(const Map &map, const Key &key)
Definition: MapUtil.h:169
Definition: InvokeTest.cpp:58
std::atomic< int64_t > sum(0)
auto v
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
static Map map(mapCap)
static map< string, int > m
char a
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
static set< string > s
Definition: InvokeTest.cpp:65
constexpr detail::Dereference dereference
Definition: Base-inl.h:2575
TEST ( Gen  ,
DereferenceWithLValueRef   
)

Definition at line 1143 of file BaseTest.cpp.

References folly::copy(), folly::gen::dereference, EXPECT_EQ, and folly::gen::from().

1143  {
1144  auto original = vector<DereferenceWrapper>{{"foo"}, {"bar"}};
1145  auto copy = original;
1146  auto expected = vector<string>{"foo", "bar"};
1147  auto actual = from(original) | dereference | as<vector>();
1148  EXPECT_EQ(expected, actual);
1149  EXPECT_EQ(copy, original);
1150 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
constexpr detail::Dereference dereference
Definition: Base-inl.h:2575
TEST ( Gen  ,
DereferenceWithRValueRef   
)

Definition at line 1152 of file BaseTest.cpp.

References folly::gen::dereference, folly::gen::empty(), EXPECT_EQ, folly::gen::from(), and folly::gen::move.

1152  {
1153  auto original = vector<DereferenceWrapper>{{"foo"}, {"bar"}};
1154  auto empty = vector<DereferenceWrapper>{{}, {}};
1155  auto expected = vector<string>{"foo", "bar"};
1156  auto actual = from(original) | move | dereference | as<vector>();
1157  EXPECT_EQ(expected, actual);
1158  EXPECT_EQ(empty, original);
1159 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
constexpr detail::Dereference dereference
Definition: Base-inl.h:2575
TEST ( Gen  ,
Indirect   
)

Definition at line 1161 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::first, folly::gen::from(), folly::gen::indirect, and folly::gen::unwrap.

1161  {
1162  vector<int> vs{1};
1163  EXPECT_EQ(&vs[0], from(vs) | indirect | first | unwrap);
1164 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Indirect indirect
Definition: Base-inl.h:2577
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
constexpr detail::First first
Definition: Base-inl.h:2553
TEST ( Gen  ,
Guard   
)

Definition at line 1166 of file BaseTest.cpp.

References EXPECT_EQ, EXPECT_THROW, folly::gen::from(), and folly::gen::sum.

1166  {
1167  using std::runtime_error;
1168  // clang-format off
1169  EXPECT_THROW(
1170  from({"1", "a", "3"})
1171  | eachTo<int>()
1172  | sum,
1173  runtime_error);
1174  EXPECT_EQ(
1175  4,
1176  from({"1", "a", "3"})
1177  | guard<runtime_error>([](runtime_error&, const char*) {
1178  return true; // continue
1179  })
1180  | eachTo<int>()
1181  | sum);
1182  EXPECT_EQ(
1183  1,
1184  from({"1", "a", "3"})
1185  | guard<runtime_error>([](runtime_error&, const char*) {
1186  return false; // break
1187  })
1188  | eachTo<int>()
1189  | sum);
1190  EXPECT_THROW(
1191  from({"1", "a", "3"})
1192  | guard<runtime_error>([](runtime_error&, const char* v) {
1193  if (v[0] == 'a') {
1194  throw;
1195  }
1196  return true;
1197  })
1198  | eachTo<int>()
1199  | sum,
1200  runtime_error);
1201  // clang-format on
1202 }
std::atomic< int64_t > sum(0)
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
TEST ( Gen  ,
eachTryTo   
)

Definition at line 1204 of file BaseTest.cpp.

References folly::gen::dereference, EXPECT_EQ, folly::gen::from(), folly::gen::sum, and folly::gen::takeWhile().

1204  {
1205  using std::runtime_error;
1206  // clang-format off
1207  EXPECT_EQ(
1208  4,
1209  from({"1", "a", "3"})
1210  | eachTryTo<int>()
1211  | dereference
1212  | sum);
1213  EXPECT_EQ(
1214  1,
1215  from({"1", "a", "3"})
1216  | eachTryTo<int>()
1217  | takeWhile()
1218  | dereference
1219  | sum);
1220  // clang-format on
1221 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TakeWhile takeWhile(Predicate pred=Predicate())
Definition: Base.h:663
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
constexpr detail::Dereference dereference
Definition: Base-inl.h:2575
TEST ( Gen  ,
Batch   
)

Definition at line 1223 of file BaseTest.cpp.

References folly::gen::batch(), EXPECT_EQ, EXPECT_THROW, and folly::gen::seq().

1223  {
1224  EXPECT_EQ((vector<vector<int>>{{1}}), seq(1, 1) | batch(5) | as<vector>());
1225  EXPECT_EQ(
1226  (vector<vector<int>>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11}}),
1227  seq(1, 11) | batch(3) | as<vector>());
1228  EXPECT_THROW(seq(1, 1) | batch(0) | as<vector>(), std::invalid_argument);
1229 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Batch batch(size_t batchSize)
Definition: Base-inl.h:2602
TEST ( Gen  ,
BatchMove   
)

Definition at line 1231 of file BaseTest.cpp.

References folly::gen::batch(), EXPECT_EQ, i, folly::gen::mapped(), and folly::gen::seq().

1231  {
1232  auto expected = vector<vector<int>>{{0, 1}, {2, 3}, {4}};
1233  auto actual = seq(0, 4) |
1234  mapped([](int i) { return std::make_unique<int>(i); }) | batch(2) |
1235  mapped([](std::vector<std::unique_ptr<int>>& pVector) {
1236  std::vector<int> iVector;
1237  for (const auto& p : pVector) {
1238  iVector.push_back(*p);
1239  };
1240  return iVector;
1241  }) |
1242  as<vector>();
1243  EXPECT_EQ(expected, actual);
1244 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
detail::Batch batch(size_t batchSize)
Definition: Base-inl.h:2602
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
TEST ( Gen  ,
Window   
)

Definition at line 1246 of file BaseTest.cpp.

References folly::gen::dereference, EXPECT_EQ, i, folly::gen::mapped(), folly::gen::seq(), folly::gen::take(), and folly::gen::window().

1246  {
1247  auto expected = seq(0, 10) | as<std::vector>();
1248  for (size_t windowSize = 1; windowSize <= 20; ++windowSize) {
1249  // no early stop
1250  auto actual = seq(0, 10) |
1251  mapped([](int i) { return std::make_unique<int>(i); }) | window(4) |
1252  dereference | as<std::vector>();
1253  EXPECT_EQ(expected, actual) << windowSize;
1254  }
1255  for (size_t windowSize = 1; windowSize <= 20; ++windowSize) {
1256  // pre-window take
1257  auto actual = seq(0) |
1258  mapped([](int i) { return std::make_unique<int>(i); }) | take(11) |
1259  window(4) | dereference | as<std::vector>();
1260  EXPECT_EQ(expected, actual) << windowSize;
1261  }
1262  for (size_t windowSize = 1; windowSize <= 20; ++windowSize) {
1263  // post-window take
1264  auto actual = seq(0) |
1265  mapped([](int i) { return std::make_unique<int>(i); }) | window(4) |
1266  take(11) | dereference | as<std::vector>();
1267  EXPECT_EQ(expected, actual) << windowSize;
1268  }
1269 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
std::vector< Future< Result > > window(Collection input, F func, size_t n)
Definition: Future-inl.h:1789
detail::Take take(Number count)
Definition: Base-inl.h:2582
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
constexpr detail::Dereference dereference
Definition: Base-inl.h:2575
TEST ( Gen  ,
Just   
)

Definition at line 1271 of file BaseTest.cpp.

References EXPECT_EQ, EXPECT_NE, folly::gen::first, folly::gen::indirect, folly::gen::just(), folly::gen::move, folly::gen::sum, folly::gen::unwrap, and x.

1271  {
1272  {
1273  int x = 3;
1274  auto j = just(x);
1275  EXPECT_EQ(&x, j | indirect | first | unwrap);
1276  x = 4;
1277  EXPECT_EQ(4, j | sum);
1278  }
1279  {
1280  int x = 3;
1281  const int& cx = x;
1282  auto j = just(cx);
1283  EXPECT_EQ(&x, j | indirect | first | unwrap);
1284  x = 5;
1285  EXPECT_EQ(5, j | sum);
1286  }
1287  {
1288  int x = 3;
1289  auto j = just(std::move(x));
1290  EXPECT_NE(&x, j | indirect | first | unwrap);
1291  x = 5;
1292  EXPECT_EQ(3, j | sum);
1293  }
1294 }
Definition: InvokeTest.cpp:58
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
constexpr detail::Indirect indirect
Definition: Base-inl.h:2577
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::just_fn just
constexpr detail::First first
Definition: Base-inl.h:2553
TEST ( Gen  ,
GroupBy   
)

Definition at line 1296 of file BaseTest.cpp.

References folly::gen::count, EXPECT_EQ, folly::gen::from(), g(), folly::gen::groupBy(), folly::gen::Group< Key, Value >::key(), folly::gen::mapOp(), folly::gen::maxBy(), mode, folly::gen::Group< Key, Value >::size(), folly::gen::sum, and folly::gen::unwrap.

1296  {
1297  vector<string> strs{
1298  "zero",
1299  "one",
1300  "two",
1301  "three",
1302  "four",
1303  "five",
1304  "six",
1305  "seven",
1306  "eight",
1307  "nine",
1308  };
1309 
1310  auto gb = from(strs) | groupBy([](const string& str) { return str.size(); });
1311 
1312  EXPECT_EQ(10, gb | mapOp(count) | sum);
1313  EXPECT_EQ(3, gb | count);
1314 
1315  vector<string> mode{"zero", "four", "five", "nine"};
1316  // clang-format off
1317  EXPECT_EQ(
1318  mode,
1319  gb
1320  | maxBy([](const Group<size_t, string>& g) { return g.size(); })
1321  | unwrap
1322  | as<vector>());
1323  // clang-format on
1324 
1325  vector<string> largest{"three", "seven", "eight"};
1326  // clang-format off
1327  EXPECT_EQ(
1328  largest,
1329  gb
1330  | maxBy([](const Group<size_t, string>& g) { return g.key(); })
1331  | unwrap
1332  | as<vector>());
1333  // clang-format on
1334 }
std::atomic< int64_t > sum(0)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
folly::Optional< PskKeyExchangeMode > mode
Map mapOp(Operator op)
Definition: Base.h:559
const Key & key() const
Definition: Base-inl.h:61
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
int * count
MaxBy maxBy(Selector selector=Selector())
Definition: Base.h:806
g_t g(f_t)
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
GroupBy groupBy(Selector selector=Selector())
Definition: Base.h:683
size_t size() const
Definition: Base-inl.h:65
TEST ( Gen  ,
GroupByAdjacent   
)

Definition at line 1336 of file BaseTest.cpp.

References EXPECT_EQ, folly::gen::from(), folly::gen::groupByAdjacent(), i, folly::gen::mapOp(), folly::gen::seq(), and folly::gen::take().

1336  {
1337  vector<string> finite{"a", "b", "cc", "dd", "ee", "fff", "g", "hhh"};
1338  vector<vector<string>> finiteGroups{
1339  {"a", "b"}, {"cc", "dd", "ee"}, {"fff"}, {"g"}, {"hhh"}};
1340  EXPECT_EQ(
1341  finiteGroups,
1342  from(finite) |
1343  groupByAdjacent([](const string& str) { return str.size(); }) |
1344  mapOp(as<vector>()) | as<vector>());
1345 
1346  auto infinite = seq(0);
1347  vector<vector<int>> infiniteGroups{
1348  {0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}, {10, 11, 12, 13, 14}};
1349  EXPECT_EQ(
1350  infiniteGroups,
1351  infinite | groupByAdjacent([](const int& i) { return (i % 10) < 5; }) |
1352  take(3) | mapOp(as<vector>()) | as<vector>());
1353 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen seq(Value first, Value last)
Definition: Base.h:484
Map mapOp(Operator op)
Definition: Base.h:559
GroupByAdjacent groupByAdjacent(Selector selector=Selector())
Definition: Base.h:690
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
detail::Take take(Number count)
Definition: Base-inl.h:2582
TEST ( Gen  ,
Unwrap   
)

Definition at line 1355 of file BaseTest.cpp.

References folly::gen::empty(), EXPECT_EQ, EXPECT_FALSE, EXPECT_THROW, EXPECT_TRUE, folly::gen::from(), folly::gen::indirect, folly::make_optional(), folly::gen::max, folly::gen::move, folly::gen::unwrap, and folly::gen::unwrapOr().

1355  {
1356  Optional<int> o(4);
1357  Optional<int> e;
1358  EXPECT_EQ(4, o | unwrap);
1360 
1361  auto oup = folly::make_optional(std::make_unique<int>(5));
1362  // optional has a value, and that value is non-null
1363  EXPECT_TRUE(bool(oup | unwrap));
1364  EXPECT_EQ(5, *(oup | unwrap));
1365  EXPECT_TRUE(oup.hasValue()); // still has a pointer (null or not)
1366  EXPECT_TRUE(bool(oup.value())); // that value isn't null
1367 
1368  auto moved1 = std::move(oup) | unwrapOr(std::make_unique<int>(6));
1369  // oup still has a value, but now it's now nullptr since the pointer was moved
1370  // into moved1
1371  EXPECT_TRUE(oup.hasValue());
1372  EXPECT_FALSE(oup.value());
1373  EXPECT_TRUE(bool(moved1));
1374  EXPECT_EQ(5, *moved1);
1375 
1376  auto moved2 = std::move(oup) | unwrapOr(std::make_unique<int>(7));
1377  // oup's still-valid nullptr value wins here, the pointer to 7 doesn't apply
1378  EXPECT_FALSE(moved2);
1379 
1380  oup.clear();
1381  auto moved3 = std::move(oup) | unwrapOr(std::make_unique<int>(8));
1382  // oup is empty now, so the unwrapOr comes into play.
1383  EXPECT_TRUE(bool(moved3));
1384  EXPECT_EQ(8, *moved3);
1385 
1386  {
1387  // mixed types, with common type matching optional
1388  Optional<double> full(3.3);
1389  decltype(full) empty;
1390  auto fallback = unwrapOr(4);
1391  EXPECT_EQ(3.3, full | fallback);
1392  EXPECT_EQ(3.3, std::move(full) | fallback);
1393  EXPECT_EQ(3.3, full | std::move(fallback));
1394  EXPECT_EQ(3.3, std::move(full) | std::move(fallback));
1395  EXPECT_EQ(4.0, empty | fallback);
1396  EXPECT_EQ(4.0, std::move(empty) | fallback);
1397  EXPECT_EQ(4.0, empty | std::move(fallback));
1398  EXPECT_EQ(4.0, std::move(empty) | std::move(fallback));
1399  }
1400 
1401  {
1402  // mixed types, with common type matching fallback
1403  Optional<int> full(3);
1404  decltype(full) empty;
1405  auto fallback = unwrapOr(5.0); // type: double
1406  // if we chose 'int' as the common type, we'd see truncation here
1407  EXPECT_EQ(1.5, (full | fallback) / 2);
1408  EXPECT_EQ(1.5, (std::move(full) | fallback) / 2);
1409  EXPECT_EQ(1.5, (full | std::move(fallback)) / 2);
1410  EXPECT_EQ(1.5, (std::move(full) | std::move(fallback)) / 2);
1411  EXPECT_EQ(2.5, (empty | fallback) / 2);
1412  EXPECT_EQ(2.5, (std::move(empty) | fallback) / 2);
1413  EXPECT_EQ(2.5, (empty | std::move(fallback)) / 2);
1414  EXPECT_EQ(2.5, (std::move(empty) | std::move(fallback)) / 2);
1415  }
1416 
1417  {
1418  auto opt = folly::make_optional(std::make_shared<int>(8));
1419  auto fallback = unwrapOr(std::make_unique<int>(9));
1420  // fallback must be std::move'd to be used
1421  EXPECT_EQ(8, *(opt | std::move(fallback)));
1422  EXPECT_TRUE(bool(opt.value())); // shared_ptr copied out, not moved
1423  EXPECT_TRUE(bool(opt)); // value still present
1424  EXPECT_TRUE(bool(fallback.value())); // fallback value not needed
1425 
1426  EXPECT_EQ(8, *(std::move(opt) | std::move(fallback)));
1427  EXPECT_FALSE(opt.value()); // shared_ptr moved out
1428  EXPECT_TRUE(bool(opt)); // gutted value still present
1429  EXPECT_TRUE(bool(fallback.value())); // fallback value not needed
1430 
1431  opt.clear();
1432 
1433  EXPECT_FALSE(opt); // opt is empty now
1434  EXPECT_EQ(9, *(std::move(opt) | std::move(fallback)));
1435  EXPECT_FALSE(fallback.value()); // fallback moved out!
1436  }
1437 
1438  {
1439  // test with nullptr
1440  vector<int> v{1, 2};
1441  EXPECT_EQ(&v[1], from(v) | indirect | max | unwrap);
1442  v.clear();
1443  EXPECT_FALSE(from(v) | indirect | max | unwrapOr(nullptr));
1444  }
1445 
1446  {
1447  // mixed type determined by fallback
1449  int x = 3;
1450  EXPECT_EQ(&x, empty | unwrapOr(&x));
1451  }
1452 }
Definition: InvokeTest.cpp:58
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
LogLevel max
Definition: LogLevel.cpp:31
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
constexpr Optional< _t< std::decay< T > > > make_optional(T &&v)
Definition: Optional.h:450
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
UnwrapOr unwrapOr(Fallback &&fallback)
Definition: Base.h:847
constexpr detail::Indirect indirect
Definition: Base-inl.h:2577
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::from_fn from
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
constexpr detail::Unwrap unwrap
Definition: Base-inl.h:2579
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862

Variable Documentation

auto multiply = [](int a, int b) { return a * b; }

Definition at line 71 of file BaseTest.cpp.

Referenced by TEST().

auto product = foldl(1, multiply)

Definition at line 73 of file BaseTest.cpp.

Referenced by TEST().

auto square = [](int x) { return x * x; }

Definition at line 69 of file BaseTest.cpp.

Referenced by TEST().