CbmRoot
_GTestCbmTrdPoint.cxx
Go to the documentation of this file.
1 #include "CbmTrdPoint.h"
2 
3 #include "gtest/gtest-spi.h"
4 #include "gtest/gtest.h"
5 
6 #include "compareTrdPoint.h"
7 
8 TEST(_GTestCbmTrdPoint, CheckDefaultConstructor) {
9  // Create object
10  CbmTrdPoint test;
11 
13  -1,
14  -1,
15  TVector3(0., 0., 0.),
16  TVector3(0., 0., 0.),
17  TVector3(0., 0., 0.),
18  TVector3(0., 0., 0.),
19  0.,
20  0.,
21  0.,
22  0);
23 
24  CbmTrdPoint* test1 = new CbmTrdPoint();
25 
27  -1,
28  -1,
29  TVector3(0., 0., 0.),
30  TVector3(0., 0., 0.),
31  TVector3(0., 0., 0.),
32  TVector3(0., 0., 0.),
33  0.,
34  0.,
35  0.,
36  0);
37 }
38 
39 TEST(_GTestCbmTrdPoint, CheckStandardConstructor) {
40  Int_t trackid {34};
41  Int_t detid {45};
42  TVector3 posin {-2.1, 6.1, 23.};
43  TVector3 momin {2.5, 4.5, 78.};
44  TVector3 posout {2.1, -6.1, -23.};
45  TVector3 momout {-2.5, -4.5, -78.};
46  Double_t tof {34.56};
47  Double_t length {1.2};
48  Double_t eloss {0.4567};
49  Int_t eventid {0};
50  // Create object
51  CbmTrdPoint test(
52  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
53 
55  trackid,
56  detid,
57  posin,
58  momin,
59  posout,
60  momout,
61  tof,
62  length,
63  eloss,
64  eventid);
65 
66  CbmTrdPoint* test1 = new CbmTrdPoint(
67  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
68 
70  trackid,
71  detid,
72  posin,
73  momin,
74  posout,
75  momout,
76  tof,
77  length,
78  eloss,
79  eventid);
80 }
81 
82 TEST(_GTestCbmTrdPoint, CheckCopyConstructor) {
83  Int_t trackid {34};
84  Int_t detid {45};
85  TVector3 posin {-2.1, 6.1, 23.};
86  TVector3 momin {2.5, 4.5, 78.};
87  TVector3 posout {2.1, -6.1, -23.};
88  TVector3 momout {-2.5, -4.5, -78.};
89  Double_t tof {34.56};
90  Double_t length {1.2};
91  Double_t eloss {0.4567};
92  Int_t eventid {0};
93  // Create object
94  CbmTrdPoint test(
95  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
96 
98  trackid,
99  detid,
100  posin,
101  momin,
102  posout,
103  momout,
104  tof,
105  length,
106  eloss,
107  eventid);
108 
109  // Create object by copy constructing
110  // test should be equal to test2 and
111  // test should not be changed
112  CbmTrdPoint test2 {test};
113 
115  trackid,
116  detid,
117  posin,
118  momin,
119  posout,
120  momout,
121  tof,
122  length,
123  eloss,
124  eventid);
125 
126  // Test if the original object wasn't changed
128  trackid,
129  detid,
130  posin,
131  momin,
132  posout,
133  momout,
134  tof,
135  length,
136  eloss,
137  eventid);
138 }
139 
140 TEST(_GTestCbmTrdPoint, CheckCopyAssignmentOperator) {
141  Int_t trackid {34};
142  Int_t detid {45};
143  TVector3 posin {-2.1, 6.1, 23.};
144  TVector3 momin {2.5, 4.5, 78.};
145  TVector3 posout {2.1, -6.1, -23.};
146  TVector3 momout {-2.5, -4.5, -78.};
147  Double_t tof {34.56};
148  Double_t length {1.2};
149  Double_t eloss {0.4567};
150  Int_t eventid {0};
151  // Create object
152  CbmTrdPoint test(
153  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
154 
156  trackid,
157  detid,
158  posin,
159  momin,
160  posout,
161  momout,
162  tof,
163  length,
164  eloss,
165  eventid);
166 
167  // Create object by copy constructing
168  // test should be equal to test2 and
169  // test should not be changed
170  CbmTrdPoint test2 {};
171  test2 = test;
172 
174  trackid,
175  detid,
176  posin,
177  momin,
178  posout,
179  momout,
180  tof,
181  length,
182  eloss,
183  eventid);
184 
185  // Test if the original object wasn't changed
187  trackid,
188  detid,
189  posin,
190  momin,
191  posout,
192  momout,
193  tof,
194  length,
195  eloss,
196  eventid);
197 }
198 
199 TEST(_GTestCbmTrdPoint, CheckMoveConstructor) {
200  Int_t trackid {34};
201  Int_t detid {45};
202  TVector3 posin {-2.1, 6.1, 23.};
203  TVector3 momin {2.5, 4.5, 78.};
204  TVector3 posout {2.1, -6.1, -23.};
205  TVector3 momout {-2.5, -4.5, -78.};
206  Double_t tof {34.56};
207  Double_t length {1.2};
208  Double_t eloss {0.4567};
209  Int_t eventid {0};
210  // Create object
211  CbmTrdPoint test(
212  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
213 
215  trackid,
216  detid,
217  posin,
218  momin,
219  posout,
220  momout,
221  tof,
222  length,
223  eloss,
224  eventid);
225 
226  // Create object by copy constructing
227  // test should be equal to test2 and
228  // test should not be changed
229  CbmTrdPoint test2 {std::move(test)};
230 
232  trackid,
233  detid,
234  posin,
235  momin,
236  posout,
237  momout,
238  tof,
239  length,
240  eloss,
241  eventid);
242 
243  // For objects with simple types move fall back to copy so
244  // the original object is kept unchanged
246  trackid,
247  detid,
248  posin,
249  momin,
250  posout,
251  momout,
252  tof,
253  length,
254  eloss,
255  eventid);
256 }
257 
258 TEST(_GTestCbmTrdPoint, CheckAssignmentOperator) {
259  Int_t trackid {34};
260  Int_t detid {45};
261  TVector3 posin {-2.1, 6.1, 23.};
262  TVector3 momin {2.5, 4.5, 78.};
263  TVector3 posout {2.1, -6.1, -23.};
264  TVector3 momout {-2.5, -4.5, -78.};
265  Double_t tof {34.56};
266  Double_t length {1.2};
267  Double_t eloss {0.4567};
268  Int_t eventid {0};
269  // Create object
270  CbmTrdPoint test(
271  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
272 
274  trackid,
275  detid,
276  posin,
277  momin,
278  posout,
279  momout,
280  tof,
281  length,
282  eloss,
283  eventid);
284 
285  // Create object by copy constructing
286  // test should be equal to test2 and
287  // test should not be changed
288  CbmTrdPoint test2 {};
289  test2 = std::move(test);
290 
292  trackid,
293  detid,
294  posin,
295  momin,
296  posout,
297  momout,
298  tof,
299  length,
300  eloss,
301  eventid);
302 
303  // For objects with simple types move fall back to copy so
304  // the original object is kept unchanged
306  trackid,
307  detid,
308  posin,
309  momin,
310  posout,
311  momout,
312  tof,
313  length,
314  eloss,
315  eventid);
316 }
317 
318 TEST(_GTestCbmTrdPoint, CheckPrint) {
319  Int_t trackid {34};
320  Int_t detid {45};
321  TVector3 posin {-2.1, 6.1, 23.};
322  TVector3 momin {2.5, 4.5, 78.};
323  TVector3 posout {2.1, -6.1, -23.};
324  TVector3 momout {-2.5, -4.5, -78.};
325  Double_t tof {34.56};
326  Double_t length {1.2};
327  Double_t eloss {0.4567};
328  Int_t eventid {0};
329  // Create object
330  CbmTrdPoint test(
331  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
332 
334  trackid,
335  detid,
336  posin,
337  momin,
338  posout,
339  momout,
340  tof,
341  length,
342  eloss,
343  eventid);
344 
345  testing::internal::CaptureStdout();
346  test.Print("");
347  std::string output = testing::internal::GetCapturedStdout();
348 
349  EXPECT_STREQ("[INFO] TRD point for track 34 in detector 45\n[INFO] "
350  "Position In (-2.1, 6.1, 23) cm\n[INFO] Momentum In (2.5, "
351  "4.5, 78) GeV\n[INFO] Position Out (2.1, -6.1, -23) "
352  "cm\n[INFO] Momentum Out (-2.5, -4.5, -78) GeV\n[INFO] "
353  "Time 34.56 ns, Length 1.2 cm, Energy loss 456700 keV\n",
354  output.c_str());
355 }
356 
357 
358 TEST(_GTestCbmTrdPoint, CheckPositionOut) {
359  Int_t trackid {34};
360  Int_t detid {45};
361  TVector3 posin {-2.1, 6.1, 23.};
362  TVector3 momin {2.5, 4.5, 78.};
363  TVector3 posout {2.1, -6.1, -23.};
364  TVector3 momout {-2.5, -4.5, -78.};
365  Double_t tof {34.56};
366  Double_t length {1.2};
367  Double_t eloss {0.4567};
368  Int_t eventid {0};
369  // Create object
370  CbmTrdPoint test(
371  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
372 
374  trackid,
375  detid,
376  posin,
377  momin,
378  posout,
379  momout,
380  tof,
381  length,
382  eloss,
383  eventid);
384 
385 
386  TVector3 testVect {0., 0., 0.};
387 
388  test.PositionOut(testVect);
389 
390  EXPECT_FLOAT_EQ(posout.X(), testVect.X());
391  EXPECT_FLOAT_EQ(posout.Y(), testVect.Y());
392  EXPECT_FLOAT_EQ(posout.Z(), testVect.Z());
393 }
394 
395 TEST(_GTestCbmTrdPoint, CheckMomentumOut) {
396  Int_t trackid {34};
397  Int_t detid {45};
398  TVector3 posin {-2.1, 6.1, 23.};
399  TVector3 momin {2.5, 4.5, 78.};
400  TVector3 posout {2.1, -6.1, -23.};
401  TVector3 momout {-2.5, -4.5, -78.};
402  Double_t tof {34.56};
403  Double_t length {1.2};
404  Double_t eloss {0.4567};
405  Int_t eventid {0};
406  // Create object
407  CbmTrdPoint test(
408  trackid, detid, posin, momin, posout, momout, tof, length, eloss);
409 
411  trackid,
412  detid,
413  posin,
414  momin,
415  posout,
416  momout,
417  tof,
418  length,
419  eloss,
420  eventid);
421 
422 
423  TVector3 testVect {0., 0., 0.};
424 
425  test.MomentumOut(testVect);
426 
427  EXPECT_FLOAT_EQ(momout.X(), testVect.X());
428  EXPECT_FLOAT_EQ(momout.Y(), testVect.Y());
429  EXPECT_FLOAT_EQ(momout.Z(), testVect.Z());
430 }
CbmTrdPoint::PositionOut
void PositionOut(TVector3 &pos) const
Definition: CbmTrdPoint.h:78
compareTrdPoint.h
TEST
TEST(_GTestCbmTrdPoint, CheckDefaultConstructor)
Definition: _GTestCbmTrdPoint.cxx:8
CbmTrdPoint::Print
virtual void Print(const Option_t *opt) const
Definition: CbmTrdPoint.cxx:51
CbmTrdPoint::MomentumOut
void MomentumOut(TVector3 &mom) const
Definition: CbmTrdPoint.h:79
compareTrdPointDataMembers
void compareTrdPointDataMembers(CbmTrdPoint &test, Int_t trackID, Int_t detID, TVector3 posin, TVector3 momin, TVector3 posout, TVector3 momout, Double_t tof, Double_t length, Double_t eLoss, Int_t eventid)
Definition: compareTrdPoint.h:6
CbmTrdPoint
Definition: CbmTrdPoint.h:23
CbmTrdPoint.h