Analysis Software
Documentation for sPHENIX simulation 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 
18 
19 #include <iostream>
20 #include <stdexcept>
21 #include <vector>
22 
23 namespace Acts {
24 
25 namespace Test {
26 BOOST_AUTO_TEST_SUITE(Surfaces)
28 BOOST_AUTO_TEST_CASE(DiamondBoundsConstruction) {
29  double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
30  // test default construction
31  // DiamondBounds defaultConstructedDiamondBounds; //deleted
32  //
34  // DiamondBounds d(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
35  BOOST_CHECK_EQUAL(
36  DiamondBounds(minHalfX, midHalfX, maxHalfX, halfY1, halfY2).type(),
38  //
40  DiamondBounds original(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
41  DiamondBounds copied(original);
42  BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiamond);
43 
44  // invalid inputs
45  BOOST_CHECK_THROW(
46  DiamondBounds db(midHalfX, minHalfX, maxHalfX, halfY1, halfY2),
47  std::logic_error);
48  BOOST_CHECK_THROW(
49  DiamondBounds db(minHalfX, maxHalfX, midHalfX, halfY1, halfY2),
50  std::logic_error);
51 }
53 BOOST_AUTO_TEST_CASE(DiamondBoundsProperties) {
54  double minHalfX(10.), midHalfX(50.), maxHalfX(30.), halfY1(10.), halfY2(20.);
56  DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
57  halfY2);
58  //
60  BOOST_CHECK_EQUAL(diamondBoundsObject.type(), SurfaceBounds::eDiamond);
61  // //redundant test
62  //
64  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXnegY),
65  minHalfX);
66  //
68  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXzeroY),
69  midHalfX);
70  //
72  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXposY),
73  maxHalfX);
74  //
76  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYneg),
77  halfY1);
78  //
80  BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYpos),
81  halfY2);
82  //
84  BOOST_CHECK_EQUAL(diamondBoundsObject.boundingBox(),
85  RectangleBounds(Vector2{-50., -10.}, Vector2{50., 20.}));
86  //
87  // clone already tested
88  //
90  Vector2 origin(0., 0.);
91  Vector2 outsideBy10(0., 30.);
92  Vector2 inRectangle(15., 0.);
93 
95  // Acts::DiamondBounds: (minHlengthX, medHlengthX, maxHlengthX, hlengthY1,
96  // hlengthY2 ) = (30.0000000, 10.0000000, 50.0000000, 10.0000000,
97  // 20.0000000)
98  diamondBoundsObject.toStream(std::cout);
99  boost::test_tools::output_test_stream dumpOuput;
100  diamondBoundsObject.toStream(dumpOuput);
101  BOOST_CHECK(
102  dumpOuput.is_equal("Acts::DiamondBounds: (halfXatYneg, halfXatYzero, "
103  "halfXatYpos, halfYneg, halfYpos) = (10.0000000, "
104  "50.0000000, 30.0000000, 10.0000000, 20.0000000)"));
105  //
107  BOOST_CHECK(diamondBoundsObject.inside(origin, BoundaryCheck(true)));
108  // dont understand why this is so:
109  BOOST_CHECK(!diamondBoundsObject.inside(outsideBy10, BoundaryCheck(true)));
110  //
112  // auto v=diamondBoundsObject.vertices();
113  std::vector<Vector2> referenceVertices{
114  {-minHalfX, -halfY1}, {minHalfX, -halfY1}, {midHalfX, 0.},
115  {maxHalfX, halfY2}, {-maxHalfX, halfY2}, {-midHalfX, 0.}};
116  const auto& actualVertices = diamondBoundsObject.vertices();
117  BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
118  referenceVertices.cbegin(),
119  referenceVertices.cend());
120 }
122 BOOST_AUTO_TEST_CASE(DiamondBoundsAssignment) {
123  double minHalfX(10.), midHalfX(20.), maxHalfX(15.), halfY1(5.), halfY2(7.);
124  DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
125  halfY2);
126  DiamondBounds similarlyConstructeDiamondBoundsObject(
127  minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
129  BOOST_CHECK_EQUAL(diamondBoundsObject,
130  similarlyConstructeDiamondBoundsObject);
131  //
133  DiamondBounds assignedDiamondBoundsObject(
134  2 * minHalfX, 2 * midHalfX, 2 * maxHalfX, 2 * halfY1, 2 * halfY2);
135  // object, in some sense
136  assignedDiamondBoundsObject = diamondBoundsObject;
137  BOOST_CHECK_EQUAL(assignedDiamondBoundsObject, diamondBoundsObject);
138 }
139 
140 BOOST_AUTO_TEST_SUITE_END()
141 
142 } // namespace Test
143 
144 } // namespace Acts