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 
17 
18 #include <limits>
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 
92  // Acts::DiamondBounds: (minHlengthX, medHlengthX, maxHlengthX, hlengthY1,
93  // hlengthY2 ) = (30.0000000, 10.0000000, 50.0000000, 10.0000000,
94  // 20.0000000)
95  diamondBoundsObject.toStream(std::cout);
96  boost::test_tools::output_test_stream dumpOuput;
97  diamondBoundsObject.toStream(dumpOuput);
98  BOOST_CHECK(
99  dumpOuput.is_equal("Acts::DiamondBounds: (halfXatYneg, halfXatYzero, "
100  "halfXatYpos, halfYneg, halfYpos) = (10.0000000, "
101  "50.0000000, 30.0000000, 10.0000000, 20.0000000)"));
102  //
104  BOOST_CHECK(diamondBoundsObject.inside(origin, BoundaryCheck(true)));
105  // dont understand why this is so:
106  BOOST_CHECK(!diamondBoundsObject.inside(outsideBy10, BoundaryCheck(true)));
107  //
109  // auto v=diamondBoundsObject.vertices();
110  std::vector<Vector2D> referenceVertices{
111  {-minHalfX, -halfY1}, {minHalfX, -halfY1}, {midHalfX, 0.},
112  {maxHalfX, halfY2}, {-maxHalfX, halfY2}, {-midHalfX, 0.}};
113  const auto& actualVertices = diamondBoundsObject.vertices();
114  BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
115  referenceVertices.cbegin(),
116  referenceVertices.cend());
117 }
119 BOOST_AUTO_TEST_CASE(DiamondBoundsAssignment) {
120  double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
121  DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
122  halfY2);
123  DiamondBounds similarlyConstructeDiamondBoundsObject(
124  minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
126  BOOST_CHECK_EQUAL(diamondBoundsObject,
127  similarlyConstructeDiamondBoundsObject);
128  //
130  DiamondBounds assignedDiamondBoundsObject(
131  2 * minHalfX, 2 * midHalfX, 2 * maxHalfX, 2 * halfY1, 2 * halfY2);
132  // object, in some sense
133  assignedDiamondBoundsObject = diamondBoundsObject;
134  BOOST_CHECK_EQUAL(assignedDiamondBoundsObject, diamondBoundsObject);
135 }
136 
137 BOOST_AUTO_TEST_SUITE_END()
138 
139 } // namespace Test
140 
141 } // namespace Acts