Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:19

0001 #include <cppunit/CompilerOutputter.h>
0002 #include <cppunit/TestFixture.h>
0003 #include <cppunit/TestResult.h>
0004 #include <cppunit/TestResultCollector.h>
0005 #include <cppunit/TestRunner.h>
0006 #include <cppunit/TextTestProgressListener.h>
0007 #include <cppunit/extensions/HelperMacros.h>
0008 #include <cppunit/ui/text/TestRunner.h>
0009 
0010 #include <algorithm>
0011 #include <boost/foreach.hpp>
0012 #include <cassert>
0013 #include <iterator>
0014 
0015 #include "CalibFormats/SiStripObjects/interface/SiStripDelay.h"
0016 
0017 #ifndef TestSiStripDelay_cc
0018 #define TestSiStripDelay_cc
0019 
0020 class TestSiStripDelay : public CppUnit::TestFixture {
0021 public:
0022   TestSiStripDelay() {}
0023   void setUp() {
0024     baseDelay1 = new SiStripBaseDelay;
0025     baseDelaySign1 = 1;
0026     baseDelay2 = new SiStripBaseDelay;
0027     baseDelaySign2 = -1;
0028     totalDelays = 15000;
0029     // totalDelays = 1;
0030     for (uint32_t i = 0; i < totalDelays; ++i) {
0031       detIds.push_back(i);
0032       coarseDelay.push_back(i / 1000);
0033       fineDelay.push_back(i / 2000);
0034       baseDelay1->put(i, i / 1000, i / 2000);
0035       baseDelay2->put(i, i / 2000, i / 1000);
0036       // coarseDelay.push_back(1);
0037       // fineDelay.push_back(2);
0038       // baseDelay1->put(i, 1, 2);
0039       // baseDelay2->put(i, 2, 1);
0040     }
0041   }
0042 
0043   void tearDown() {
0044     delete baseDelay1;
0045     delete baseDelay2;
0046   }
0047 
0048   void testConstructor() {
0049     SiStripDelay delay(*baseDelay1, baseDelaySign1, std::make_pair("baseDelay1", "delay1"));
0050     CPPUNIT_ASSERT(delay.getNumberOfTags() == 1);
0051     CPPUNIT_ASSERT(delay.getBaseDelay(0) == baseDelay1);
0052     CPPUNIT_ASSERT(delay.getTagSign(0) == 1);
0053     CPPUNIT_ASSERT(delay.getRcdName(0) == "baseDelay1");
0054     CPPUNIT_ASSERT(delay.getLabelName(0) == "delay1");
0055   }
0056 
0057   void testFillNewDelay() {
0058     SiStripDelay delay(*baseDelay1, baseDelaySign1, std::make_pair("baseDelay1", "delay1"));
0059     delay.fillNewDelay(*baseDelay2, baseDelaySign2, std::make_pair("baseDelay2", "delay2"));
0060     CPPUNIT_ASSERT(delay.getNumberOfTags() == 2);
0061     CPPUNIT_ASSERT(delay.getBaseDelay(0) == baseDelay1);
0062     CPPUNIT_ASSERT(delay.getTagSign(0) == baseDelaySign1);
0063     CPPUNIT_ASSERT(delay.getRcdName(0) == "baseDelay1");
0064     CPPUNIT_ASSERT(delay.getLabelName(0) == "delay1");
0065     CPPUNIT_ASSERT(delay.getBaseDelay(1) == baseDelay2);
0066     CPPUNIT_ASSERT(delay.getTagSign(1) == baseDelaySign2);
0067     CPPUNIT_ASSERT(delay.getRcdName(1) == "baseDelay2");
0068     CPPUNIT_ASSERT(delay.getLabelName(1) == "delay2");
0069   }
0070 
0071   void testMakeDelay() {
0072     SiStripDelay delay(*baseDelay1, baseDelaySign1, std::make_pair("baseDelay1", "delay1"));
0073     CPPUNIT_ASSERT(delay.makeDelay());
0074     for (uint32_t i = 0; i < totalDelays; ++i) {
0075       CPPUNIT_ASSERT(float(delay.getDelay(detIds[i])) == float(baseDelay1->delay(detIds[i]) * baseDelaySign1));
0076     }
0077     delay.fillNewDelay(*baseDelay2, baseDelaySign2, std::make_pair("baseDelay2", "delay2"));
0078     CPPUNIT_ASSERT(delay.makeDelay());
0079     for (uint32_t i = 0; i < totalDelays; ++i) {
0080       //       std::cout << "float(delay.getDelay("<<detIds[i]<<")) = " <<
0081       //       float(delay.getDelay(detIds[i])) << std::endl; std::cout <<
0082       //       "float(baseDelay1->delay("<<detIds[i]<<") = " <<
0083       //       float(baseDelay1->delay(detIds[i])) << std::endl; std::cout <<
0084       //       "float(baseDelay2->delay("<<detIds[i]<<") = " <<
0085       //       float(baseDelay2->delay(detIds[i])) << std::endl; std::cout <<
0086       //       "float(baseDelay1->delay("<<detIds[i]<<")*"<<baseDelaySign1<<" -
0087       //       baseDelay2->delay("<<detIds[i]<<"))*"<<baseDelaySign2<<" = " <<
0088       //       float(baseDelay1->delay(detIds[i])*baseDelaySign1 +
0089       //       baseDelay2->delay(detIds[i])*baseDelaySign2) << std::endl;
0090       CPPUNIT_ASSERT(float(delay.getDelay(detIds[i])) == float(baseDelay1->delay(detIds[i]) * baseDelaySign1 +
0091                                                                baseDelay2->delay(detIds[i]) * baseDelaySign2));
0092     }
0093   }
0094 
0095   SiStripBaseDelay *baseDelay1;
0096   int baseDelaySign1;
0097   SiStripBaseDelay *baseDelay2;
0098   int baseDelaySign2;
0099   std::vector<uint32_t> detIds;
0100   std::vector<uint16_t> coarseDelay;
0101   std::vector<uint16_t> fineDelay;
0102   uint32_t totalDelays;
0103 
0104   // Declare and build the test suite
0105   CPPUNIT_TEST_SUITE(TestSiStripDelay);
0106   CPPUNIT_TEST(testConstructor);
0107   CPPUNIT_TEST(testFillNewDelay);
0108   CPPUNIT_TEST(testMakeDelay);
0109   CPPUNIT_TEST_SUITE_END();
0110 };
0111 
0112 // Register the test suite in the registry.
0113 // This way we will have to only pass the registry to the runner
0114 // and it will contain all the registered test suites.
0115 CPPUNIT_TEST_SUITE_REGISTRATION(TestSiStripDelay);
0116 
0117 #endif