File indexing completed on 2023-10-25 09:36:19
0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "CommonTools/Utils/interface/MinFunctionSelector.h"
0003 #include "CommonTools/Utils/interface/MaxFunctionSelector.h"
0004 #include "CommonTools/Utils/interface/RangeSelector.h"
0005 #include "CommonTools/Utils/interface/MinObjectPairSelector.h"
0006 #include "CommonTools/Utils/interface/MaxObjectPairSelector.h"
0007 #include "CommonTools/Utils/interface/RangeObjectPairSelector.h"
0008 #include "CommonTools/Utils/interface/PtMinSelector.h"
0009 #include "CommonTools/Utils/interface/EtMinSelector.h"
0010 #include <iostream>
0011
0012 class testSelectors : public CppUnit::TestFixture {
0013 CPPUNIT_TEST_SUITE(testSelectors);
0014 CPPUNIT_TEST(checkAll);
0015 CPPUNIT_TEST_SUITE_END();
0016
0017 public:
0018 void setUp() {}
0019 void tearDown() {}
0020 void checkAll();
0021 };
0022
0023 CPPUNIT_TEST_SUITE_REGISTRATION(testSelectors);
0024
0025 namespace test {
0026 struct A {
0027 explicit A(double x) : x_(x) {}
0028 double x() const { return x_; }
0029 double pt() const { return x_; }
0030 double et() const { return x_; }
0031
0032 private:
0033 double x_;
0034 };
0035
0036 struct Add {
0037 double operator()(const A& a1, const A& a2) const { return a1.x() + a2.x(); }
0038 };
0039 }
0040
0041 void testSelectors::checkAll() {
0042 using namespace test;
0043 {
0044 A a(1.0);
0045 MinFunctionSelector<A, &A::x> minSel(0.9);
0046 MaxFunctionSelector<A, &A::x> maxSel(1.1);
0047 RangeSelector<A, &A::x> rangeSel(0.9, 1.1);
0048 PtMinSelector ptMinSel(0.9);
0049 EtMinSelector etMinSel(0.9);
0050
0051 CPPUNIT_ASSERT(minSel(a));
0052 CPPUNIT_ASSERT(maxSel(a));
0053 CPPUNIT_ASSERT(rangeSel(a));
0054 CPPUNIT_ASSERT(ptMinSel(a));
0055 CPPUNIT_ASSERT(etMinSel(a));
0056 }
0057 {
0058 A a1(3.0), a2(5.0);
0059 MinObjectPairSelector<Add> minSel(7.9);
0060 MaxObjectPairSelector<Add> maxSel(8.1);
0061 RangeObjectPairSelector<Add> rangeSel(7.9, 8.1);
0062 CPPUNIT_ASSERT(minSel(a1, a2));
0063 CPPUNIT_ASSERT(maxSel(a1, a2));
0064 CPPUNIT_ASSERT(rangeSel(a1, a2));
0065 }
0066 }