ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DiamondBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DiamondBoundsTests.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 
19 
20 namespace Acts {
21 
22 namespace Test {
23 BOOST_AUTO_TEST_SUITE(Surfaces)
25 BOOST_AUTO_TEST_CASE(DiamondBoundsConstruction) {
26  double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
27  // test default construction
28  // DiamondBounds defaultConstructedDiamondBounds; //deleted
29  //
31  // DiamondBounds d(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
32  BOOST_CHECK_EQUAL(
33  DiamondBounds(minHalfX, midHalfX, maxHalfX, halfY1, halfY2).type(),
35  //
37  DiamondBounds original(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
38  DiamondBounds copied(original);
39  BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiamond);
40 
41  // invalid inputs
42  BOOST_CHECK_THROW(
43  DiamondBounds db(midHalfX, minHalfX, maxHalfX, halfY1, halfY2),
44  std::logic_error);
45  BOOST_CHECK_THROW(
46  DiamondBounds db(minHalfX, maxHalfX, midHalfX, halfY1, halfY2),
47  std::logic_error);
48 }
50 BOOST_AUTO_TEST_CASE(DiamondBoundsProperties) {
51  double minHalfX(10.), midHalfX(50.), maxHalfX(30.), halfY1(10.), halfY2(20.);
53  DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
54  halfY2);
55  //
57  BOOST_CHECK_EQUAL(diamondBoundsObject.type(), SurfaceBounds::eDiamond);
58  // //redundant test
59  //
61  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXnegY),
62  minHalfX);
63  //
65  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXzeroY),
66  midHalfX);
67  //
69  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXposY),
70  maxHalfX);
71  //
73  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYneg),
74  halfY1);
75  //
77  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYpos),
78  halfY2);
79  //
81  BOOST_CHECK_EQUAL(diamondBoundsObject.boundingBox(),
82  RectangleBounds(Vector2D{-50., -10.}, Vector2D{50., 20.}));
83  //
84  // clone already tested
85  //
87  Vector2D origin(0., 0.);
88  Vector2D outsideBy10(0., 30.);
89  Vector2D inRectangle(15., 0.);
90  CHECK_CLOSE_REL(diamondBoundsObject.distanceToBoundary(origin), -10.,
91  1e-6); // makes sense
92  CHECK_CLOSE_REL(diamondBoundsObject.distanceToBoundary(outsideBy10), 10.,
93  1e-6); // ok
94  //
96  // Acts::DiamondBounds: (minHlengthX, medHlengthX, maxHlengthX, hlengthY1,
97  // hlengthY2 ) = (30.0000000, 10.0000000, 50.0000000, 10.0000000,
98  // 20.0000000)
99  diamondBoundsObject.toStream(std::cout);
100  boost::test_tools::output_test_stream dumpOuput;
101  diamondBoundsObject.toStream(dumpOuput);
102  BOOST_CHECK(
103  dumpOuput.is_equal("Acts::DiamondBounds: (halfXatYneg, halfXatYzero, "
104  "halfXatYpos, halfYneg, halfYpos) = (10.0000000, "
105  "50.0000000, 30.0000000, 10.0000000, 20.0000000)"));
106  //
108  BOOST_CHECK(diamondBoundsObject.inside(origin, BoundaryCheck(true)));
109  // dont understand why this is so:
110  BOOST_CHECK(!diamondBoundsObject.inside(outsideBy10, BoundaryCheck(true)));
111  //
113  // auto v=diamondBoundsObject.vertices();
114  std::vector<Vector2D> referenceVertices{
115  {-minHalfX, -halfY1}, {minHalfX, -halfY1}, {midHalfX, 0.},
116  {maxHalfX, halfY2}, {-maxHalfX, halfY2}, {-midHalfX, 0.}};
117  const auto& actualVertices = diamondBoundsObject.vertices();
118  BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
119  referenceVertices.cbegin(),
120  referenceVertices.cend());
121 }
123 BOOST_AUTO_TEST_CASE(DiamondBoundsAssignment) {
124  double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
125  DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
126  halfY2);
127  DiamondBounds similarlyConstructeDiamondBoundsObject(
128  minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
130  BOOST_CHECK_EQUAL(diamondBoundsObject,
131  similarlyConstructeDiamondBoundsObject);
132  //
134  DiamondBounds assignedDiamondBoundsObject(
135  2 * minHalfX, 2 * midHalfX, 2 * maxHalfX, 2 * halfY1, 2 * halfY2);
136  // object, in some sense
137  assignedDiamondBoundsObject = diamondBoundsObject;
138  BOOST_CHECK_EQUAL(assignedDiamondBoundsObject, diamondBoundsObject);
139 }
140 
141 BOOST_AUTO_TEST_SUITE_END()
142 
143 } // namespace Test
144 
145 } // namespace Acts