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 
16 
17 #include <limits>
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 outside(30., 0.);
99  Vector2D inRectangle(2., 0.5);
100 
102  std::vector<Vector2D> expectedVertices{
103  {1., -2.}, {6., 2.}, {-6., 2.}, {-1., -2.}};
104  const auto& actualVertices = trapezoidBoundsObject.vertices();
105  BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
106  expectedVertices.cbegin(),
107  expectedVertices.cend());
112  //
114  BOOST_CHECK_EQUAL(trapezoidBoundsObject.boundingBox(),
115  RectangleBounds(6., 2.));
116  //
117 
118  //
120  boost::test_tools::output_test_stream dumpOuput;
121  trapezoidBoundsObject.toStream(dumpOuput);
122  BOOST_CHECK(
123  dumpOuput.is_equal("Acts::TrapezoidBounds: (minHlengthX, maxHlengthX, "
124  "hlengthY) = (1.0000000, 6.0000000, 2.0000000)"));
125  //
127  BOOST_CHECK(trapezoidBoundsObject.inside(inRectangle, BoundaryCheck(true)));
128  BOOST_CHECK(!trapezoidBoundsObject.inside(outside, BoundaryCheck(true)));
129 }
131 BOOST_AUTO_TEST_CASE(TrapezoidBoundsAssignment) {
132  double minHalfX(1.), maxHalfX(6.), halfY(2.);
133  TrapezoidBounds trapezoidBoundsObject(minHalfX, maxHalfX, halfY);
134  // operator == not implemented in this class
135  //
137  TrapezoidBounds assignedTrapezoidBoundsObject(10., 20., 14.2);
138  assignedTrapezoidBoundsObject = trapezoidBoundsObject;
139  BOOST_CHECK_EQUAL(assignedTrapezoidBoundsObject, trapezoidBoundsObject);
140 }
141 
142 BOOST_AUTO_TEST_SUITE_END()
143 
144 } // namespace Test
145 
146 } // namespace Acts