Skip to content

Commit

Permalink
CI job to check for BOOST_TEST macro usage (acts-project#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger authored Jul 29, 2020
1 parent 408d496 commit 049006c
Show file tree
Hide file tree
Showing 57 changed files with 1,239 additions and 1,161 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ jobs:
- name: Check
run: >
CI/check_include_guards.py . --fail-global --exclude "*thirdparty/*"
boost_test_macro:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check
run: >
CI/check_boost_test_macro.sh
14 changes: 14 additions & 0 deletions CI/check_boost_test_macro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

test_string="BOOST_TEST("
grep $test_string -n -r Tests --include "*.cpp" --include "*.hpp" --include "*.ipp"

status=$?

if [[ $status -eq 0 ]]; then
echo "Found occurrences of '$test_string'"
exit 1
else
echo "Did not find occurrences of '$test_string'"
exit 0
fi
24 changes: 24 additions & 0 deletions Tests/CommonHelpers/Acts/Tests/CommonHelpers/Assertions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is part of the Acts project.
//
// Copyright (C) 2020 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 http://mozilla.org/MPL/2.0/.

#pragma once

#include <boost/test/unit_test.hpp>

#include <vector>

#define CHECK_NE_COLLECTIONS(col1, col2) \
do { \
BOOST_CHECK_EQUAL(col1.size(), col2.size()); \
std::vector<bool> result; \
for (size_t i = 0; i < col1.size(); i++) { \
result.push_back(col1[i] == col2[i]); \
} \
BOOST_CHECK(not std::all_of(result.begin(), result.end(), \
[](bool r) { return r; })); \
} while (0)
36 changes: 18 additions & 18 deletions Tests/IntegrationTests/Fatras/FatrasSimulationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,35 @@ BOOST_DATA_TEST_CASE(FatrasSimulation, dataset, pdg, phi, eta, p,
input.push_back(std::move(particle));
}
BOOST_TEST_INFO(input.front());
BOOST_TEST(input.size() == numParticles);
BOOST_CHECK_EQUAL(input.size(), numParticles);

// run the simulation
auto result = simulator.simulate(geoCtx, magCtx, generator, input,
simulatedInitial, simulatedFinal, hits);

// should always succeed
BOOST_TEST(result.ok());
BOOST_CHECK(result.ok());

// ensure simulated particle containers have consistent content
BOOST_TEST(simulatedInitial.size() == simulatedFinal.size());
BOOST_CHECK_EQUAL(simulatedInitial.size(), simulatedFinal.size());
for (std::size_t i = 0; i < simulatedInitial.size(); ++i) {
const auto& initialParticle = simulatedInitial[i];
const auto& finalParticle = simulatedFinal[i];
// particle identify should not change during simulation
BOOST_TEST(initialParticle.particleId() == finalParticle.particleId());
BOOST_TEST(initialParticle.process() == finalParticle.process());
BOOST_TEST(initialParticle.pdg() == finalParticle.pdg());
BOOST_TEST(initialParticle.charge() == finalParticle.charge());
BOOST_TEST(initialParticle.mass() == finalParticle.mass());
BOOST_CHECK_EQUAL(initialParticle.particleId(), finalParticle.particleId());
BOOST_CHECK_EQUAL(initialParticle.process(), finalParticle.process());
BOOST_CHECK_EQUAL(initialParticle.pdg(), finalParticle.pdg());
BOOST_CHECK_EQUAL(initialParticle.charge(), finalParticle.charge());
BOOST_CHECK_EQUAL(initialParticle.mass(), finalParticle.mass());
}

// we have no particle cuts and should not loose any particles.
// might end up with more due to secondaries
BOOST_TEST(input.size() <= simulatedInitial.size());
BOOST_TEST(input.size() <= simulatedFinal.size());
BOOST_CHECK_LE(input.size(), simulatedInitial.size());
BOOST_CHECK_LE(input.size(), simulatedFinal.size());
// there should be some hits if we started with a charged particle
if (ActsFatras::findCharge(pdg) != 0) {
BOOST_TEST(0u < hits.size());
BOOST_CHECK_LT(0u, hits.size());
}

// sort all outputs by particle id to simply further tests
Expand All @@ -223,18 +223,18 @@ BOOST_DATA_TEST_CASE(FatrasSimulation, dataset, pdg, phi, eta, p,
sortByParticleId(hits);

// check that all particle ids are unique
BOOST_TEST(areParticleIdsUnique(input));
BOOST_TEST(areParticleIdsUnique(simulatedInitial));
BOOST_TEST(areParticleIdsUnique(simulatedFinal));
BOOST_CHECK(areParticleIdsUnique(input));
BOOST_CHECK(areParticleIdsUnique(simulatedInitial));
BOOST_CHECK(areParticleIdsUnique(simulatedFinal));
// hits must necessarily contain particle id duplicates
// check that every input particles is simulated
for (const auto& particle : input) {
BOOST_TEST(containsParticleId(simulatedInitial, particle));
BOOST_TEST(containsParticleId(simulatedFinal, particle));
BOOST_CHECK(containsParticleId(simulatedInitial, particle));
BOOST_CHECK(containsParticleId(simulatedFinal, particle));
}
// check that all hits can be associated to a particle
for (const auto& hit : hits) {
BOOST_TEST(containsParticleId(simulatedInitial, hit));
BOOST_TEST(containsParticleId(simulatedFinal, hit));
BOOST_CHECK(containsParticleId(simulatedInitial, hit));
BOOST_CHECK(containsParticleId(simulatedFinal, hit));
}
}
26 changes: 13 additions & 13 deletions Tests/UnitTests/Core/EventData/FreeTrackParametersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(free_initialization) {

// Test if the object can be created w/o covariance
FreeTrackParameters fpwoCov(cov, params);
BOOST_TEST(!fpwoCov.covariance().has_value());
BOOST_CHECK(!fpwoCov.covariance().has_value());
CHECK_CLOSE_ABS(fpwoCov.parameters(), params, 1e-6);

// Test if the object can be create with covariance
Expand All @@ -47,30 +47,30 @@ BOOST_AUTO_TEST_CASE(free_initialization) {
CHECK_CLOSE_ABS(fp.parameters(), params, 1e-6);

// Test == comparison
BOOST_TEST(fp == fp);
BOOST_TEST(fp != fpwoCov);
BOOST_CHECK_EQUAL(fp, fp);
BOOST_CHECK_NE(fp, fpwoCov);

FreeTrackParameters fpCopyConstr(fp);
BOOST_TEST(fpCopyConstr == fp);
BOOST_CHECK_EQUAL(fpCopyConstr, fp);

covCpy = *cov;
FreeTrackParameters fpMoveConstr(FreeTrackParameters(covCpy, params));
BOOST_TEST(fpMoveConstr == fp);
BOOST_CHECK_EQUAL(fpMoveConstr, fp);

// Test copy assignment
FreeTrackParameters fpCopyAssignment = fp;
BOOST_TEST(fpCopyAssignment == fp);
BOOST_CHECK_EQUAL(fpCopyAssignment, fp);

// Test move assignment
covCpy = *cov;
FreeTrackParameters fpMoveAssignment = FreeTrackParameters(covCpy, params);
BOOST_TEST(fpMoveAssignment == fp);
BOOST_CHECK_EQUAL(fpMoveAssignment, fp);

/// Repeat constructing and assignment with neutral parameters

// Test if the object can be created w/o covariance
NeutralFreeTrackParameters nfpwoCov(std::nullopt, params);
BOOST_TEST(!nfpwoCov.covariance().has_value());
BOOST_CHECK(!nfpwoCov.covariance().has_value());
CHECK_CLOSE_ABS(nfpwoCov.parameters(), params, 1e-6);

covCpy = *cov;
Expand All @@ -79,22 +79,22 @@ BOOST_AUTO_TEST_CASE(free_initialization) {
CHECK_CLOSE_ABS(nfp.parameters(), params, 1e-6);

NeutralFreeTrackParameters nfpCopyConstr(nfp);
BOOST_TEST(nfpCopyConstr == nfp);
BOOST_CHECK_EQUAL(nfpCopyConstr, nfp);

covCpy = *cov;
NeutralFreeTrackParameters nfpMoveConstr(
NeutralFreeTrackParameters(covCpy, params));
BOOST_TEST(nfpMoveConstr == nfp);
BOOST_CHECK_EQUAL(nfpMoveConstr, nfp);

// Test copy assignment
NeutralFreeTrackParameters nfpCopyAssignment = nfp;
BOOST_TEST(nfpCopyAssignment == nfp);
BOOST_CHECK_EQUAL(nfpCopyAssignment, nfp);

// Test move assignment
covCpy = *cov;
NeutralFreeTrackParameters nfpMoveAssignment =
NeutralFreeTrackParameters(covCpy, params);
BOOST_TEST(nfpMoveAssignment == nfp);
BOOST_CHECK_EQUAL(nfpMoveAssignment, nfp);

/// Test getters/setters

Expand Down Expand Up @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(free_initialization) {
CHECK_CLOSE_ABS(fp.position(), pos, 1e-6);
CHECK_CLOSE_ABS(fp.momentum(), dir / qop, 1e-6);
CHECK_CLOSE_ABS(fp.charge(), +1., 1e-6);
BOOST_TEST(nfp.charge() == 0.);
BOOST_CHECK_EQUAL(nfp.charge(), 0.);
CHECK_CLOSE_ABS(fp.time(), t, 1e-6);

// Test setters
Expand Down
40 changes: 20 additions & 20 deletions Tests/UnitTests/Core/Geometry/ConeVolumeBoundsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,52 @@ BOOST_AUTO_TEST_CASE(ConeVolumeBoundsTests) {
ConeVolumeBounds solidCone(0., 0., 0.45, 50_mm, 50_mm, 0., M_PI);

// Test correct parameter return
BOOST_TEST(solidCone.get(ConeVolumeBounds::eInnerAlpha) == 0.);
BOOST_TEST(solidCone.get(ConeVolumeBounds::eInnerOffsetZ) == 0.);
BOOST_TEST(solidCone.get(ConeVolumeBounds::eOuterAlpha) == 0.45);
BOOST_TEST(solidCone.get(ConeVolumeBounds::eOuterOffsetZ) == 50.);
BOOST_TEST(solidCone.get(ConeVolumeBounds::eHalfLengthZ) == 50.);
BOOST_TEST(solidCone.get(ConeVolumeBounds::eAveragePhi) == 0.);
BOOST_TEST(solidCone.get(ConeVolumeBounds::eHalfPhiSector) == M_PI);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eInnerAlpha), 0.);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eInnerOffsetZ), 0.);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eOuterAlpha), 0.45);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eOuterOffsetZ), 50.);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eHalfLengthZ), 50.);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eAveragePhi), 0.);
BOOST_CHECK_EQUAL(solidCone.get(ConeVolumeBounds::eHalfPhiSector), M_PI);
// Derived quantities
BOOST_TEST(solidCone.innerTanAlpha() == 0.);
BOOST_TEST(solidCone.innerRmin() == 0.);
BOOST_TEST(solidCone.innerRmax() == 0.);
BOOST_TEST(solidCone.outerTanAlpha() == std::tan(0.45));
BOOST_CHECK_EQUAL(solidCone.innerTanAlpha(), 0.);
BOOST_CHECK_EQUAL(solidCone.innerRmin(), 0.);
BOOST_CHECK_EQUAL(solidCone.innerRmax(), 0.);
BOOST_CHECK_EQUAL(solidCone.outerTanAlpha(), std::tan(0.45));

double outerRmax = 100_mm * solidCone.outerTanAlpha();
BOOST_TEST(solidCone.outerRmin() == 0.);
BOOST_TEST(solidCone.outerRmax() == outerRmax);
BOOST_CHECK_EQUAL(solidCone.outerRmin(), 0.);
BOOST_CHECK_EQUAL(solidCone.outerRmax(), outerRmax);

auto solidConeSurfaces = solidCone.orientedSurfaces();
BOOST_TEST(solidConeSurfaces.size() == 2);
BOOST_CHECK_EQUAL(solidConeSurfaces.size(), 2);

// Single solid Cone - with cut off
ConeVolumeBounds cutOffCone(0., 0., 0.45, 80_mm, 50_mm, 0., M_PI);
auto cutOffConeSurfaces = cutOffCone.orientedSurfaces();
BOOST_TEST(cutOffConeSurfaces.size() == 3);
BOOST_CHECK_EQUAL(cutOffConeSurfaces.size(), 3);

// Cone - Cone inlay
ConeVolumeBounds cutOffHollowCone(0.35, 70_mm, 0.45, 80_mm, 50_mm, 0., M_PI);
auto cutOffHollowConeSurfaces = cutOffHollowCone.orientedSurfaces();
BOOST_TEST(cutOffHollowConeSurfaces.size() == 4);
BOOST_CHECK_EQUAL(cutOffHollowConeSurfaces.size(), 4);

// Sectoral Cone - Cone inlay
ConeVolumeBounds cutOffHollowSectoralCone(0.35, 70_mm, 0.45, 80_mm, 50_mm, 0.,
0.456);
auto cutOffHollowSectoralConeSurfaces =
cutOffHollowSectoralCone.orientedSurfaces();
BOOST_TEST(cutOffHollowSectoralConeSurfaces.size() == 6);
BOOST_CHECK_EQUAL(cutOffHollowSectoralConeSurfaces.size(), 6);

// Sectoral Cone - Hollow Cone
ConeVolumeBounds cutOffHollowCylCone(10_mm, 0.45, 80_mm, 50_mm, 0., M_PI);
auto cutOffHollowCylConeSurfaces = cutOffHollowCylCone.orientedSurfaces();
BOOST_TEST(cutOffHollowCylConeSurfaces.size() == 4);
BOOST_CHECK_EQUAL(cutOffHollowCylConeSurfaces.size(), 4);

// Single Hollow Cylinder - Cone inlay
ConeVolumeBounds cutOffHollowConeCyl(120_mm, 0.35, 70_mm, 50_mm, 0., M_PI);
auto cutOffHollowConeCylSurfaces = cutOffHollowConeCyl.orientedSurfaces();
BOOST_TEST(cutOffHollowConeCylSurfaces.size() == 4);
BOOST_CHECK_EQUAL(cutOffHollowConeCylSurfaces.size(), 4);
}

BOOST_AUTO_TEST_CASE(ConeVolumeBoundsSurfaceOrientation) {
Expand All @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(ConeVolumeBoundsSurfaceOrientation) {
ConeVolumeBounds hcone(10_mm, 0.45, 80_mm, 50_mm, 0., M_PI);

auto cvbOrientedSurfaces = hcone.orientedSurfaces(nullptr);
BOOST_TEST(cvbOrientedSurfaces.size(), 4);
BOOST_CHECK_EQUAL(cvbOrientedSurfaces.size(), 4);

auto geoCtx = GeometryContext();
Vector3D xaxis(1., 0., 0.);
Expand Down
12 changes: 7 additions & 5 deletions Tests/UnitTests/Core/Geometry/CuboidVolumeBoundsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ BOOST_AUTO_TEST_CASE(CuboidVolumeException) {
BOOST_AUTO_TEST_CASE(CuboidVolumeProperties) {
CuboidVolumeBounds box(hx, hy, hz);
// Test the type
BOOST_TEST(box.type() == VolumeBounds::eCuboid);
BOOST_CHECK_EQUAL(box.type(), VolumeBounds::eCuboid);
// Test the halflength x
CHECK_CLOSE_ABS(box.get(CuboidVolumeBounds::eHalfLengthX), hx, s_epsilon);
// Test the halflength y
CHECK_CLOSE_ABS(box.get(CuboidVolumeBounds::eHalfLengthY), hy, s_epsilon);
// Test the halflength z
CHECK_CLOSE_ABS(box.get(CuboidVolumeBounds::eHalfLengthZ), hz, s_epsilon);
// Test the streaming
std::vector<double> actvalues = box.values();
std::vector<double> refvalues = {hx, hy, hz};
BOOST_TEST(box.values() == refvalues);
BOOST_CHECK_EQUAL_COLLECTIONS(actvalues.begin(), actvalues.end(),
refvalues.begin(), refvalues.end());

// Inside position
Vector3D inside({5., 10., 8.});
Expand All @@ -84,19 +86,19 @@ BOOST_AUTO_TEST_CASE(CuboidVolumeProperties) {
{20., 1., -2.}, {1., -30., 2.}, {-1., 2., 100.}};

// Inside position
BOOST_TEST(box.inside(inside, s_onSurfaceTolerance));
BOOST_CHECK(box.inside(inside, s_onSurfaceTolerance));

// Outside position
for (const auto& outside : outsides) {
BOOST_TEST(!box.inside(outside, s_onSurfaceTolerance));
BOOST_CHECK(!box.inside(outside, s_onSurfaceTolerance));
}
}

BOOST_AUTO_TEST_CASE(CuboidVolumeBoundarySurfaces) {
CuboidVolumeBounds box(5, 8, 7);
auto cvbOrientedSurfaces = box.orientedSurfaces(nullptr);

BOOST_TEST(cvbOrientedSurfaces.size(), (size_t)6);
BOOST_CHECK_EQUAL(cvbOrientedSurfaces.size(), 6);

auto geoCtx = GeometryContext();

Expand Down
Loading

0 comments on commit 049006c

Please sign in to comment.