ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EllipseBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EllipseBoundsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
13 #include <limits>
14 
18 
19 namespace Acts {
20 
21 namespace Test {
22 BOOST_AUTO_TEST_SUITE(Surfaces)
23 
24 
25 BOOST_AUTO_TEST_CASE(EllipseBoundsConstruction) {
26  double innerRx(10.), innerRy(15.), outerRx(25.), outerRy(30.),
27  phiSector(M_PI / 2.), averagePhi(0.);
28 
29  // test default construction
30  // EllipseBounds defaultConstructedEllipseBounds; //deleted
31  //
33  BOOST_CHECK_EQUAL(
34  EllipseBounds(innerRx, innerRy, outerRx, outerRy, phiSector, averagePhi)
35  .type(),
37  //
39  EllipseBounds original(innerRx, innerRy, outerRx, outerRy, phiSector,
40  averagePhi);
41  EllipseBounds copied(original);
42  BOOST_CHECK_EQUAL(copied, original);
43 }
44 
45 // Streaning and recreation test
46 BOOST_AUTO_TEST_CASE(EllipseBoundsRecreation) {
47  double innerRx(10.), innerRy(15.), outerRx(25.), outerRy(30.),
48  phiSector(M_PI / 2.), averagePhi(0.);
49  // const bool symmetric(false);
50  EllipseBounds original(innerRx, innerRy, outerRx, outerRy, phiSector,
51  averagePhi);
52  auto valvector = original.values();
53  std::array<double, EllipseBounds::eSize> values;
54  std::copy_n(valvector.begin(), EllipseBounds::eSize, values.begin());
55  EllipseBounds recreated(values);
56  BOOST_CHECK_EQUAL(recreated, original);
57 }
58 
59 // Unit tests for AnnulusBounds exception throwing
60 BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
61  double innerRx(10.), innerRy(15.), outerRx(25.), outerRy(30.),
62  phiSector(M_PI / 2.), averagePhi(0.);
63  // Exception for innerRx < 0
64  BOOST_CHECK_THROW(
65  EllipseBounds(-innerRx, innerRy, outerRx, outerRy, phiSector, averagePhi),
66  std::logic_error);
67  // Exception for innerRy < 0
68  BOOST_CHECK_THROW(
69  EllipseBounds(innerRx, -innerRy, outerRx, outerRy, phiSector, averagePhi),
70  std::logic_error);
71  // Exception for innerRx < 0 and innerRy < 0
72  BOOST_CHECK_THROW(EllipseBounds(-innerRx, -innerRy, outerRx, outerRy,
73  phiSector, averagePhi),
74  std::logic_error);
75  // Exception for opening outerRx <= 0
76  BOOST_CHECK_THROW(
77  EllipseBounds(innerRx, innerRy, 0., outerRy, phiSector, averagePhi),
78  std::logic_error);
79  // Exception for opening outerRy <= 0
80  BOOST_CHECK_THROW(
81  EllipseBounds(innerRx, innerRy, outerRx, 0., phiSector, averagePhi),
82  std::logic_error);
83  // Exception for iouterRx < 0 and outerRy < 0
84  BOOST_CHECK_THROW(EllipseBounds(innerRx, innerRy, -outerRx, -outerRy,
85  phiSector, averagePhi),
86  std::logic_error);
87  // Exception for innerRx > outerRx
88  BOOST_CHECK_THROW(
89  EllipseBounds(outerRx, innerRy, innerRx, outerRy, phiSector, averagePhi),
90  std::logic_error);
91  // Exception for innerRxy > outerRy
92  BOOST_CHECK_THROW(
93  EllipseBounds(innerRx, outerRy, outerRx, innerRy, phiSector, averagePhi),
94  std::logic_error);
95  // Exception for negative phiSector
96  BOOST_CHECK_THROW(
97  EllipseBounds(innerRx, innerRy, outerRx, outerRy, -phiSector, averagePhi),
98  std::logic_error);
99  // Exception for average phi out of bound
100  BOOST_CHECK_THROW(
101  EllipseBounds(innerRx, innerRy, outerRx, outerRy, phiSector, 4.),
102  std::logic_error);
103 }
104 
106 BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(CylinderBoundsProperties, 1)
107 BOOST_AUTO_TEST_CASE(EllipseBoundsProperties) {
108  double innerRx(10.), outerRx(15.), innerRy(15.), outerRy(20.), averagePhi(0.),
109  phiSector(M_PI / 2.);
111  EllipseBounds ellipseBoundsObject(innerRx, innerRy, outerRx, outerRy,
112  phiSector, averagePhi);
113  //
115  BOOST_CHECK_EQUAL(ellipseBoundsObject.type(), SurfaceBounds::eEllipse);
116  //
117  // clone already tested
118  //
120  Vector2D origin(0., 0.);
121  Vector2D outsideBy15(0., 30.);
122  Vector2D inRectangle(17., 11.);
123  CHECK_CLOSE_REL(ellipseBoundsObject.distanceToBoundary(origin), 10.,
124  1e-6); // makes sense
125  CHECK_CLOSE_REL(ellipseBoundsObject.distanceToBoundary(outsideBy15), 15.,
126  1e-6); // fails, not clear why
127  //
129  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRx), innerRx);
130  //
132  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRx), outerRx);
133  //
135  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRy), innerRy);
136  //
138  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRy), outerRy);
139  //
141  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eAveragePhi),
142  averagePhi);
143  //
145  // std::vector<Vector2D> expectedVertices{{15, 0}, {0, 20}, {-15, 0}, {0,
146  // -20}}; const auto& actualVertices = ellipseBoundsObject.vertices(4);
147  // BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(),
148  // actualVertices.cend(),
149  // expectedVertices.cbegin(),
150  // expectedVertices.cend());
151  //
153  BOOST_CHECK_EQUAL(ellipseBoundsObject.boundingBox(),
154  RectangleBounds(15., 20.));
155  //
157  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eHalfPhiSector),
158  M_PI / 2.);
159  //
161  boost::test_tools::output_test_stream dumpOuput;
162  ellipseBoundsObject.toStream(dumpOuput);
163  BOOST_CHECK(dumpOuput.is_equal(
164  "Acts::EllipseBounds: (innerRadius0, outerRadius0, innerRadius1, "
165  "outerRadius1, hPhiSector, averagePhi) = (10.0000000, 15.0000000, "
166  "15.0000000, "
167  "20.0000000, 0.0000000, 1.5707963, 0.0000000)"));
168  //
170  BOOST_CHECK(!ellipseBoundsObject.inside(inRectangle, BoundaryCheck(true)));
171  // dont understand why this is so:
172  BOOST_CHECK(!ellipseBoundsObject.inside(outsideBy15, BoundaryCheck(true)));
173 }
175 BOOST_AUTO_TEST_CASE(EllipseBoundsAssignment) {
176  double innerRx(10.), outerRx(15.), innerRy(15.), outerRy(20.), averagePhi(0.),
177  phiSector(M_PI / 2.);
178  EllipseBounds ellipseBoundsObject(innerRx, outerRx, innerRy, outerRy,
179  averagePhi, phiSector);
180  EllipseBounds similarlyConstructeEllipseBoundsObject(
181  innerRx, outerRx, innerRy, outerRy, averagePhi, phiSector);
183  BOOST_CHECK_EQUAL(ellipseBoundsObject,
184  similarlyConstructeEllipseBoundsObject);
185  //
187  EllipseBounds assignedEllipseBoundsObject(11., 12., 17., 18., 1.);
188  // object, in some sense
189  assignedEllipseBoundsObject = ellipseBoundsObject;
190  BOOST_CHECK_EQUAL(assignedEllipseBoundsObject, ellipseBoundsObject);
191 }
192 
193 BOOST_AUTO_TEST_SUITE_END()
194 
195 } // namespace Test
196 
197 } // namespace Acts