From a3f97465829eeda0432ccc4032b0eb1b3cd78750 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 5 Dec 2024 09:19:15 +0100 Subject: [PATCH] added Tests --- .../Acts/Visualization/Interpolation3D.hpp | 9 ++-- .../Core/Visualization/CMakeLists.txt | 1 + .../Visualization/Interpolation3DTests.cpp | 51 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Tests/UnitTests/Core/Visualization/Interpolation3DTests.cpp diff --git a/Core/include/Acts/Visualization/Interpolation3D.hpp b/Core/include/Acts/Visualization/Interpolation3D.hpp index 480dc5b0859..34f1aafde15 100644 --- a/Core/include/Acts/Visualization/Interpolation3D.hpp +++ b/Core/include/Acts/Visualization/Interpolation3D.hpp @@ -6,7 +6,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#pragma once + #include "Acts/Definitions/Algebra.hpp" + #include namespace Acts::Interpolation3D { @@ -20,8 +23,8 @@ namespace Acts::Interpolation3D { /// /// @return std::vector interpolated points template -std::vector spline( - const std::vector& inputs, std::size_t nPoints) { +std::vector spline(const std::vector& inputs, + std::size_t nPoints) { std::vector output; if (nPoints < 2) { @@ -47,4 +50,4 @@ std::vector spline( return output; } -} // namespace Acts::Interpolation3D \ No newline at end of file +} // namespace Acts::Interpolation3D diff --git a/Tests/UnitTests/Core/Visualization/CMakeLists.txt b/Tests/UnitTests/Core/Visualization/CMakeLists.txt index ca6768e876b..97d76217917 100644 --- a/Tests/UnitTests/Core/Visualization/CMakeLists.txt +++ b/Tests/UnitTests/Core/Visualization/CMakeLists.txt @@ -1,5 +1,6 @@ add_unittest(Visualization3D Visualization3DTests.cpp) add_unittest(EventDataView3D EventDataView3DTests.cpp) +add_unittest(Interpolation3D Interpolation3DTests.cpp) add_unittest(PrimitivesView3D PrimitivesView3DTests.cpp) add_unittest(SurfaceView3D SurfaceView3DTests.cpp) add_unittest(TrackingGeometryView3D TrackingGeometryView3DTests.cpp) diff --git a/Tests/UnitTests/Core/Visualization/Interpolation3DTests.cpp b/Tests/UnitTests/Core/Visualization/Interpolation3DTests.cpp new file mode 100644 index 00000000000..63c65ab3c66 --- /dev/null +++ b/Tests/UnitTests/Core/Visualization/Interpolation3DTests.cpp @@ -0,0 +1,51 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include +#include + +#include "Acts/Visualization/Interpolation3D.hpp" +#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" + +namespace Acts::Test { + +BOOST_AUTO_TEST_SUITE(Visualization) + +BOOST_AUTO_TEST_CASE(SplineInterpolation) { + + /// Define the input vector + double R = 10.; + std::vector inputs; + for (double phi = 0; phi < 2 * std::numbers::pi; phi += std::numbers::pi / 4) { + inputs.push_back(Acts::Vector3(R * cos(phi), R * sin(phi), 0.)); + } + + // Interpolate the points options + std::vector trajectory; + + // (0) - nothing happens + trajectory = Acts::Interpolation3D::spline(inputs, 1); + // Check input and output size are the same + BOOST_CHECK_EQUAL(trajectory.size(), inputs.size()); + + // (1) - interpolate between the points with 12 points in total + trajectory = Acts::Interpolation3D::spline(inputs, 12); + // Check the output size is correct + BOOST_CHECK_EQUAL(trajectory.size(), 12); + + for (const auto& point : trajectory) { + // Check the interpolated points are on the circle + // with a tolerance of course + CHECK_CLOSE_ABS(point.norm(), R, 0.1); + } + +} + +BOOST_AUTO_TEST_SUITE_END() + +} // namespace Acts::Test \ No newline at end of file