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