1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <cppunit/extensions/HelperMacros.h>
#include "CommonTools/Utils/interface/MinFunctionSelector.h"
#include "CommonTools/Utils/interface/MaxFunctionSelector.h"
#include "CommonTools/Utils/interface/RangeSelector.h"
#include "CommonTools/Utils/interface/MinObjectPairSelector.h"
#include "CommonTools/Utils/interface/MaxObjectPairSelector.h"
#include "CommonTools/Utils/interface/RangeObjectPairSelector.h"
#include "CommonTools/Utils/interface/PtMinSelector.h"
#include "CommonTools/Utils/interface/EtMinSelector.h"
#include <iostream>
class testSelectors : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(testSelectors);
CPPUNIT_TEST(checkAll);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void checkAll();
};
CPPUNIT_TEST_SUITE_REGISTRATION(testSelectors);
namespace test {
struct A {
explicit A(double x) : x_(x) {}
double x() const { return x_; }
double pt() const { return x_; }
double et() const { return x_; }
private:
double x_;
};
struct Add {
double operator()(const A& a1, const A& a2) const { return a1.x() + a2.x(); }
};
} // namespace test
void testSelectors::checkAll() {
using namespace test;
{
A a(1.0);
MinFunctionSelector<A, &A::x> minSel(0.9);
MaxFunctionSelector<A, &A::x> maxSel(1.1);
RangeSelector<A, &A::x> rangeSel(0.9, 1.1);
PtMinSelector ptMinSel(0.9);
EtMinSelector etMinSel(0.9);
CPPUNIT_ASSERT(minSel(a));
CPPUNIT_ASSERT(maxSel(a));
CPPUNIT_ASSERT(rangeSel(a));
CPPUNIT_ASSERT(ptMinSel(a));
CPPUNIT_ASSERT(etMinSel(a));
}
{
A a1(3.0), a2(5.0);
MinObjectPairSelector<Add> minSel(7.9);
MaxObjectPairSelector<Add> maxSel(8.1);
RangeObjectPairSelector<Add> rangeSel(7.9, 8.1);
CPPUNIT_ASSERT(minSel(a1, a2));
CPPUNIT_ASSERT(maxSel(a1, a2));
CPPUNIT_ASSERT(rangeSel(a1, a2));
}
}
|