ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrapezoidBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrapezoidBoundsTests.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 utf = boost::unit_test;
20 
21 namespace Acts {
22 
23 namespace Test {
24 BOOST_AUTO_TEST_SUITE(Surfaces)
25 
26 
27 BOOST_AUTO_TEST_CASE(TrapezoidBoundsConstruction) {
28  double minHalfX(1.), maxHalfX(6.), halfY(2.);
29  //
30  // default construction deleted
31  // TrapezoidBounds defaultConstructedTrapezoidBounds;
32  //
34  BOOST_CHECK_EQUAL(TrapezoidBounds(minHalfX, maxHalfX, halfY).type(),
37  TrapezoidBounds original(minHalfX, maxHalfX, halfY);
38  TrapezoidBounds copied(original);
39  BOOST_CHECK_EQUAL(copied, original);
40 }
41 
43 BOOST_AUTO_TEST_CASE(TrapezoidBoundsRecreated) {
44  double minHalfX(1.), maxHalfX(6.), halfY(2.);
46  TrapezoidBounds original(minHalfX, maxHalfX, halfY);
47  // const bool symmetric(false);
48  auto valvector = original.values();
49  std::array<double, TrapezoidBounds::eSize> values;
50  std::copy_n(valvector.begin(), TrapezoidBounds::eSize, values.begin());
51  TrapezoidBounds recreated(values);
52  BOOST_CHECK_EQUAL(original, recreated);
53 }
54 
55 // Exception tests
56 BOOST_AUTO_TEST_CASE(TrapezoidBoundsException) {
57  double minHalfX(1.), maxHalfX(6.), halfY(2.);
58 
59  // Negative x at min y
60  BOOST_CHECK_THROW(TrapezoidBounds(-minHalfX, maxHalfX, halfY),
61  std::logic_error);
62 
63  // Negative x at max y
64  BOOST_CHECK_THROW(TrapezoidBounds(minHalfX, -maxHalfX, halfY),
65  std::logic_error);
66 
67  // Negative x at miny and max y
68  BOOST_CHECK_THROW(TrapezoidBounds(-minHalfX, -maxHalfX, halfY),
69  std::logic_error);
70 
71  // Negative y
72  BOOST_CHECK_THROW(TrapezoidBounds(minHalfX, maxHalfX, -halfY),
73  std::logic_error);
74 }
75 
77 BOOST_AUTO_TEST_CASE(TrapezoidBoundsProperties, *utf::expected_failures(3)) {
78  double minHalfX(1.), maxHalfX(6.), halfY(2.);
79  //
80  TrapezoidBounds trapezoidBoundsObject(minHalfX, maxHalfX, halfY);
81  //
83  BOOST_CHECK_EQUAL(trapezoidBoundsObject.type(), SurfaceBounds::eTrapezoid);
84  //
86  BOOST_CHECK_EQUAL(
87  trapezoidBoundsObject.get(TrapezoidBounds::eHalfLengthXnegY), minHalfX);
88  //
90  BOOST_CHECK_EQUAL(
91  trapezoidBoundsObject.get(TrapezoidBounds::eHalfLengthXposY), maxHalfX);
92  //
94  BOOST_CHECK_EQUAL(trapezoidBoundsObject.get(TrapezoidBounds::eHalfLengthY),
95  halfY);
96  //
98  Vector2D origin(0., 0.);
99  Vector2D outside(30., 0.);
100  Vector2D inRectangle(2., 0.5);
101  CHECK_CLOSE_REL(trapezoidBoundsObject.distanceToBoundary(origin), -2.,
102  1e-6); // makes sense
103  CHECK_CLOSE_REL(trapezoidBoundsObject.distanceToBoundary(outside),
104  std::hypot(2., 24.),
105  1e-6); // ok
106  //
108  std::vector<Vector2D> expectedVertices{
109  {1., -2.}, {6., 2.}, {-6., 2.}, {-1., -2.}};
110  const auto& actualVertices = trapezoidBoundsObject.vertices();
111  BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
112  expectedVertices.cbegin(),
113  expectedVertices.cend());
118  //
120  BOOST_CHECK_EQUAL(trapezoidBoundsObject.boundingBox(),
121  RectangleBounds(6., 2.));
122  //
123 
124  //
126  boost::test_tools::output_test_stream dumpOuput;
127  trapezoidBoundsObject.toStream(dumpOuput);
128  BOOST_CHECK(
129  dumpOuput.is_equal("Acts::TrapezoidBounds: (minHlengthX, maxHlengthX, "
130  "hlengthY) = (1.0000000, 6.0000000, 2.0000000)"));
131  //
133  BOOST_CHECK(trapezoidBoundsObject.inside(inRectangle, BoundaryCheck(true)));
134  BOOST_CHECK(!trapezoidBoundsObject.inside(outside, BoundaryCheck(true)));
135 }
137 BOOST_AUTO_TEST_CASE(TrapezoidBoundsAssignment) {
138  double minHalfX(1.), maxHalfX(6.), halfY(2.);
139  TrapezoidBounds trapezoidBoundsObject(minHalfX, maxHalfX, halfY);
140  // operator == not implemented in this class
141  //
143  TrapezoidBounds assignedTrapezoidBoundsObject(10., 20., 14.2);
144  assignedTrapezoidBoundsObject = trapezoidBoundsObject;
145  BOOST_CHECK_EQUAL(assignedTrapezoidBoundsObject, trapezoidBoundsObject);
146 }
147 
148 BOOST_AUTO_TEST_SUITE_END()
149 
150 } // namespace Test
151 
152 } // namespace Acts