Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:09

0001 /**
0002    \file
0003    test file for ME0DetId
0004 
0005    \author Marcello Maggi from an example of Stefano ARGIRO
0006    \date 06 Jan 2014
0007 */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include "DataFormats/MuonDetId/interface/ME0DetId.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 
0013 #include <iostream>
0014 using namespace std;
0015 
0016 class testME0DetId : public CppUnit::TestFixture {
0017   CPPUNIT_TEST_SUITE(testME0DetId);
0018   CPPUNIT_TEST(testOne);
0019   CPPUNIT_TEST(testFail);
0020   CPPUNIT_TEST(testMemberOperators);
0021   CPPUNIT_TEST_SUITE_END();
0022 
0023 public:
0024   void setUp() {}
0025   void tearDown() {}
0026 
0027   void testOne();
0028   void testFail();
0029   void testMemberOperators();
0030 };
0031 
0032 ///registration of the test so that the runner can find it
0033 CPPUNIT_TEST_SUITE_REGISTRATION(testME0DetId);
0034 
0035 void testME0DetId::testOne() {
0036   for (int region = ME0DetId::minRegionId; region <= ME0DetId::maxRegionId; ++region) {
0037     for (int layer = ME0DetId::minLayerId; layer <= ME0DetId::maxLayerId; ++layer)
0038       for (int chamber = ME0DetId::minChamberId; chamber <= ME0DetId::maxChamberId; ++chamber) {
0039         for (int roll = ME0DetId::minRollId; roll <= ME0DetId::maxRollId; ++roll) {
0040           ME0DetId detid(region, layer, chamber, roll);
0041           CPPUNIT_ASSERT(detid.region() == region);
0042           CPPUNIT_ASSERT(detid.layer() == layer);
0043           CPPUNIT_ASSERT(detid.chamber() == chamber);
0044           CPPUNIT_ASSERT(detid.roll() == roll);
0045 
0046           //  test constructor from id
0047           int myId = detid.rawId();
0048           ME0DetId anotherId(myId);
0049           CPPUNIT_ASSERT(detid == anotherId);
0050         }
0051       }
0052   }
0053 }
0054 
0055 void testME0DetId::testFail() {
0056   // contruct using an invalid input index
0057   try {
0058     // Wrong Layer
0059     ME0DetId detid(0, 57, 0, 0);
0060     CPPUNIT_ASSERT("Failed to throw required exception 0" == 0);
0061     detid.rawId();  // avoid compiler warning
0062   } catch (cms::Exception& e) {
0063     // OK
0064   } catch (...) {
0065     CPPUNIT_ASSERT("Threw wrong kind of exception 0" == 0);
0066   }
0067 
0068   try {
0069     // Wrong Region
0070     ME0DetId detid(2, 0, 0, 0);
0071     CPPUNIT_ASSERT("Failed to throw required exception 1" == 0);
0072     detid.rawId();  // avoid compiler warning
0073   } catch (cms::Exception& e) {
0074     // OK
0075   } catch (...) {
0076     CPPUNIT_ASSERT("Threw wrong kind of exception 1" == 0);
0077   }
0078 
0079   try {
0080     // Not existant chamber number
0081     ME0DetId detid(-1, 1, 37, 1);
0082     CPPUNIT_ASSERT("Failed to throw required exception 2" == 0);
0083     detid.rawId();  // avoid compiler warning
0084   } catch (cms::Exception& e) {
0085     // OK
0086   } catch (...) {
0087     CPPUNIT_ASSERT("Threw wrong kind of exception 2" == 0);
0088   }
0089 
0090   // contruct using an invalid input id
0091   try {
0092     ME0DetId detid(100);
0093     CPPUNIT_ASSERT("Failed to throw required exception 3" == 0);
0094     detid.rawId();  // avoid compiler warning
0095   } catch (cms::Exception& e) {
0096     // OK
0097   } catch (...) {
0098     CPPUNIT_ASSERT("Threw wrong kind of exception 3" == 0);
0099   }
0100 }
0101 
0102 void testME0DetId::testMemberOperators() {
0103   ME0DetId unit1(1, 5, 3, 1);
0104   ME0DetId unit2 = unit1;
0105 
0106   CPPUNIT_ASSERT(unit2 == unit1);
0107 
0108   ME0DetId layer = unit1.layerId();
0109   ME0DetId unit3(1, 5, 3, 0);
0110 
0111   CPPUNIT_ASSERT(layer == unit3);
0112 
0113   ME0DetId chamber = unit1.chamberId();
0114   ME0DetId unit4(1, 0, 3, 0);
0115 
0116   CPPUNIT_ASSERT(chamber == unit4);
0117 }