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