Back to home page

EIC code displayed by LXR

 
 

    


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

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/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0013 #include "Acts/Surfaces/SurfaceBounds.hpp"
0014 
0015 #include <cstddef>
0016 #include <numeric>
0017 #include <ostream>
0018 #include <vector>
0019 
0020 namespace Acts {
0021 
0022 /// Class to implement pure virtual method of SurfaceBounds for testing only
0023 class SurfaceBoundsStub : public SurfaceBounds {
0024  public:
0025   /// Implement ctor and pure virtual methods of SurfaceBounds
0026   explicit SurfaceBoundsStub(std::size_t nValues = 0) : m_values(nValues, 0) {
0027     std::iota(m_values.begin(), m_values.end(), 0);
0028   }
0029 
0030 #if defined(__GNUC__) && (__GNUC__ == 13 || __GNUC__ == 14) && \
0031     !defined(__clang__)
0032 #pragma GCC diagnostic push
0033 #pragma GCC diagnostic ignored "-Warray-bounds"
0034 #pragma GCC diagnostic ignored "-Wstringop-overflow"
0035 #endif
0036   SurfaceBoundsStub(const SurfaceBoundsStub& other) = default;
0037 #if defined(__GNUC__) && (__GNUC__ == 13 || __GNUC__ == 14) && \
0038     !defined(__clang__)
0039 #pragma GCC diagnostic pop
0040 #endif
0041 
0042   ~SurfaceBoundsStub() override = default;
0043   BoundsType type() const final { return SurfaceBounds::eOther; }
0044   std::vector<double> values() const override { return m_values; }
0045   bool inside(const Vector2& /*lpos*/,
0046               const BoundaryTolerance& /*boundaryTolerance*/) const final {
0047     return true;
0048   }
0049 
0050   std::ostream& toStream(std::ostream& sl) const final {
0051     sl << "SurfaceBoundsStub";
0052     return sl;
0053   }
0054 
0055  private:
0056   std::vector<double> m_values;
0057 };
0058 
0059 }  // namespace Acts
0060 
0061 namespace Acts::Test {
0062 
0063 BOOST_AUTO_TEST_SUITE(Surfaces)
0064 
0065 /// Unit test for creating compliant/non-compliant SurfaceBounds object
0066 BOOST_AUTO_TEST_CASE(SurfaceBoundsConstruction) {
0067   SurfaceBoundsStub u;
0068   SurfaceBoundsStub s(1);  // would act as std::size_t cast to SurfaceBounds
0069   SurfaceBoundsStub t(s);
0070   SurfaceBoundsStub v(u);
0071 }
0072 
0073 BOOST_AUTO_TEST_CASE(SurfaceBoundsProperties) {
0074   SurfaceBoundsStub surface(5);
0075   std::vector<double> reference{0, 1, 2, 3, 4};
0076   const auto& boundValues = surface.values();
0077   BOOST_CHECK_EQUAL_COLLECTIONS(reference.cbegin(), reference.cend(),
0078                                 boundValues.cbegin(), boundValues.cend());
0079 }
0080 
0081 /// Unit test for testing SurfaceBounds properties
0082 BOOST_AUTO_TEST_CASE(SurfaceBoundsEquality) {
0083   SurfaceBoundsStub surface(1);
0084   SurfaceBoundsStub copiedSurface(surface);
0085   SurfaceBoundsStub differentSurface(2);
0086   BOOST_CHECK_EQUAL(surface, copiedSurface);
0087   BOOST_CHECK_NE(surface, differentSurface);
0088 
0089   SurfaceBoundsStub assignedSurface;
0090   assignedSurface = surface;
0091   BOOST_CHECK_EQUAL(surface, assignedSurface);
0092 
0093   const auto& surfaceboundValues = surface.values();
0094   const auto& assignedboundValues = assignedSurface.values();
0095   BOOST_CHECK_EQUAL_COLLECTIONS(
0096       surfaceboundValues.cbegin(), surfaceboundValues.cend(),
0097       assignedboundValues.cbegin(), assignedboundValues.cend());
0098 }
0099 
0100 BOOST_AUTO_TEST_SUITE_END()
0101 
0102 }  // namespace Acts::Test