Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:51

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/tools/output_test_stream.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/DiamondBounds.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 
0018 #include <iostream>
0019 #include <stdexcept>
0020 #include <vector>
0021 
0022 namespace Acts::Test {
0023 
0024 BOOST_AUTO_TEST_SUITE(Surfaces)
0025 /// Unit test for creating compliant/non-compliant DiamondBounds object
0026 BOOST_AUTO_TEST_CASE(DiamondBoundsConstruction) {
0027   /// Test default construction
0028   // default construction is deleted
0029 
0030   const double minHalfX = 10.;
0031   const double midHalfX = 20.;
0032   const double maxHalfX = 15.;
0033   const double halfY1 = 5.;
0034   const double halfY2 = 7.;
0035 
0036   /// Test construction with dimensions
0037   BOOST_CHECK_EQUAL(
0038       DiamondBounds(minHalfX, midHalfX, maxHalfX, halfY1, halfY2).type(),
0039       SurfaceBounds::eDiamond);
0040 
0041   /// Copy constructor
0042   DiamondBounds original(minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0043   DiamondBounds copied(original);
0044   BOOST_CHECK_EQUAL(copied.type(), SurfaceBounds::eDiamond);
0045 
0046   /// Test invalid inputs
0047   BOOST_CHECK_THROW(
0048       DiamondBounds db(midHalfX, minHalfX, maxHalfX, halfY1, halfY2),
0049       std::logic_error);
0050   BOOST_CHECK_THROW(
0051       DiamondBounds db(minHalfX, maxHalfX, midHalfX, halfY1, halfY2),
0052       std::logic_error);
0053 }
0054 
0055 /// Unit tests for DiamondBounds properties
0056 BOOST_AUTO_TEST_CASE(DiamondBoundsProperties) {
0057   const double minHalfX = 10.;
0058   const double midHalfX = 50.;  // != 20.
0059   const double maxHalfX = 30.;  // != 15.
0060   const double halfY1 = 10.;    // != 5.
0061   const double halfY2 = 20.;    // != 7.
0062 
0063   /// Test clone
0064   DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
0065                                     halfY2);
0066 
0067   /// Test type() (redundant; already used in constructor confirmation)
0068   BOOST_CHECK_EQUAL(diamondBoundsObject.type(), SurfaceBounds::eDiamond);
0069 
0070   /// Test the half length at negative y
0071   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXnegY),
0072                     minHalfX);
0073 
0074   /// Test the half length at the x axis
0075   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXzeroY),
0076                     midHalfX);
0077 
0078   /// Test the half length at positive y
0079   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthXposY),
0080                     maxHalfX);
0081 
0082   /// Test half length into the negative side
0083   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYneg),
0084                     halfY1);
0085 
0086   /// Test half length into the positive side
0087   BOOST_CHECK_EQUAL(diamondBoundsObject.get(DiamondBounds::eHalfLengthYpos),
0088                     halfY2);
0089 
0090   /// Test boundingBox
0091   BOOST_CHECK_EQUAL(diamondBoundsObject.boundingBox(),
0092                     RectangleBounds(Vector2{-50., -10.}, Vector2{50., 20.}));
0093 
0094   /// Test distanceToBoundary
0095   Vector2 origin(0., 0.);
0096   Vector2 outsideBy10(0., 30.);
0097   Vector2 inRectangle(15., 0.);
0098 
0099   /// Test dump
0100   diamondBoundsObject.toStream(std::cout);
0101   boost::test_tools::output_test_stream dumpOutput;
0102   diamondBoundsObject.toStream(dumpOutput);
0103   BOOST_CHECK(
0104       dumpOutput.is_equal("Acts::DiamondBounds: (halfXatYneg, halfXatYzero, "
0105                           "halfXatYpos, halfYneg, halfYpos) = (10.0000000, "
0106                           "50.0000000, 30.0000000, 10.0000000, 20.0000000)"));
0107 
0108   /// Test inside
0109   BOOST_CHECK(diamondBoundsObject.inside(origin, BoundaryTolerance::None()));
0110   // dont understand why this is so:
0111   BOOST_CHECK(
0112       !diamondBoundsObject.inside(outsideBy10, BoundaryTolerance::None()));
0113 
0114   /// Test vertices (does this need to be implemented in this class??
0115   // auto v=diamondBoundsObject.vertices();
0116   std::vector<Vector2> referenceVertices{
0117       {-minHalfX, -halfY1}, {minHalfX, -halfY1}, {midHalfX, 0.},
0118       {maxHalfX, halfY2},   {-maxHalfX, halfY2}, {-midHalfX, 0.}};
0119   const auto& actualVertices = diamondBoundsObject.vertices();
0120   BOOST_CHECK_EQUAL_COLLECTIONS(actualVertices.cbegin(), actualVertices.cend(),
0121                                 referenceVertices.cbegin(),
0122                                 referenceVertices.cend());
0123 }
0124 
0125 /// Unit test for testing DiamondBounds assignment
0126 BOOST_AUTO_TEST_CASE(DiamondBoundsAssignment) {
0127   const double minHalfX = 10.;
0128   const double midHalfX = 20.;
0129   const double maxHalfX = 15.;
0130   const double halfY1 = 5.;
0131   const double halfY2 = 7.;
0132 
0133   DiamondBounds diamondBoundsObject(minHalfX, midHalfX, maxHalfX, halfY1,
0134                                     halfY2);
0135   DiamondBounds similarlyConstructeDiamondBoundsObject(
0136       minHalfX, midHalfX, maxHalfX, halfY1, halfY2);
0137 
0138   /// Test operator ==
0139   BOOST_CHECK_EQUAL(diamondBoundsObject,
0140                     similarlyConstructeDiamondBoundsObject);
0141 
0142   /// Test assignment
0143   DiamondBounds assignedDiamondBoundsObject(
0144       2 * minHalfX, 2 * midHalfX, 2 * maxHalfX, 2 * halfY1, 2 * halfY2);
0145 
0146   // object, in some sense
0147   assignedDiamondBoundsObject = diamondBoundsObject;
0148   BOOST_CHECK_EQUAL(assignedDiamondBoundsObject, diamondBoundsObject);
0149 }
0150 
0151 BOOST_AUTO_TEST_SUITE_END()
0152 
0153 }  // namespace Acts::Test