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 
16 
17 #include <limits>
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  //
125  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRx), innerRx);
126  //
128  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRx), outerRx);
129  //
131  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eInnerRy), innerRy);
132  //
134  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eOuterRy), outerRy);
135  //
137  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eAveragePhi),
138  averagePhi);
139  //
141  // std::vector<Vector2D> expectedVertices{{15, 0}, {0, 20}, {-15, 0}, {0,
142  // -20}}; const auto& actualVertices = ellipseBoundsObject.vertices(4);
143  // BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(),
144  // actualVertices.cend(),
145  // expectedVertices.cbegin(),
146  // expectedVertices.cend());
147  //
149  BOOST_CHECK_EQUAL(ellipseBoundsObject.boundingBox(),
150  RectangleBounds(15., 20.));
151  //
153  BOOST_CHECK_EQUAL(ellipseBoundsObject.get(EllipseBounds::eHalfPhiSector),
154  M_PI / 2.);
155  //
157  boost::test_tools::output_test_stream dumpOuput;
158  ellipseBoundsObject.toStream(dumpOuput);
159  BOOST_CHECK(dumpOuput.is_equal(
160  "Acts::EllipseBounds: (innerRadius0, outerRadius0, innerRadius1, "
161  "outerRadius1, hPhiSector, averagePhi) = (10.0000000, 15.0000000, "
162  "15.0000000, "
163  "20.0000000, 0.0000000, 1.5707963, 0.0000000)"));
164  //
166  BOOST_CHECK(!ellipseBoundsObject.inside(inRectangle, BoundaryCheck(true)));
167  // dont understand why this is so:
168  BOOST_CHECK(!ellipseBoundsObject.inside(outsideBy15, BoundaryCheck(true)));
169 }
171 BOOST_AUTO_TEST_CASE(EllipseBoundsAssignment) {
172  double innerRx(10.), outerRx(15.), innerRy(15.), outerRy(20.), averagePhi(0.),
173  phiSector(M_PI / 2.);
174  EllipseBounds ellipseBoundsObject(innerRx, outerRx, innerRy, outerRy,
175  averagePhi, phiSector);
176  EllipseBounds similarlyConstructeEllipseBoundsObject(
177  innerRx, outerRx, innerRy, outerRy, averagePhi, phiSector);
179  BOOST_CHECK_EQUAL(ellipseBoundsObject,
180  similarlyConstructeEllipseBoundsObject);
181  //
183  EllipseBounds assignedEllipseBoundsObject(11., 12., 17., 18., 1.);
184  // object, in some sense
185  assignedEllipseBoundsObject = ellipseBoundsObject;
186  BOOST_CHECK_EQUAL(assignedEllipseBoundsObject, ellipseBoundsObject);
187 }
188 
189 BOOST_AUTO_TEST_SUITE_END()
190 
191 } // namespace Test
192 
193 } // namespace Acts