~plane1/maus/devel_624

« back to all changes in this revision

Viewing changes to tests/cpp_unit/Interface/TofHitTest.cpp

  • Committer: Christopher Tunnell
  • Date: 2011-03-15 11:37:27 UTC
  • Revision ID: c.tunnell1@physics.ox.ac.uk-20110315113727-c4eyg55wg5zzj3in
closes #376

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "gtest/gtest.h" 
2
 
 
3
 
#include "src/common/Interface/TofHit.hh"
4
 
 
5
 
 
6
 
namespace {
7
 
bool TofHitEquality(TofHit th1, TofHit th2, double float_tolerance) {
8
 
  bool equal = true;
9
 
  equal &= th1.GetTrackID()   == th2.GetTrackID();
10
 
  equal &= th1.GetStripNo()   == th2.GetStripNo();
11
 
  equal &= th1.GetPlaneNo()   == th2.GetPlaneNo();
12
 
  equal &= th1.GetStationNo() == th2.GetStationNo();
13
 
  equal &= th1.GetPID()       == th2.GetPID();
14
 
 
15
 
  equal &= th1.GetVolumeName() == th2.GetVolumeName();
16
 
 
17
 
  equal &= fabs(th1.GetTime()   - th2.GetTime())   < float_tolerance;
18
 
  equal &= fabs(th1.GetEnergy() - th2.GetEnergy()) < float_tolerance;
19
 
  equal &= fabs(th1.GetMass()   - th2.GetMass())   < float_tolerance;
20
 
  equal &= fabs(th1.GetEdep()   - th2.GetEdep())   < float_tolerance;
21
 
  equal &= fabs(th1.GetPathLength() - th2.GetPathLength()) < float_tolerance;
22
 
 
23
 
  equal &= fabs( (th1.GetPosition() - th2.GetPosition()).mag() ) < float_tolerance;
24
 
  equal &= fabs( (th1.GetMomentum() - th2.GetMomentum()).mag() ) < float_tolerance;
25
 
  return equal;
26
 
}
27
 
 
28
 
class TofHitTest : public ::testing::Test
29
 
{
30
 
protected:
31
 
  TofHitTest () { 
32
 
    th_all.SetTrackID(1);
33
 
    th_all.SetStripNo(2);
34
 
    th_all.SetPlaneNo(3);
35
 
    th_all.SetStationNo(4);
36
 
    th_all.SetEdep(5.);
37
 
    th_all.SetPathLength(6.);
38
 
    th_all.SetPosition(ThreeVector(7., 8., 9.));
39
 
    th_all.SetMomentum(ThreeVector(10., 11., 12.));
40
 
    th_all.SetVolumeName("Tofstrip4320");
41
 
    th_all.SetTime(13.);
42
 
    th_all.SetEnergy(14.);
43
 
    th_all.SetPID(15);
44
 
    th_all.SetMass(16.);
45
 
  }
46
 
  virtual ~TofHitTest  () {}
47
 
 
48
 
  virtual void SetUp   () {}
49
 
  virtual void TearDown() {}
50
 
 
51
 
  TofHit th;
52
 
  TofHit th_all;
53
 
 
54
 
};
55
 
 
56
 
 
57
 
 
58
 
// Test accessors by set and then get
59
 
TEST_F(TofHitTest, TrackIDAccessors) {
60
 
  TofHit th;
61
 
  th.SetTrackID   (-1);
62
 
  EXPECT_EQ(th.GetTrackID(), -1);
63
 
}
64
 
 
65
 
TEST_F(TofHitTest, StripNoAccessors) {
66
 
  th.SetStripNo   (-2);
67
 
  EXPECT_EQ(th.GetStripNo(), -2);
68
 
}
69
 
 
70
 
TEST_F(TofHitTest, PlaneNoAccessors) {
71
 
  th.SetPlaneNo   (-3);
72
 
  EXPECT_EQ(th.GetPlaneNo(),-3);
73
 
}
74
 
 
75
 
TEST_F(TofHitTest, StationNoAccessors) {
76
 
  th.SetStationNo (-4);
77
 
  EXPECT_EQ(th.GetStationNo(), -4);
78
 
}
79
 
 
80
 
TEST_F(TofHitTest, EdepAccessors) {
81
 
  th.SetEdep      (-5);
82
 
  EXPECT_EQ(th.GetEdep(), -5);
83
 
}
84
 
 
85
 
TEST_F(TofHitTest, PathLengthAccessors) {
86
 
  th.SetPathLength(-6.);
87
 
  EXPECT_EQ(th.GetPathLength(), -6.);
88
 
}
89
 
 
90
 
TEST_F(TofHitTest, PositionAccessors) {
91
 
  th.SetPosition  (ThreeVector(-7., -8., -9.));
92
 
  EXPECT_EQ(th.GetPosition().x(),-7.);
93
 
  EXPECT_EQ(th.GetPosition().y(),-8.);
94
 
  EXPECT_EQ(th.GetPosition().z(),-9.);
95
 
}
96
 
 
97
 
TEST_F(TofHitTest, MomentumAccessors) {
98
 
  th.SetMomentum  (ThreeVector(-10., -11., -12.));
99
 
  EXPECT_EQ(th.GetMomentum().x(),-10.);
100
 
  EXPECT_EQ(th.GetMomentum().y(),-11.);
101
 
  EXPECT_EQ(th.GetMomentum().z(),-12.);
102
 
}
103
 
 
104
 
TEST_F(TofHitTest, VolumeNameAccessors) {
105
 
  th.SetVolumeName("Badname");
106
 
  EXPECT_EQ( th.GetVolumeName(), "Badname");
107
 
}
108
 
 
109
 
TEST_F(TofHitTest, TimeAccessors) {
110
 
  th.SetTime      (-13.);
111
 
  EXPECT_EQ( th.GetTime(), -13. );
112
 
}
113
 
 
114
 
TEST_F(TofHitTest, EnergyAccessors) {
115
 
  th.SetEnergy    (-14.);
116
 
  EXPECT_EQ( th.GetEnergy(), -14. );
117
 
}
118
 
 
119
 
TEST_F(TofHitTest, PIDAccessors) {
120
 
  th.SetPID       (-15);
121
 
  EXPECT_EQ( th.GetPID(), -15 );
122
 
}
123
 
 
124
 
TEST_F(TofHitTest, MassAccessors) {
125
 
  th.SetMass      (-16.);
126
 
  EXPECT_EQ( th.GetMass(), -16. );
127
 
}
128
 
 
129
 
TEST_F(TofHitTest, AddEdep) {
130
 
  th.SetEdep(1.);
131
 
  th.AddEdep(2.);
132
 
  EXPECT_DOUBLE_EQ(th.GetEdep(), 3.);
133
 
}
134
 
 
135
 
TEST_F(TofHitTest, AddPathLength) {
136
 
  th.SetPathLength(1.);
137
 
  th.AddPathLength(2.);
138
 
  EXPECT_DOUBLE_EQ(th.GetPathLength(), 3.);
139
 
}
140
 
 
141
 
//Hope no one ever wants to make a 0 > strip number > 10...
142
 
TEST_F(TofHitTest, DecodeVolumeName) { //GAK!
143
 
  th.SetVolumeName("TOFstrip10123");
144
 
  th.DecodeVolumeName();
145
 
  EXPECT_EQ(th.GetStationNo(), 10);
146
 
  EXPECT_EQ(th.GetPlaneNo(), 1); 
147
 
  EXPECT_EQ(th.GetStripNo(), 2);
148
 
}
149
 
 
150
 
TEST_F(TofHitTest, CopyConstructor) {
151
 
  TofHit th_copy(th);
152
 
  TofHit th_all_copy(th_all);
153
 
  EXPECT_TRUE(TofHitEquality(th, th_copy, 1e-9));
154
 
  EXPECT_TRUE(TofHitEquality(th_all, th_all_copy, 1e-9));
155
 
}
156
 
 
157
 
 
158
 
TEST_F(TofHitTest, EqualsAssignmentOperator) {
159
 
  TofHit th_copy; //if I put all on one line, gcc implicitly calls copy constructor
160
 
  th_copy = th;
161
 
  TofHit th_all_copy;
162
 
  th_all_copy = th_all;
163
 
  EXPECT_TRUE(TofHitEquality(th, th_copy, 1e-9));
164
 
  EXPECT_TRUE(TofHitEquality(th_all, th_all_copy, 1e-9));
165
 
}
166
 
 
167
 
TEST_F(TofHitTest, Destructor) {
168
 
  TofHit* th_p        = new TofHit();
169
 
  TofHit* th_all_copy = new TofHit(th_all);
170
 
  delete th_all_copy; //check memory is deallocated
171
 
  delete th_p;
172
 
}
173
 
 
174
 
 
175
 
} //namespace
176