Macros | Functions
Edge_test.cc File Reference

Simple test on a recob::Edge object. More...

#include <array>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include "boost/test/unit_test.hpp"
#include "lardataobj/RecoBase/Edge.h"
#include "lardataobj/RecoBase/SpacePoint.h"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( hit_test )
 

Functions

void EdgeTestDefaultConstructor ()
 
void EdgeTestValueConstructor ()
 
void EdgeTestSpacePointConstructor ()
 
void EdgeClassDocumentationTest ()
 
 BOOST_AUTO_TEST_CASE (EdgeTests)
 
 BOOST_AUTO_TEST_CASE (EdgeDocumentationTests)
 

Detailed Description

Simple test on a recob::Edge object.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
July 6, 2017
Version
1.0

This test simply creates recob::Edge objects and verifies that the values it can access are the right ones.

See http://www.boost.org/libs/test for the Boost test library home page.

Timing: version 1.0: ~1.5" (debug mode)

Definition in file Edge_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( hit_test )

Definition at line 33 of file Edge_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( EdgeTests  )

Definition at line 290 of file Edge_test.cc.

290  {
294 } // EdgeTests
void EdgeTestValueConstructor()
Definition: Edge_test.cc:99
void EdgeTestSpacePointConstructor()
Definition: Edge_test.cc:160
void EdgeTestDefaultConstructor()
Definition: Edge_test.cc:46
BOOST_AUTO_TEST_CASE ( EdgeDocumentationTests  )

Definition at line 296 of file Edge_test.cc.

296  {
298 }
void EdgeClassDocumentationTest()
Definition: Edge_test.cc:235
void EdgeClassDocumentationTest ( )

Definition at line 235 of file Edge_test.cc.

235  {
236 
237  // prepare the space points for the test, already sorted
238  // BUG the double brace syntax is required to work around clang bug 21629
239  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
240  std::array<double, 3U> const error = {{ 0.1, 0.1, 0.1 }};
241  std::array<double, 3U> const point = {{ 1.0, 1.0, 1.0 }};
242  std::vector<recob::SpacePoint> points;
243  for (unsigned int i = 0; i < 10; ++i)
244  points.emplace_back(point.data(), error.data(), 1.0, i);
245 
246  // prepare the edge with two of the space points
247  recob::Edge const edge(points[3], points[6], 0);
248 
249  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250  if (!std::is_sorted(points.begin(), points.end()))
251  throw std::runtime_error("Space points not sorted!");
252 
253  // find the first space point
254  auto const iFirstPoint = std::lower_bound
255  (points.begin(), points.end(), edge.FirstPointID());
256 
257  if ((iFirstPoint == points.end()) || (iFirstPoint->ID() != edge.FirstPointID())) {
258  throw std::runtime_error
259  ("First point not found: ID=" + std::to_string(edge.FirstPointID()));
260  }
261  recob::SpacePoint const& firstPoint = *iFirstPoint;
262 
263  // find the second space point
264  auto const iSecondPoint = std::lower_bound
265  (points.begin(), points.end(), edge.SecondPointID());
266 
267  if ((iSecondPoint == points.end()) || (iSecondPoint->ID() != edge.SecondPointID())) {
268  throw std::runtime_error
269  ("Second point not found: ID=" + std::to_string(edge.SecondPointID()));
270  }
271  recob::SpacePoint const& secondPoint = *iSecondPoint;
272  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273 
274  BOOST_TEST(&firstPoint == &points[3]);
275  BOOST_TEST(&secondPoint == &points[6]);
276 
277 
278 } // EdgeClassDocumentationTest()
error
Definition: include.cc:26
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
Edge is an object containing the results of a Principal Components Analysis of a group of space point...
Definition: Edge.h:61
void EdgeTestDefaultConstructor ( )

Definition at line 46 of file Edge_test.cc.

46  {
47 
48  /*
49  * Tested interface:
50  *
51  * /// Default constructor (all invalid IDs).
52  * Edge() = default;
53  *
54  * /// Returns the length of this edge [cm].
55  * double Length() const;
56  *
57  * /// Returns the ID of the SpacePoint this edge emanates from.
58  * SpacePointID_t FirstPointID() const;
59  *
60  * /// Returns the ID of the SpacePoint this edge ends on.
61  * SpacePointID_t SecondPointID() const;
62  *
63  * /// Returns the ID of this edge.
64  * ID_t ID() const;
65  *
66  * /// Streaming operator: prints the edge `a` into the specified stream.
67  * std::ostream& operator << (std::ostream & o, const Edge& a);
68  *
69  * /// Comparison operator: strict ordering of edge by ID.
70  * inline bool operator< (const Edge& a, const Edge& b);
71  *
72  * /// Comparison operator: strict ordering of edge by ID.
73  * inline bool operator< (const Edge& e, Edge::ID_t id);
74  *
75  * /// Comparison operator: strict ordering of edge by ID.
76  * inline bool operator< (Edge::ID_t id, const Edge& e);
77  *
78  */
79 
80  recob::Edge const e;
81 
82  constexpr auto EinvID = recob::Edge::InvalidID;
83  constexpr auto PinvID = recob::SpacePoint::InvalidID;
84 
85  BOOST_TEST(e.ID() == EinvID);
86  BOOST_TEST(e.FirstPointID() == PinvID);
87  BOOST_TEST(e.SecondPointID() == PinvID);
88  BOOST_TEST(e.Length() == 0.0); // exactly so
89 
90  BOOST_TEST(!(e < e));
91  BOOST_TEST(!(e < e.ID()));
92  BOOST_TEST(!(e.ID() < e));
93 
94  std::cout << "Printout of a default-constructed edge: " << e << std::endl;
95 
96 } // EdgeTestDefaultConstructor()
static constexpr ID_t InvalidID
Special value for an invalid edge ID.
Definition: Edge.h:72
double Length() const
Returns the length of this edge [cm].
Definition: Edge.h:108
SpacePointID_t FirstPointID() const
Returns the ID of the SpacePoint this edge emanates from.
Definition: Edge.h:112
const double e
static constexpr ID_t InvalidID
Special value for an invalid ID.
Definition: SpacePoint.h:29
ID_t ID() const
Returns the ID of this edge.
Definition: Edge.h:120
QTextStream & endl(QTextStream &s)
Edge is an object containing the results of a Principal Components Analysis of a group of space point...
Definition: Edge.h:61
SpacePointID_t SecondPointID() const
Returns the ID of the SpacePoint this edge ends on.
Definition: Edge.h:116
void EdgeTestSpacePointConstructor ( )

Definition at line 160 of file Edge_test.cc.

160  {
161 
162  /*
163  * Tested interface:
164  *
165  * /// Default constructor (all invalid IDs).
166  * Edge() = default;
167  *
168  * /// Constructor: assigns all values.
169  * Edge(
170  * const double length,
171  * SpacePointID_t firstPointID, SpacePointID_t secondPointID,
172  * ID_t id = InvalidID
173  * );
174  *
175  * /// Constructor: uses the specified spacepoints.
176  * Edge(
177  * SpacePoint const& firstPoint, SpacePoint const& secondPoint,
178  * ID_t id = InvalidID
179  * );
180  *
181  * /// Returns the length of this edge [cm].
182  * double Length() const;
183  *
184  * /// Returns the ID of the SpacePoint this edge emanates from.
185  * SpacePointID_t FirstPointID() const;
186  *
187  * /// Returns the ID of the SpacePoint this edge ends on.
188  * SpacePointID_t SecondPointID() const;
189  *
190  * /// Returns the ID of this edge.
191  * ID_t ID() const;
192  *
193  * /// Streaming operator: prints the edge `a` into the specified stream.
194  * std::ostream& operator << (std::ostream & o, const Edge& a);
195  *
196  * /// Comparison operator: strict ordering of edge by ID.
197  * inline bool operator< (const Edge& a, const Edge& b);
198  *
199  * /// Comparison operator: strict ordering of edge by ID.
200  * inline bool operator< (const Edge& e, Edge::ID_t id);
201  *
202  * /// Comparison operator: strict ordering of edge by ID.
203  * inline bool operator< (Edge::ID_t id, const Edge& e);
204  *
205  */
206 
207  // BUG the double brace syntax is required to work around clang bug 21629
208  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
209  std::array<double, 3U> const error = {{ 0.1, 0.1, 0.1 }};
210  std::array<double, 3U> point;
211 
212  // BUG the double brace syntax is required to work around clang bug 21629
213  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
214  point = {{ 1.0, 1.0, 1.0 }};
215  recob::SpacePoint const p1(point.data(), error.data(), 1.0, 0);
216 
217  // BUG the double brace syntax is required to work around clang bug 21629
218  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
219  point = {{ 4.0, 5.0, 13.0 }};
220  recob::SpacePoint const p2(point.data(), error.data(), 1.0, 1);
221 
222  recob::Edge const e(p1, p2, 0);
223 
224  BOOST_TEST(e.ID() == 0);
225  BOOST_TEST(e.FirstPointID() == 0);
226  BOOST_TEST(e.SecondPointID() == 1);
227  BOOST_CHECK_CLOSE(e.Length(), 13.0, 1e-4); // tolerance: 10^-6
228 
229  std::cout << "Printout of a spacepoint-constructed edge: " << e << std::endl;
230 
231 } // EdgeTestSpacePointConstructor()
error
Definition: include.cc:26
const double e
QTextStream & endl(QTextStream &s)
Edge is an object containing the results of a Principal Components Analysis of a group of space point...
Definition: Edge.h:61
void EdgeTestValueConstructor ( )

Definition at line 99 of file Edge_test.cc.

99  {
100 
101  /*
102  * Tested interface:
103  *
104  * /// Constructor: assigns all values.
105  * Edge(
106  * const double length,
107  * SpacePointID_t firstPointID, SpacePointID_t secondPointID,
108  * ID_t id = InvalidID
109  * );
110  *
111  * /// Returns the length of this edge [cm].
112  * double Length() const;
113  *
114  * /// Returns the ID of the SpacePoint this edge emanates from.
115  * SpacePointID_t FirstPointID() const;
116  *
117  * /// Returns the ID of the SpacePoint this edge ends on.
118  * SpacePointID_t SecondPointID() const;
119  *
120  * /// Returns the ID of this edge.
121  * ID_t ID() const;
122  *
123  * /// Streaming operator: prints the edge `a` into the specified stream.
124  * std::ostream& operator << (std::ostream & o, const Edge& a);
125  *
126  * /// Comparison operator: strict ordering of edge by ID.
127  * inline bool operator< (const Edge& a, const Edge& b);
128  *
129  * /// Comparison operator: strict ordering of edge by ID.
130  * inline bool operator< (const Edge& e, Edge::ID_t id);
131  *
132  * /// Comparison operator: strict ordering of edge by ID.
133  * inline bool operator< (Edge::ID_t id, const Edge& e);
134  *
135  */
136 
137  recob::Edge const e(3.0, 5, 10, 3);
138 
139  BOOST_TEST(e.ID() == 3);
140  BOOST_TEST(e.FirstPointID() == 5);
141  BOOST_TEST(e.SecondPointID() == 10);
142  BOOST_TEST(e.Length() == 3.0); // exactly so
143 
144  BOOST_TEST(!(e < e));
145  BOOST_TEST(!(e < e.ID()));
146  BOOST_TEST(!(e.ID() < e));
147 
148  std::cout << "Printout of a value-constructed edge: " << e << std::endl;
149 
150  recob::Edge o(3.0, 5, 10, 4);
151 
152  BOOST_TEST( (e < o));
153  BOOST_TEST(!(o < e));
154  BOOST_TEST( (e < o.ID()));
155  BOOST_TEST(!(o.ID() < e));
156 
157 } // EdgeTestValueConstructor()
const double e
QTextStream & endl(QTextStream &s)
Edge is an object containing the results of a Principal Components Analysis of a group of space point...
Definition: Edge.h:61