CbmRoot
_GTestCbmMatch.cxx
Go to the documentation of this file.
1 #include "CbmLink.h"
2 #include "CbmMatch.h"
3 
4 #include "gtest/gtest-spi.h"
5 #include "gtest/gtest.h"
6 
7 #include "compareLink.h"
8 #include "compareMatch.h"
9 
10 TEST(_GTestCbmMatch, CheckDefaultConstructor) {
11  CbmMatch test;
12  {
13  SCOPED_TRACE("CheckDefaultConstructor");
14  compareMatchDataMembers(test, 0, 0.);
15  }
16 }
17 
18 TEST(_GTestCbmMatch, AddLink1) {
19  CbmMatch test;
20  {
21  SCOPED_TRACE("AddLink1: Initial Test");
22  compareMatchDataMembers(test, 0, 0.);
23  }
24 
25  test.AddLink(-2., -2);
26  {
27  SCOPED_TRACE("AddLink1: Add first link");
28  compareMatchDataMembers(test, 1, -2.);
29  }
30 
31  test.AddLink(-2., -2);
32  {
33  SCOPED_TRACE("AddLink1: Add second link");
34  compareMatchDataMembers(test, 1, -4.);
35  }
36 
37  test.AddLink(-8., -3);
38  {
39  SCOPED_TRACE("AddLink1: Add third link");
40  compareMatchDataMembers(test, 2, -12.);
41  }
42 }
43 
44 TEST(_GTestCbmMatch, AddLink2) {
45 
46  CbmMatch test;
47  {
48  SCOPED_TRACE("AddLink2: Initial Test");
49  compareMatchDataMembers(test, 0, 0.);
50  }
51 
52  test.AddLink(-2., -2, -2, -2);
53  {
54  SCOPED_TRACE("AddLink2: Add first link");
55  compareMatchDataMembers(test, 1, -2.);
56  }
57 
58  test.AddLink(-2., -2, -2, -2);
59  {
60  SCOPED_TRACE("AddLink2: Add second link");
61  compareMatchDataMembers(test, 1, -4.);
62  }
63 
64  test.AddLink(-8., -3, -2, -2);
65  {
66  SCOPED_TRACE("AddLink2: Add third link");
67  compareMatchDataMembers(test, 2, -12.);
68  }
69 
70  test.AddLink(8., -3, -3, -2);
71  {
72  SCOPED_TRACE("AddLink2: Add forth link");
73  compareMatchDataMembers(test, 3, -4.);
74  }
75 
76  test.AddLink(4., -3, -3, -3);
77  {
78  SCOPED_TRACE("AddLink2: Add fifth link");
79  compareMatchDataMembers(test, 4, 0.);
80  }
81 }
82 
84  CbmMatch test;
85 
86  CbmLink testLink1 {};
87  CbmLink testLink2 {};
88  CbmLink testLink3 {-8., -3, -2, -2};
89  CbmLink testLink4 {8., -3, -3, -2};
90  CbmLink testLink5 {2., -3, -3, -3};
91 
92  {
93  SCOPED_TRACE("AddLink3: Initial Test");
94  compareMatchDataMembers(test, 0, 0.);
95  }
96 
97  test.AddLink(testLink1);
98  {
99  SCOPED_TRACE("AddLink3: Add first link");
100  compareMatchDataMembers(test, 1, -1.);
101  }
102 
103  test.AddLink(testLink2);
104  {
105  SCOPED_TRACE("AddLink3: Add second link");
106  compareMatchDataMembers(test, 1, -2.);
107  }
108 
109  test.AddLink(testLink3);
110  {
111  SCOPED_TRACE("AddLink3: Add third link");
112  compareMatchDataMembers(test, 2, -10.);
113  }
114 
115  test.AddLink(testLink4);
116  {
117  SCOPED_TRACE("AddLink3: Add forth link");
118  compareMatchDataMembers(test, 3, -2.);
119  }
120 
121  test.AddLink(testLink5);
122  {
123  SCOPED_TRACE("AddLink3: Add fifth link");
124  compareMatchDataMembers(test, 4, 0.);
125  }
126 
127  return test;
128 }
129 
130 TEST(_GTestCbmMatch, AddLink3) {
131 
132  CbmMatch test = TestAddLinks3();
133  CbmMatch test2;
134 
135  test2.AddLinks(test);
136  {
137  SCOPED_TRACE("AddLink3: Add fifth link");
138  compareMatchDataMembers(test2, 4, 0.);
139  }
140 }
141 
142 TEST(_GTestCbmMatch, ClearLink) {
143 
144  CbmMatch test = TestAddLinks3();
145  {
146  SCOPED_TRACE("ClearLink: Initial Test");
147  compareMatchDataMembers(test, 4, 0.);
148  }
149 
150  test.ClearLinks();
151  {
152  SCOPED_TRACE("ClearLink: Clear Link");
153  compareMatchDataMembers(test, 0, 0.);
154  }
155 }
156 
157 
158 TEST(_GTestCbmMatch, GetLink) {
159 
160  CbmMatch test = TestAddLinks3();
161  {
162  SCOPED_TRACE("GetLink: Initial Test");
163  compareMatchDataMembers(test, 4, 0.);
164  }
165 
166  CbmLink testLink {};
167  testLink = test.GetLink(0);
168  {
169  SCOPED_TRACE("GetLink: Get Link 0");
170  compareLinkDataMembers(testLink, -1, -1, -1, -2.);
171  }
172 
173  testLink = test.GetLink(1);
174  {
175  SCOPED_TRACE("GetLink: Get Link 1");
176  compareLinkDataMembers(testLink, -2, -2, -3, -8.);
177  }
178 
179  testLink = test.GetLink(2);
180  {
181  SCOPED_TRACE("GetLink: Get Link 2");
182  compareLinkDataMembers(testLink, -2, -3, -3, 8.);
183  }
184 
185  testLink = test.GetLink(3);
186  {
187  SCOPED_TRACE("GetLink: Get Link 3");
188  compareLinkDataMembers(testLink, -3, -3, -3, 2.);
189  }
190 }
191 
192 TEST(_GTestCbmMatch, GetLinks) {
193 
194  CbmMatch test = TestAddLinks3();
195  {
196  SCOPED_TRACE("GetLinks: Initial Test");
197  compareMatchDataMembers(test, 4, 0.);
198  }
199 
200  std::vector<CbmLink> link = test.GetLinks();
201 
202  CbmLink testLink = link[0];
203  {
204  SCOPED_TRACE("GetLinks: Get Link 0");
205  compareLinkDataMembers(testLink, -1, -1, -1, -2.);
206  }
207 
208  testLink = link[1];
209  {
210  SCOPED_TRACE("GetLinks: Get Link 1");
211  compareLinkDataMembers(testLink, -2, -2, -3, -8.);
212  }
213 
214  testLink = link[2];
215  {
216  SCOPED_TRACE("GetLinks: Get Link 2");
217  compareLinkDataMembers(testLink, -2, -3, -3, 8.);
218  }
219 
220  testLink = link[3];
221  {
222  SCOPED_TRACE("GetLinks: Get Link 3");
223  compareLinkDataMembers(testLink, -3, -3, -3, 2.);
224  }
225 }
226 
227 TEST(_GTestCbmMatch, GetMatchedLink) {
228 
229  CbmMatch test = TestAddLinks3();
230  {
231  SCOPED_TRACE("GetMatchedLink: Initial Test");
232  compareMatchDataMembers(test, 4, 0.);
233  }
234 
235  // Get the link with the highest weight
236  // which is in our test setup Link3
237  CbmLink testLink = test.GetMatchedLink();
238  {
239  SCOPED_TRACE("GetMatchedLink: Test Links");
240  compareLinkDataMembers(testLink, -2, -3, -3, 8);
241  }
242 }
243 
244 
245 TEST(_GTestCbmMatch, CheckToString) {
246 
247  CbmMatch test;
248 
249  EXPECT_STREQ("CbmMatch: nofLinks=0\n totalWeight=0, matchedIndex=-1\n",
250  test.ToString().c_str());
251 
252  CbmLink testLink {-8., -3, -2, -2};
253  test.AddLink(testLink);
254 
255  EXPECT_STREQ("CbmMatch: nofLinks=1\nCbmLink: weight=-8 index=-3 entry=-2 "
256  "file=-2\n totalWeight=-8, matchedIndex=0\n",
257  test.ToString().c_str());
258 }
CbmMatch::GetMatchedLink
const CbmLink & GetMatchedLink() const
Definition: CbmMatch.h:37
CbmMatch
Definition: CbmMatch.h:22
compareMatch.h
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
TestAddLinks3
CbmMatch TestAddLinks3()
Definition: _GTestCbmMatch.cxx:83
CbmMatch.h
CbmMatch::AddLink
void AddLink(const CbmLink &newLink)
Definition: CbmMatch.cxx:42
TEST
TEST(_GTestCbmMatch, CheckDefaultConstructor)
Definition: _GTestCbmMatch.cxx:10
compareMatchDataMembers
void compareMatchDataMembers(CbmMatch &testMatch, Int_t noflinks, Double_t weight)
Definition: compareMatch.h:7
CbmMatch::AddLinks
void AddLinks(const CbmMatch &match)
Definition: CbmMatch.cxx:35
CbmMatch::GetLinks
const std::vector< CbmLink > & GetLinks() const
Definition: CbmMatch.h:36
CbmMatch::ClearLinks
void ClearLinks()
Definition: CbmMatch.cxx:74
CbmMatch::ToString
virtual std::string ToString() const
Return string representation of the object.
Definition: CbmMatch.cxx:21