Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-23 08:24:25

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/LineBounds.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 
0017 #include <algorithm>
0018 #include <array>
0019 #include <stdexcept>
0020 #include <vector>
0021 
0022 using namespace Acts;
0023 
0024 namespace ActsTests {
0025 
0026 BOOST_AUTO_TEST_SUITE(SurfacesSuite)
0027 /// Unit test for creating compliant/non-compliant LineBounds object
0028 BOOST_AUTO_TEST_CASE(LineBoundsConstruction) {
0029   const double radius = 0.5;
0030   const double halfZ = 10.;
0031 
0032   /// Test LineBounds(double, double)
0033   LineBounds lineBounds(radius, halfZ);
0034   BOOST_CHECK_EQUAL(lineBounds.type(), SurfaceBounds::eLine);
0035 
0036   /// Test copy construction;
0037   LineBounds copyConstructedLineBounds(lineBounds);  // implicit
0038   BOOST_CHECK_EQUAL(copyConstructedLineBounds.type(), SurfaceBounds::eLine);
0039 }
0040 
0041 /// Unit test for testing LineBounds recreation from streaming
0042 BOOST_AUTO_TEST_CASE(LineBoundsRecreation) {
0043   const double radius = 0.5;
0044   const double halfZ = 20.;  // != 10.
0045 
0046   LineBounds original(radius, halfZ);
0047   LineBounds recreated(original);
0048   auto valvector = original.values();
0049   std::array<double, LineBounds::eSize> values{};
0050   std::copy_n(valvector.begin(), LineBounds::eSize, values.begin());
0051   BOOST_CHECK_EQUAL(original, recreated);
0052 }
0053 
0054 /// Unit test for testing LineBounds exceptions
0055 BOOST_AUTO_TEST_CASE(LineBoundsExceptions) {
0056   const double radius = 0.5;
0057   const double halfZ = 20.;  // != 10.
0058 
0059   // Negative radius
0060   BOOST_CHECK_THROW(LineBounds(-radius, halfZ), std::logic_error);
0061 
0062   // Negative half length
0063   BOOST_CHECK_THROW(LineBounds(radius, -halfZ), std::logic_error);
0064 
0065   // Negative radius and half length
0066   BOOST_CHECK_THROW(LineBounds(-radius, -halfZ), std::logic_error);
0067 }
0068 
0069 /// Unit test for testing LineBounds assignment
0070 BOOST_AUTO_TEST_CASE(LineBoundsAssignment) {
0071   const double radius = 0.5;
0072   const double halfZ = 20.;  // != 10.
0073 
0074   LineBounds lineBoundsObject(radius, halfZ);
0075   LineBounds assignedLineBounds = lineBoundsObject;
0076   BOOST_CHECK_EQUAL(assignedLineBounds, lineBoundsObject);
0077 }
0078 
0079 /// Unit tests for LineBounds properties
0080 BOOST_AUTO_TEST_CASE(LineBoundsProperties) {
0081   const double radius = 0.5;
0082   const double halfZ = 20.;  // != 10.
0083 
0084   LineBounds lineBoundsObject(radius, halfZ);
0085 
0086   /// Test for type()
0087   BOOST_CHECK_EQUAL(lineBoundsObject.type(), SurfaceBounds::eLine);
0088 
0089   /// Test for inside()
0090   const Vector2 origin{0., 0.};
0091   const Vector2 atRadius{0.5, 10.};
0092   const Vector2 beyondEnd{0., 30.};
0093   const Vector2 unitZ{0., 1.};
0094   const Vector2 unitR{1., 0.};
0095   const BoundaryTolerance tolerance = BoundaryTolerance::AbsoluteEuclidean(0.1);
0096   // This fails because the bounds are not inclusive.
0097   BOOST_CHECK(!lineBoundsObject.inside(atRadius, tolerance));
0098   BOOST_CHECK(!lineBoundsObject.inside(beyondEnd, tolerance));
0099   BOOST_CHECK(lineBoundsObject.inside(unitZ, tolerance));
0100   BOOST_CHECK(!lineBoundsObject.inside(unitR, tolerance));
0101 
0102   /// Test negative radius inside
0103   BOOST_CHECK(lineBoundsObject.inside(Vector2{-0.2, 10}, tolerance));
0104   BOOST_CHECK(!lineBoundsObject.inside(Vector2{-0.8, 10}, tolerance));
0105 
0106   /// Test for r()
0107   BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eR), radius);
0108 
0109   /// Test for halfLengthZ
0110   BOOST_CHECK_EQUAL(lineBoundsObject.get(LineBounds::eHalfLengthZ), halfZ);
0111 
0112   /// Test for dump
0113   boost::test_tools::output_test_stream dumpOutput;
0114   lineBoundsObject.toStream(dumpOutput);
0115   BOOST_CHECK(dumpOutput.is_equal(
0116       "Acts::LineBounds: (radius, halflengthInZ) = (0.5000000, 20.0000000)"));
0117 }
0118 
0119 BOOST_AUTO_TEST_CASE(LineBoundsCenter) {
0120   const double radius = 2.5;
0121   const double halfZ = 15.0;
0122 
0123   LineBounds lineBounds(radius, halfZ);
0124   Vector2 center = lineBounds.center();
0125 
0126   // LineBounds should have centroid at origin since it's symmetric
0127   BOOST_CHECK_EQUAL(center.x(), 0.0);
0128   BOOST_CHECK_EQUAL(center.y(), 0.0);
0129 }
0130 
0131 BOOST_AUTO_TEST_SUITE_END()
0132 
0133 }  // namespace ActsTests