Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**
0002    \file
0003    test file for RPCCompDetId
0004 
0005    \author Stefano ARGIRO
0006    \date 27 Jul 2005
0007 */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include <DataFormats/MuonDetId/interface/RPCCompDetId.h>
0011 #include <FWCore/Utilities/interface/Exception.h>
0012 
0013 #include <iostream>
0014 using namespace std;
0015 
0016 class testRPCCompDetId : public CppUnit::TestFixture {
0017   CPPUNIT_TEST_SUITE(testRPCCompDetId);
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(testRPCCompDetId);
0034 
0035 void testRPCCompDetId::testOne() {
0036   for (int region = RPCCompDetId::minRegionId; region <= RPCCompDetId::maxRegionId; ++region) {
0037     const int minRing(0 != region ? RPCCompDetId::minRingForwardId : RPCCompDetId::minRingBarrelId);
0038     const int maxRing(0 != region ? RPCCompDetId::maxRingForwardId : RPCCompDetId::maxRingBarrelId);
0039     const int minSector(0 != region ? RPCCompDetId::minSectorForwardId : RPCCompDetId::minSectorBarrelId);
0040     const int maxSector(0 != region ? RPCCompDetId::maxSectorForwardId : RPCCompDetId::maxSectorBarrelId);
0041 
0042     for (int ring = minRing; ring <= maxRing; ++ring)
0043       for (int station = RPCCompDetId::minStationId; station <= RPCCompDetId::maxStationId; ++station)
0044         for (int sector = minSector; sector <= maxSector; ++sector)
0045           for (int layer = RPCCompDetId::minLayerId; layer <= RPCCompDetId::maxLayerId; ++layer)
0046             for (int subSector = RPCCompDetId::minSubSectorId; subSector <= RPCCompDetId::maxSubSectorId; ++subSector) {
0047               RPCCompDetId detid(region, ring, station, sector, layer, subSector, 0);
0048 
0049               CPPUNIT_ASSERT(detid.region() == region);
0050               CPPUNIT_ASSERT(detid.ring() == ring);
0051               CPPUNIT_ASSERT(detid.station() == station);
0052               CPPUNIT_ASSERT(detid.sector() == sector);
0053               CPPUNIT_ASSERT(detid.layer() == layer);
0054               CPPUNIT_ASSERT(detid.subsector() == subSector);
0055 
0056               //  test constructor from id
0057               int myId = detid.rawId();
0058               RPCCompDetId anotherId(myId);
0059               CPPUNIT_ASSERT(detid == anotherId);
0060             }
0061   }
0062 }
0063 
0064 void testRPCCompDetId::testFail() {
0065   // contruct using an invalid input index
0066   try {
0067     // Station number too high
0068     RPCCompDetId detid(0, 1, 7, 2, 2, 1, 1);
0069     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0070     detid.rawId();  // avoid compiler warning
0071   } catch (cms::Exception& e) {
0072     // OK
0073   } catch (...) {
0074     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0075   }
0076 
0077   // contruct using an invalid input id
0078   try {
0079     RPCCompDetId detid(100);
0080     CPPUNIT_ASSERT("Failed to throw required exception" == 0);
0081     detid.rawId();  // avoid compiler warning
0082   } catch (cms::Exception& e) {
0083     // OK
0084   } catch (...) {
0085     CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
0086   }
0087 }
0088 
0089 void testRPCCompDetId::testMemberOperators() {
0090   RPCCompDetId unit1(0, -2, 1, 2, 2, 1, 1);
0091   RPCCompDetId unit2 = unit1;
0092   CPPUNIT_ASSERT(unit2 == unit1);
0093 }