Skip to content

Commit

Permalink
update Surface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Oct 27, 2024
1 parent 27b719f commit 75401b9
Show file tree
Hide file tree
Showing 26 changed files with 501 additions and 461 deletions.
17 changes: 8 additions & 9 deletions Tests/UnitTests/Core/Surfaces/AnnulusBoundsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ namespace Acts::Test {

BOOST_AUTO_TEST_SUITE(Surfaces)

ActsScalar minRadius = 7.2;
ActsScalar maxRadius = 12.0;
ActsScalar minPhi = 0.74195;
ActsScalar maxPhi = 1.33970;
const ActsScalar minRadius = 7.2;
const ActsScalar maxRadius = 12.0;
const ActsScalar minPhi = 0.74195;
const ActsScalar maxPhi = 1.33970;

Vector2 offset(-2., 2.);
const Vector2 offset(-2., 2.);

// Unit tests for AnnulusBounds constructors
BOOST_AUTO_TEST_CASE(AnnulusBoundsConstruction) {
Expand Down Expand Up @@ -60,13 +60,13 @@ BOOST_AUTO_TEST_CASE(AnnulusBoundsExcpetion) {
// Exception for swapped radii
BOOST_CHECK_THROW(AnnulusBounds(maxRadius, minRadius, minPhi, maxPhi, offset),
std::logic_error);
// Exception for out of range min phi
// Exception for out of range min phi
BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, -4., maxPhi, offset),
std::logic_error);
// Exception for out of range max phi
// Exception for out of range max phi
BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, minPhi, 4., offset),
std::logic_error);
// Exception for out of range max phi
// Exception for out of range max phi
BOOST_CHECK_THROW(AnnulusBounds(minRadius, maxRadius, maxPhi, minPhi, offset),
std::logic_error);
}
Expand All @@ -76,7 +76,6 @@ BOOST_AUTO_TEST_CASE(AnnulusBoundsProperties) {
/// Test construction with radii and default sector
AnnulusBounds aBounds(minRadius, maxRadius, minPhi, maxPhi, offset);

//
/// Test type() (redundant; already used in constructor confirmation)
BOOST_CHECK_EQUAL(aBounds.type(), SurfaceBounds::eAnnulus);

Expand Down
7 changes: 3 additions & 4 deletions Tests/UnitTests/Core/Surfaces/BoundaryToleranceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <optional>
#include <vector>

#include "BoundaryToleranceTestsRefs.hpp"

namespace Acts::Test {

BOOST_AUTO_TEST_SUITE(Surfaces)
Expand All @@ -42,6 +40,7 @@ BOOST_AUTO_TEST_CASE(BoundaryCheckBoxSimple) {
BOOST_CHECK(
!detail::insideAlignedBox(ll, ur, tolerance, {2, 0}, std::nullopt));
}

// Aligned box w/ tolerance check along first axis
BOOST_AUTO_TEST_CASE(BoundaryCheckBoxToleranceLoc0) {
boost::execution_monitor em;
Expand Down Expand Up @@ -73,7 +72,7 @@ BOOST_AUTO_TEST_CASE(BoundaryCheckBoxCovariance) {
cov << 1, 0.5, 0.5, 2;
Vector2 ll(-1, -1);
Vector2 ur(1, 1);
auto tolerance = BoundaryTolerance::Chi2Bound(cov.inverse(), 3.0);
auto tolerance = BoundaryTolerance::Chi2Bound(cov.inverse(), 3.);
BOOST_CHECK(
detail::insideAlignedBox(ll, ur, tolerance, {0, 0}, std::nullopt));
BOOST_CHECK(
Expand Down Expand Up @@ -190,7 +189,7 @@ BOOST_AUTO_TEST_CASE(BoundaryCheckDifferentTolerances) {

{
auto tolerance =
BoundaryTolerance::Chi2Bound(SquareMatrix2::Identity(), 1.0);
BoundaryTolerance::Chi2Bound(SquareMatrix2::Identity(), 1.);
BOOST_CHECK(
detail::insideAlignedBox(ll, ur, tolerance, {0, 0}, std::nullopt));
BOOST_CHECK(
Expand Down
45 changes: 23 additions & 22 deletions Tests/UnitTests/Core/Surfaces/ConeBoundsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
// Note on nomenclature:
// - alpha = cone opening half angle
// - z is the axis of symmetry
// - zmin, zmax define limits for truncated cone
// - zMin, zMax define limits for truncated cone
// - phi is clock angle around cone, with x axis corresponding to phi=0
// - Cone segments may be defined with the avphi (central position of segment)
// and halfphi (extent in phi of cone segment either side of the avphi)
// - Cone segments may be defined with the averagePhi (central position of
// segment) and halfPhi (extent in phi of cone segment either side of the
// averagePhi)
// - Local coords are z, rphi

namespace Acts::Test {
Expand All @@ -41,10 +42,10 @@ const double halfPhi = std::numbers::pi / 4.;
const double averagePhi = 0.;
const bool symmetric = false;

// Unit test for creating compliant/non-compliant ConeBounds object
/// Unit test for creating compliant/non-compliant ConeBounds object
BOOST_AUTO_TEST_CASE(ConeBoundsConstruction) {
// test default construction
// ConeBounds defaultConstructedConeBounds; // deleted
/// Test default construction
// default construction is deleted

BOOST_TEST_CHECKPOINT("Four parameter constructor (last two at default)");
ConeBounds defaultConeBounds(alpha, symmetric);
Expand All @@ -69,7 +70,7 @@ BOOST_AUTO_TEST_CASE(ConeBoundsConstruction) {
BOOST_CHECK_EQUAL(copyConstructedConeBounds, fiveParamConstructedConeBounds);
}

// Streaning and recreation test
/// Streaning and recreation test
BOOST_AUTO_TEST_CASE(ConeBoundsRecreation) {
ConeBounds original(alpha, zMin, zMax, halfPhi, averagePhi);
auto valvector = original.values();
Expand All @@ -80,7 +81,7 @@ BOOST_AUTO_TEST_CASE(ConeBoundsRecreation) {
BOOST_CHECK_EQUAL(recreated, original);
}

// Unit tests for AnnulusBounds exception throwing
/// Unit tests for AnnulusBounds exception throwing
BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
// Exception for opening angle smaller 0
BOOST_CHECK_THROW(ConeBounds(-alpha, zMin, zMax, halfPhi, averagePhi),
Expand All @@ -99,47 +100,47 @@ BOOST_AUTO_TEST_CASE(ConeBoundsExceptions) {
BOOST_CHECK_THROW(ConeBounds(alpha, zMin, zMax, -halfPhi, averagePhi),
std::logic_error);

// Exception for out of range phi positioning
// Exception for out of range phi positioning
BOOST_CHECK_THROW(
ConeBounds(alpha, zMin, zMax, halfPhi, 2 * std::numbers::pi),
std::logic_error);
}

// Unit tests for properties of ConeBounds object
/// Unit tests for properties of ConeBounds object
BOOST_AUTO_TEST_CASE(ConeBoundsProperties) {
const Vector2 origin(0, 0);
const Vector2 somewhere(4., 4.);
ConeBounds coneBoundsObject(alpha, zMin, zMax, halfPhi, averagePhi);

// test for type (redundant)
/// Test for type (redundant)
BOOST_CHECK_EQUAL(coneBoundsObject.type(), SurfaceBounds::eCone);

// test for inside
/// Test for inside
BOOST_CHECK(!coneBoundsObject.inside(origin));

// test for r
/// Test for r
CHECK_CLOSE_REL(coneBoundsObject.r(zMin), zMin * std::tan(alpha), 1e-6);

// test for tanAlpha
/// Test for tanAlpha
CHECK_CLOSE_REL(coneBoundsObject.tanAlpha(), std::tan(alpha), 1e-6);

// test for alpha
/// Test for alpha
CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eAlpha), alpha, 1e-6);

// test for minZ
/// Test for minZ
CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMinZ), zMin, 1e-6);

// test for maxZ
/// Test for maxZ
CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eMaxZ), zMax, 1e-6);

// test for averagePhi
/// Test for averagePhi
CHECK_CLOSE_REL(coneBoundsObject.get(ConeBounds::eHalfPhiSector), halfPhi,
1e-6);

// test for dump
boost::test_tools::output_test_stream dumpOuput;
coneBoundsObject.toStream(dumpOuput);
BOOST_CHECK(dumpOuput.is_equal(
/// Test for dump
boost::test_tools::output_test_stream dumpOutput;
coneBoundsObject.toStream(dumpOutput);
BOOST_CHECK(dumpOutput.is_equal(
"Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, averagePhi) = "
"(0.4142136, 3.0000000, 6.0000000, 0.7853982, 0.0000000)"));
}
Expand Down
52 changes: 25 additions & 27 deletions Tests/UnitTests/Core/Surfaces/ConeSurfaceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include <boost/test/data/test_case.hpp>
#include <boost/test/tools/output_test_stream.hpp>
#include <boost/test/unit_test.hpp>

#include "Acts/Definitions/Algebra.hpp"
Expand Down Expand Up @@ -37,9 +38,10 @@ BOOST_AUTO_TEST_SUITE(ConeSurfaces)

/// Unit test for creating compliant/non-compliant ConeSurface object
BOOST_AUTO_TEST_CASE(ConeSurfaceConstruction) {
// ConeSurface default constructor is deleted
//
// Constructor with transform, alpha and symmetry indicator
/// Test default construction
// default construction is deleted

/// Constructor with transform, alpha and symmetry indicator
const double alpha = std::numbers::pi / 8.;
const double halfPhiSector = std::numbers::pi / 16.;
const double zMin = 1.;
Expand All @@ -56,34 +58,32 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceConstruction) {
Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric)->type(),
Surface::Cone);

// Constructor with transform pointer, alpha,z min and max, halfPhiSector
/// Constructor with transform pointer, alpha,z min and max, halfPhiSector
BOOST_CHECK_EQUAL(Surface::makeShared<ConeSurface>(pTransform, alpha, zMin,
zMax, halfPhiSector)
->type(),
Surface::Cone);

// Constructor with transform and ConeBounds pointer
// ConeBounds (double alpha, double zmin, double zmax, double
// halfphi=std::numbers::pi, double avphi=0.)
/// Constructor with transform and ConeBounds pointer
auto pConeBounds =
std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
BOOST_CHECK_EQUAL(
Surface::makeShared<ConeSurface>(pTransform, pConeBounds)->type(),
Surface::Cone);

// Copy constructor
/// Copy constructor
auto coneSurfaceObject =
Surface::makeShared<ConeSurface>(pTransform, alpha, symmetric);
auto copiedConeSurface = Surface::makeShared<ConeSurface>(*coneSurfaceObject);
BOOST_CHECK_EQUAL(copiedConeSurface->type(), Surface::Cone);
BOOST_CHECK(*copiedConeSurface == *coneSurfaceObject);

// Copied and transformed
/// Copied and transformed
auto copiedTransformedConeSurface = Surface::makeShared<ConeSurface>(
tgContext, *coneSurfaceObject, pTransform);
BOOST_CHECK_EQUAL(copiedTransformedConeSurface->type(), Surface::Cone);

// Construct with nullptr bounds
/// Construct with nullptr bounds
BOOST_CHECK_THROW(auto nullBounds = Surface::makeShared<ConeSurface>(
Transform3::Identity(), nullptr),
AssertionFailureException);
Expand All @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
binningPosition, 1e-6);

/// Test referenceFrame
Vector3 globalPosition{2.0, 2.0, 2.0};
Vector3 globalPosition{2., 2., 2.};
Vector3 momentum{1.e6, 1.e6, 1.e6};
double rootHalf = std::sqrt(0.5);
RotationMatrix3 expectedFrame;
Expand Down Expand Up @@ -143,7 +143,6 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
Vector2 localPosition{1., std::numbers::pi / 2.};
globalPosition =
coneSurfaceObject->localToGlobal(tgContext, localPosition, momentum);
// std::cout<<globalPosition<<std::endl;
Vector3 expectedPosition{0.0220268, 1.65027, 3.5708};

CHECK_CLOSE_REL(globalPosition, expectedPosition, 1e-2);
Expand All @@ -152,7 +151,6 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
localPosition =
coneSurfaceObject->globalToLocal(tgContext, globalPosition, momentum)
.value();
// std::cout<<localPosition<<std::endl;
Vector2 expectedLocalPosition{1., std::numbers::pi / 2.};

CHECK_CLOSE_REL(localPosition, expectedLocalPosition, 1e-6);
Expand All @@ -174,18 +172,18 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceProperties) {
std::string("Acts::ConeSurface"));

/// Test dump
// TODO 2017-04-12 msmk: check how to correctly check output
// boost::test_tools::output_test_stream dumpOuput;
// coneSurfaceObject.toStream(dumpOuput);
// BOOST_CHECK(dumpOuput.is_equal(
// "Acts::ConeSurface\n"
// " Center position (x, y, z) = (0.0000, 1.0000, 2.0000)\n"
// " Rotation: colX = (1.000000, 0.000000, 0.000000)\n"
// " colY = (0.000000, 1.000000, 0.000000)\n"
// " colZ = (0.000000, 0.000000, 1.000000)\n"
// " Bounds : Acts::ConeBounds: (tanAlpha, minZ, maxZ, averagePhi,
// halfPhiSector) = (0.4142136, 0.0000000, inf, 0.0000000,
// 3.1415927)"));
boost::test_tools::output_test_stream dumpOutput;
dumpOutput << coneSurfaceObject->toStream(tgContext);
BOOST_CHECK(dumpOutput.is_equal(
"Acts::ConeSurface\n"
" Center position (x, y, z) = (0.0000, 1.0000, 2.0000)\n"
" Rotation: colX = (1.000000, 0.000000, 0.000000)\n"
" colY = (0.000000, 1.000000, 0.000000)\n"
" colZ = (0.000000, 0.000000, 1.000000)\n"
" Bounds : Acts::ConeBounds: (tanAlpha, minZ, maxZ, halfPhiSector, "
"averagePhi) = (0.4142136, 0.0000000, inf, 3.1415927, 0.0000000)"

));
}

BOOST_AUTO_TEST_CASE(ConeSurfaceEqualityOperators) {
Expand Down Expand Up @@ -220,7 +218,7 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceExtent) {
const double zMax = 10.;
const Translation3 translation{0., 0., 0.}; // != {0., 1., 2.}

// Testing a Full cone
/// Testing a Full cone
auto pTransform = Transform3(translation);
auto pConeBounds = std::make_shared<const ConeBounds>(alpha, zMin, zMax);
auto pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
Expand All @@ -244,7 +242,7 @@ BOOST_AUTO_TEST_CASE(ConeSurfaceExtent) {
CHECK_CLOSE_ABS(rMax, pConeExtent.max(BinningValue::binY),
s_onSurfaceTolerance);

// Now a sector
/// Now a sector
pConeBounds =
std::make_shared<const ConeBounds>(alpha, zMin, zMax, halfPhiSector, 0.);
pCone = Surface::makeShared<ConeSurface>(pTransform, pConeBounds);
Expand Down
Loading

0 comments on commit 75401b9

Please sign in to comment.