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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/**
\file
test file for RPCCompDetId
\author Stefano ARGIRO
\date 27 Jul 2005
*/
#include <cppunit/extensions/HelperMacros.h>
#include <DataFormats/MuonDetId/interface/RPCCompDetId.h>
#include <FWCore/Utilities/interface/Exception.h>
#include <iostream>
using namespace std;
class testRPCCompDetId : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(testRPCCompDetId);
CPPUNIT_TEST(testOne);
CPPUNIT_TEST(testFail);
CPPUNIT_TEST(testMemberOperators);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testOne();
void testFail();
void testMemberOperators();
};
///registration of the test so that the runner can find it
CPPUNIT_TEST_SUITE_REGISTRATION(testRPCCompDetId);
void testRPCCompDetId::testOne() {
for (int region = RPCCompDetId::minRegionId; region <= RPCCompDetId::maxRegionId; ++region) {
const int minRing(0 != region ? RPCCompDetId::minRingForwardId : RPCCompDetId::minRingBarrelId);
const int maxRing(0 != region ? RPCCompDetId::maxRingForwardId : RPCCompDetId::maxRingBarrelId);
const int minSector(0 != region ? RPCCompDetId::minSectorForwardId : RPCCompDetId::minSectorBarrelId);
const int maxSector(0 != region ? RPCCompDetId::maxSectorForwardId : RPCCompDetId::maxSectorBarrelId);
for (int ring = minRing; ring <= maxRing; ++ring)
for (int station = RPCCompDetId::minStationId; station <= RPCCompDetId::maxStationId; ++station)
for (int sector = minSector; sector <= maxSector; ++sector)
for (int layer = RPCCompDetId::minLayerId; layer <= RPCCompDetId::maxLayerId; ++layer)
for (int subSector = RPCCompDetId::minSubSectorId; subSector <= RPCCompDetId::maxSubSectorId; ++subSector) {
RPCCompDetId detid(region, ring, station, sector, layer, subSector, 0);
CPPUNIT_ASSERT(detid.region() == region);
CPPUNIT_ASSERT(detid.ring() == ring);
CPPUNIT_ASSERT(detid.station() == station);
CPPUNIT_ASSERT(detid.sector() == sector);
CPPUNIT_ASSERT(detid.layer() == layer);
CPPUNIT_ASSERT(detid.subsector() == subSector);
// test constructor from id
int myId = detid.rawId();
RPCCompDetId anotherId(myId);
CPPUNIT_ASSERT(detid == anotherId);
}
}
}
void testRPCCompDetId::testFail() {
// contruct using an invalid input index
try {
// Station number too high
RPCCompDetId detid(0, 1, 7, 2, 2, 1, 1);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
// contruct using an invalid input id
try {
RPCCompDetId detid(100);
CPPUNIT_ASSERT("Failed to throw required exception" == 0);
detid.rawId(); // avoid compiler warning
} catch (cms::Exception& e) {
// OK
} catch (...) {
CPPUNIT_ASSERT("Threw wrong kind of exception" == 0);
}
}
void testRPCCompDetId::testMemberOperators() {
RPCCompDetId unit1(0, -2, 1, 2, 2, 1, 1);
RPCCompDetId unit2 = unit1;
CPPUNIT_ASSERT(unit2 == unit1);
}
|