File indexing completed on 2024-04-06 12:01:21
0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "CommonTools/Utils/interface/PtMinSelector.h"
0003 #include "CommonTools/Utils/interface/Selection.h"
0004 #include <iostream>
0005 #include <vector>
0006 #include <iterator>
0007 #include <algorithm>
0008
0009 class testSelectIterator : public CppUnit::TestFixture {
0010 CPPUNIT_TEST_SUITE(testSelectIterator);
0011 CPPUNIT_TEST(checkAll);
0012 CPPUNIT_TEST_SUITE_END();
0013
0014 public:
0015 void setUp() {}
0016 void tearDown() {}
0017 void checkAll();
0018 };
0019
0020 CPPUNIT_TEST_SUITE_REGISTRATION(testSelectIterator);
0021
0022 namespace test {
0023 struct A {
0024 explicit A(double x) : x_(x) {}
0025 double pt() const { return x_; }
0026
0027 private:
0028 double x_;
0029 };
0030 }
0031
0032 void testSelectIterator::checkAll() {
0033 using namespace test;
0034 using namespace std;
0035 vector<A> v;
0036 for (double x = 0; x < 10.1; ++x)
0037 v.push_back(A(x));
0038 CPPUNIT_ASSERT(v.size() == 11);
0039 PtMinSelector select(3.5);
0040 Selection<vector<A>, PtMinSelector> sel(v, select);
0041 CPPUNIT_ASSERT(sel.size() == 7);
0042 for (size_t i = 0; i < sel.size(); ++i) {
0043 CPPUNIT_ASSERT(select(sel[i]));
0044 }
0045 for (Selection<vector<A>, PtMinSelector>::const_iterator i = sel.begin(); i != sel.end(); ++i) {
0046 CPPUNIT_ASSERT(select(*i));
0047 }
0048 vector<A> selected;
0049 copy(sel.begin(), sel.end(), back_inserter(selected));
0050 CPPUNIT_ASSERT(sel.size() == selected.size());
0051 for (size_t i = 0; i < selected.size(); ++i) {
0052 CPPUNIT_ASSERT(select(selected[i]));
0053 }
0054 }