All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
filterRangeFor_test.cc File Reference

Test for util::filterRangeFor(). More...

#include "lardata/Utilities/filterRangeFor.h"
#include "boost/test/unit_test.hpp"
#include <algorithm>
#include <numeric>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( filterRangeFor_test )
 

Functions

template<typename Cont , typename Pred >
void testPredicate (Cont &data, Pred pred)
 
 BOOST_AUTO_TEST_CASE (filterRangeFor_testCase)
 

Detailed Description

Test for util::filterRangeFor().

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
May 1, 2018
See Also
lardata/Utilities/filterRangeFor.h

The test is run with no arguments.

Definition in file filterRangeFor_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( filterRangeFor_test )

Definition at line 16 of file filterRangeFor_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( filterRangeFor_testCase  )

Definition at line 42 of file filterRangeFor_test.cc.

42  {
43 
44  std::vector<int> data(20);
45  std::iota(data.begin(), data.end(), 0);
46 
47  BOOST_TEST_MESSAGE("Selecting multiples of 3");
48  testPredicate<std::vector<int> const>
49  (data, [](int v){ return (v % 3) == 0; });
50  testPredicate(data, [](int v){ return (v % 3) == 0; });
51 
52  BOOST_TEST_MESSAGE("Selecting values that are not 9");
53  testPredicate<std::vector<int> const>(data, [](int v){ return v != 9; });
54  testPredicate(data, [](int v){ return v != 9; });
55 
56  BOOST_TEST_MESSAGE("Selecting values that are 50");
57  testPredicate<std::vector<int> const>(data, [](int v){ return v == 50; });
58  testPredicate(data, [](int v){ return v == 50; });
59 
60 } // BOOST_AUTO_TEST_CASE(filterRangeFor_testCase)
void testPredicate(Cont &data, Pred pred)
template<typename Cont , typename Pred >
void testPredicate ( Cont &  data,
Pred  pred 
)

Definition at line 26 of file filterRangeFor_test.cc.

26  {
27 
28  auto const nPass = std::count_if(data.begin(), data.end(), pred);
29 
30  unsigned int n = 0;
31  for (auto const& v: util::filterRangeFor(data, pred)) {
32  ++n;
33  BOOST_TEST_CHECKPOINT(" testing value: " << v);
34  BOOST_TEST(pred(v));
35  } // for
36 
37  BOOST_TEST(n == nPass);
38 } // testPredicate()
auto filterRangeFor(Range &&range, Pred &&pred) -> decltype(auto)
Provides iteration only through elements passing a condition.