Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:45:43

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "CommonTools/Utils/interface/PointerComparator.h"
0003 #include "CommonTools/Utils/interface/PtComparator.h"
0004 #include "CommonTools/Utils/interface/EtComparator.h"
0005 #include <iostream>
0006 
0007 class testComparators : public CppUnit::TestFixture {
0008   CPPUNIT_TEST_SUITE(testComparators);
0009   CPPUNIT_TEST(checkAll);
0010   CPPUNIT_TEST_SUITE_END();
0011 
0012 public:
0013   void setUp() {}
0014   void tearDown() {}
0015   void checkAll();
0016 };
0017 
0018 CPPUNIT_TEST_SUITE_REGISTRATION(testComparators);
0019 
0020 namespace test {
0021   struct A {
0022     explicit A(double x) : x_(x) {}
0023     double pt() const { return x_; }
0024     double et() const { return x_; }
0025     double px() const { return x_; }
0026     double py() const { return x_; }
0027     double pz() const { return x_; }
0028 
0029   private:
0030     double x_;
0031   };
0032 }  // namespace test
0033 
0034 void testComparators::checkAll() {
0035   using namespace test;
0036   A a(1), b(2);
0037 
0038   LessByPt<A> cmp1;
0039   LessByEt<A> cmp2;
0040   NumericSafeLessByPt<A> cmp3;
0041   NumericSafeLessByEt<A> cmp4;
0042   CPPUNIT_ASSERT(cmp1(a, b));
0043   CPPUNIT_ASSERT(cmp2(a, b));
0044   CPPUNIT_ASSERT(cmp3(a, b));
0045   CPPUNIT_ASSERT(cmp4(a, b));
0046 
0047   GreaterByPt<A> cmp5;
0048   GreaterByEt<A> cmp6;
0049   NumericSafeGreaterByPt<A> cmp7;
0050   NumericSafeGreaterByEt<A> cmp8;
0051   CPPUNIT_ASSERT(cmp5(b, a));
0052   CPPUNIT_ASSERT(cmp6(b, a));
0053   CPPUNIT_ASSERT(cmp7(b, a));
0054   CPPUNIT_ASSERT(cmp8(b, a));
0055   PointerComparator<LessByPt<A> > cmp9;
0056   CPPUNIT_ASSERT(cmp9(&a, &b));
0057 }