Skip to content

Commit

Permalink
refactor: Move common test helpers to core (#2645)
Browse files Browse the repository at this point in the history
This PR moves MultiTrajectory test helpers to the Core package. Thanks to that we would be able to reuse them in ATLAS to setup the compatible test. Once changes in MTJ implemenation in ACTS change it would be reflected in the test and during integration of that change the shared test will indicate what exacly needs to be updated.

@paulgessinger @CarloVarni - since you two discussed that a bit @ workshop please let me know if this is the right direction. As you see I have left out thet TestTrackProxy and TestSourceLink in order minimize polution of Core package.
  • Loading branch information
tboldagh authored Dec 6, 2023
1 parent 0fe485d commit b533a87
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <random>
#include <utility>

namespace Acts {
namespace Test {
namespace Acts::detail::Test {

/// Generate a random parameters vector and covariance matrix.
///
Expand Down Expand Up @@ -77,5 +76,4 @@ inline auto generateFreeParametersCovariance(generator_t& rng) {
return generateParametersCovariance<ActsScalar, eFreeSize>(rng);
}

} // namespace Test
} // namespace Acts
} // namespace Acts::detail::Test
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/TrackStatePropMask.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/EventData/detail/TestTrackState.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/Tests/CommonHelpers/TestTrackState.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"
#include "Acts/Utilities/HashedString.hpp"

#include <random>

namespace Acts::Test {
namespace Acts::detail::Test {

template <typename factory_t>
class MultiTrajectoryTestsCommon {
Expand Down Expand Up @@ -376,7 +376,7 @@ class MultiTrajectoryTestsCommon {
BOOST_CHECK_EQUAL(
ts.getUncalibratedSourceLink().template get<TestSourceLink>().sourceId,
ttsb.sourceLink.sourceId);
auto m2 = std::get<Measurement<BoundIndices, 2u>>(meas);
auto m2 = std::get<Acts::Measurement<BoundIndices, 2u>>(meas);

BOOST_CHECK_EQUAL(ts.calibratedSize(), 2);
BOOST_CHECK_EQUAL(ts.effectiveCalibrated(), m2.parameters());
Expand Down Expand Up @@ -1065,4 +1065,4 @@ class MultiTrajectoryTestsCommon {
// runTest([](std::string_view c) { return c; });
}
};
} // namespace Acts::Test
} // namespace Acts::detail::Test
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#include <iosfwd>
#include <stdexcept>

namespace Acts {
namespace Test {
namespace Acts::detail::Test {

/// A minimal source link implementation for testing.
///
Expand Down Expand Up @@ -69,7 +68,24 @@ struct TestSourceLink final {
TestSourceLink(TestSourceLink&&) = default;
TestSourceLink& operator=(const TestSourceLink&) = default;
TestSourceLink& operator=(TestSourceLink&&) = default;

bool operator==(const TestSourceLink& rhs) const {
return (m_geometryId == rhs.m_geometryId) && (sourceId == rhs.sourceId) &&
(indices == rhs.indices) && (parameters == rhs.parameters) &&
(covariance == rhs.covariance);
}
bool operator!=(const TestSourceLink& rhs) const { return !(*this == rhs); }
std::ostream& print(std::ostream& os) const {
os << "TestsSourceLink(geometryId=" << m_geometryId
<< ",sourceId=" << sourceId;
if (indices[0] != eBoundSize) {
os << ",index0=" << indices[0];
}
if (indices[1] != eBoundSize) {
os << ",index1=" << indices[1];
}
os << ")";
return os;
}
constexpr std::size_t index() const { return sourceId; }

struct SurfaceAccessor {
Expand All @@ -82,9 +98,10 @@ struct TestSourceLink final {
};
};

bool operator==(const TestSourceLink& lhs, const TestSourceLink& rhs);
bool operator!=(const TestSourceLink& lhs, const TestSourceLink& rhs);
std::ostream& operator<<(std::ostream& os, const TestSourceLink& sourceLink);
inline std::ostream& operator<<(std::ostream& os,
const TestSourceLink& sourceLink) {
return sourceLink.print(os);
}

/// Extract the measurement from a TestSourceLink.
///
Expand Down Expand Up @@ -133,5 +150,4 @@ void testSourceLinkCalibrator(
trackState);
}

} // namespace Test
} // namespace Acts
} // namespace Acts::detail::Test
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/Tests/CommonHelpers/GenerateParameters.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/EventData/detail/GenerateParameters.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"

#include <random>

namespace Acts::Test {
namespace Acts::detail::Test {

struct TestTrackState {
std::shared_ptr<Surface> surface;
Expand Down Expand Up @@ -132,4 +132,4 @@ void fillTrackState(const TestTrackState& pc, TrackStatePropMask mask,
}
}

} // namespace Acts::Test
} // namespace Acts::detail::Test
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/Measurement.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryHierarchyMap.hpp"
#include "Acts/MagneticField/MagneticFieldContext.hpp"
#include "Acts/Propagator/AbortList.hpp"
#include "Acts/Propagator/ActionList.hpp"
#include "Acts/Propagator/StandardAborters.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <memory>
Expand Down Expand Up @@ -46,8 +46,8 @@ using MeasurementResolutionMap =

/// Result struct for generated measurements and outliers.
struct Measurements {
std::vector<TestSourceLink> sourceLinks;
std::vector<TestSourceLink> outlierSourceLinks;
std::vector<Acts::detail::Test::TestSourceLink> sourceLinks;
std::vector<Acts::detail::Test::TestSourceLink> outlierSourceLinks;
std::vector<BoundVector> truthParameters;
};

Expand Down
38 changes: 0 additions & 38 deletions Tests/CommonHelpers/Acts/Tests/CommonHelpers/TestSourceLink.cpp

This file was deleted.

13 changes: 7 additions & 6 deletions Tests/CommonHelpers/Acts/Tests/CommonHelpers/TestSpacePoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ class TestSpacePoint {
};

inline bool operator==(const TestSpacePoint& lhs, const TestSpacePoint& rhs) {
return (std::equal(lhs.sourceLinks().begin(), lhs.sourceLinks().end(),
rhs.sourceLinks().begin(),
[](const auto& lsl, const auto& rsl) {
return lsl.template get<TestSourceLink>() ==
rsl.template get<TestSourceLink>();
}) &&
return (std::equal(
lhs.sourceLinks().begin(), lhs.sourceLinks().end(),
rhs.sourceLinks().begin(),
[](const auto& lsl, const auto& rsl) {
return lsl.template get<Acts::detail::Test::TestSourceLink>() ==
rsl.template get<Acts::detail::Test::TestSourceLink>();
}) &&
lhs.x() == rhs.x()) &&
(lhs.y() == rhs.y()) && (lhs.z() == rhs.z()) &&
(lhs.varianceR() == rhs.varianceR()) &&
Expand Down
1 change: 0 additions & 1 deletion Tests/CommonHelpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../Data" acts_test_data_dir)
add_library(
ActsTestsCommonHelpers SHARED
Acts/Tests/CommonHelpers/DataDirectory.cpp
Acts/Tests/CommonHelpers/TestSourceLink.cpp
)
target_compile_definitions(
ActsTestsCommonHelpers
Expand Down
3 changes: 2 additions & 1 deletion Tests/UnitTests/Alignment/Kernel/AlignmentTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Geometry/CuboidVolumeBounds.hpp"
#include "Acts/Geometry/CuboidVolumeBuilder.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
Expand All @@ -34,7 +35,6 @@
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Tests/CommonHelpers/MeasurementsCreator.hpp"
#include "Acts/Tests/CommonHelpers/PredefinedMaterials.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/TrackFitting/GainMatrixSmoother.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
#include "Acts/TrackFitting/KalmanFitter.hpp"
Expand All @@ -50,6 +50,7 @@ namespace {
using namespace Acts;
using namespace ActsAlignment;
using namespace Acts::Test;
using namespace Acts::detail::Test;
using namespace Acts::UnitLiterals;

using StraightPropagator =
Expand Down
8 changes: 4 additions & 4 deletions Tests/UnitTests/Core/EventData/MeasurementTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/Measurement.hpp"
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/EventData/detail/GenerateParameters.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Tests/CommonHelpers/GenerateParameters.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"

#include <algorithm>
#include <array>
Expand All @@ -28,8 +28,8 @@
#include <vector>

using namespace Acts;
using namespace Acts::Test;
using SourceLink = Acts::Test::TestSourceLink;
using namespace Acts::detail::Test;
using SourceLink = Acts::detail::Test::TestSourceLink;
namespace bd = boost::unit_test::data;

namespace {
Expand Down
7 changes: 4 additions & 3 deletions Tests/UnitTests/Core/EventData/MultiTrajectoryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/TrackStatePropMask.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/detail/MultiTrajectoryTestsCommon.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/EventData/detail/TestTrackState.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Tests/CommonHelpers/MultiTrajectoryTestsCommon.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/Tests/CommonHelpers/TestTrackState.hpp"

#include <algorithm>
#include <array>
Expand All @@ -40,6 +40,7 @@ namespace {
using namespace Acts;
using namespace Acts::UnitLiterals;
using namespace Acts::Test;
using namespace Acts::detail::Test;
namespace bd = boost::unit_test::data;

using ParametersVector = BoundTrackParameters::ParametersVector;
Expand Down
17 changes: 17 additions & 0 deletions Tests/UnitTests/Core/EventData/SourceLinkTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,31 @@

#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"

#include <any>
#include <sstream>

using namespace Acts::UnitLiterals;

BOOST_AUTO_TEST_SUITE(EventDataSourceLink)

BOOST_AUTO_TEST_CASE(TestSourceLinkCoverage) {
using Acts::detail::Test::TestSourceLink;
TestSourceLink ts;
Acts::Vector2 stddev(0.01, 0.1);
Acts::SquareMatrix2 cov = stddev.cwiseProduct(stddev).asDiagonal();
TestSourceLink l1(Acts::eBoundLoc0, 0.1, cov(0, 0),
Acts::GeometryIdentifier(0x999), 0);
TestSourceLink l2(l1);

BOOST_CHECK(l1 == l2); // testing the ==
BOOST_CHECK(!(l1 != l2)); // testing the !=
std::ostringstream str;
str << l1;
}

struct MySourceLink {
Acts::GeometryIdentifier m_geometryId;

Expand Down
7 changes: 4 additions & 3 deletions Tests/UnitTests/Core/EventData/TrackTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include "Acts/EventData/TrackStatePropMask.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/EventData/detail/GenerateParameters.hpp"
#include "Acts/EventData/detail/TestTrackState.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Tests/CommonHelpers/GenerateParameters.hpp"
#include "Acts/Tests/CommonHelpers/TestTrackState.hpp"
#include "Acts/Utilities/HashedString.hpp"
#include "Acts/Utilities/Holders.hpp"
#include "Acts/Utilities/Zip.hpp"
Expand All @@ -45,7 +45,8 @@ using namespace Acts::UnitLiterals;

using namespace Acts;
using namespace Acts::HashedStringLiteral;
using namespace Acts::Test;
using namespace Acts::detail::Test;

using MultiTrajectoryTraits::IndexType;
namespace bd = boost::unit_test::data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/GenericCurvilinearTrackParameters.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/LayerCreator.hpp"
Expand All @@ -28,7 +29,7 @@
#include "Acts/Tests/CommonHelpers/CylindricalTrackingGeometry.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Tests/CommonHelpers/MeasurementsCreator.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"
#include "Acts/Utilities/Logger.hpp"

#include <algorithm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Acts/EventData/Measurement.hpp"
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/detail/TestSourceLink.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
Expand All @@ -32,7 +33,6 @@
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Tests/CommonHelpers/CubicTrackingGeometry.hpp"
#include "Acts/Tests/CommonHelpers/MeasurementsCreator.hpp"
#include "Acts/Tests/CommonHelpers/TestSourceLink.hpp"
#include "Acts/Tests/CommonHelpers/TestSpacePoint.hpp"

#include <algorithm>
Expand All @@ -53,7 +53,7 @@ namespace Test {
using namespace UnitLiterals;

using StraightPropagator = Propagator<StraightLineStepper, Navigator>;

using TestSourceLink = detail::Test::TestSourceLink;
using ConstantFieldStepper = EigenStepper<>;
using ConstantFieldPropagator = Propagator<ConstantFieldStepper, Navigator>;
// Construct initial track parameters.
Expand Down
Loading

0 comments on commit b533a87

Please sign in to comment.