Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows test builds #1255

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/cmake-presets/ci-windows-github.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"inherits": ["base"],
"displayName": "fast build with testing and JSON",
"cacheVariables": {
"CELERITAS_BUILD_TESTS": {"type": "BOOL", "value": "OFF"},
"CELERITAS_BUILD_TESTS": {"type": "BOOL", "value": "ON"},
"CELERITAS_USE_JSON": {"type": "BOOL", "value": "ON"}
}
},
Expand Down
12 changes: 6 additions & 6 deletions test/TestMacros.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,22 @@ TEST(IsVecEq, failures)
IsVecEq("expectedddddddddd", "actualllllllllll", expected, actual));

// multiple wrong values
expected.push_back(100.);
actual.push_back(102.);
expected.push_back(100);
actual.push_back(102);
EXPECT_FALSE(IsVecEq("expected", "actual", expected, actual));
EXPECT_FALSE(IsVecEq("static_array", "actual", static_array, actual));

// Ten wrong values
expected.assign(10, 5.);
actual.assign(10, 6.);
expected.assign(10, 5);
actual.assign(10, 6);
EXPECT_FALSE(IsVecEq("expected", "actual", expected, actual));

// Uncomment this line to test output
// EXPECT_VEC_EQ(expected, actual);

// 100 wrong values (should truncate)
expected.assign(100, 5.);
actual.assign(100, 6.);
expected.assign(100, 5);
actual.assign(100, 6);
EXPECT_FALSE(IsVecEq("expected", "actual", expected, actual));

// A couple of wrong values in a large array
Expand Down
2 changes: 1 addition & 1 deletion test/celeritas/em/CombinedBrem.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ TEST_F(CombinedBremTest, basic_relativistic_brem)

TEST_F(CombinedBremTest, stress_test_combined)
{
int const num_samples = 1e4;
int const num_samples = 10000;
std::vector<double> avg_engine_samples;
std::vector<double> avg_energy_samples;

Expand Down
21 changes: 11 additions & 10 deletions test/celeritas/em/Fluctuation.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ TEST_F(EnergyLossDistributionTest, urban)
counts[bin]++;
sum += loss;
}

if (CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_DOUBLE)
{
static real_type const expected_counts[]
= {0, 0, 12, 223, 1174, 2359, 2661, 1867, 898, 369,
189, 107, 60, 48, 20, 9, 2, 2, 0, 0};
EXPECT_VEC_SOFT_EQ(expected_counts, counts);
EXPECT_SOFT_EQ(0.0099918954960280353, sum / num_samples);
EXPECT_EQ(551188, rng.count());
}
#ifdef _MSC_VER
// TODO: determine why the sampled sequence is different
GTEST_SKIP() << "Results differ statistically when built with MSVC...";
#endif

static real_type const expected_counts[]
= {0, 0, 12, 223, 1174, 2359, 2661, 1867, 898, 369,
189, 107, 60, 48, 20, 9, 2, 2, 0, 0};
EXPECT_VEC_SOFT_EQ(expected_counts, counts);
EXPECT_SOFT_EQ(0.0099918954960280353, sum / num_samples);
EXPECT_EQ(551188, rng.count());
}
//---------------------------------------------------------------------------//
} // namespace test
Expand Down
6 changes: 3 additions & 3 deletions test/celeritas/em/KleinNishina.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ TEST_F(KleinNishinaInteractorTest, distributions)
Interaction out = interact(rng_engine);
// Bin energy loss
double eps = out.energy.value() / inc_energy;
int eps_bin = eps * nbins;
int eps_bin = static_cast<int>(std::floor(eps * nbins));
if (eps_bin >= 0 && eps_bin < nbins)
{
++eps_dist[eps_bin];
}

// Bin directional change
// Bin directional change, remapping from [-1,1] to [0,1]
double costheta = dot_product(inc_direction, out.direction);
int ct_bin = (1 + costheta) / 2 * nbins; // Remap from [-1,1] to [0,1]
int ct_bin = static_cast<int>(std::floor((1 + costheta) / 2 * nbins));
if (ct_bin >= 0 && ct_bin < nbins)
{
++costheta_dist[ct_bin];
Expand Down
2 changes: 1 addition & 1 deletion test/celeritas/em/LivermorePE.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ TEST_F(LivermorePETest, distributions_all)
// Bin directional change of the photoelectron
real_type costheta
= dot_product(inc_direction, out.secondaries.front().direction);
int ct_bin = (1 + costheta) / 2 * nbins; // Remap from [-1,1] to [0,1]
int ct_bin = static_cast<int>(std::floor((1 + costheta) / 2 * nbins));
if (ct_bin >= 0 && ct_bin < nbins)
{
++costheta_dist[ct_bin];
Expand Down
2 changes: 1 addition & 1 deletion test/celeritas/em/MollerBhabha.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ TEST_F(MollerBhabhaInteractorTest, cutoff_1MeV)
//---------------------------------------------------------------------------//
TEST_F(MollerBhabhaInteractorTest, stress_test)
{
int const num_samples = 1e4;
int const num_samples = 10000;
std::vector<double> avg_engine_samples;

CutoffView cutoff_view(this->cutoff_params()->host_ref(), MaterialId{0});
Expand Down
2 changes: 1 addition & 1 deletion test/celeritas/em/MuBremsstrahlung.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ TEST_F(MuBremsstrahlungInteractorTest, basic)

TEST_F(MuBremsstrahlungInteractorTest, stress_test)
{
unsigned int const num_samples = 1e4;
unsigned int const num_samples = 10000;
std::vector<double> avg_engine_samples;

for (auto particle : {pdg::mu_minus(), pdg::mu_plus()})
Expand Down
2 changes: 1 addition & 1 deletion test/celeritas/em/SeltzerBerger.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ TEST_F(SeltzerBergerTest, basic)

TEST_F(SeltzerBergerTest, stress_test)
{
int const num_samples = 1e4;
int const num_samples = 10000;
std::vector<real_type> avg_engine_samples;

// Views
Expand Down
3 changes: 2 additions & 1 deletion test/celeritas/em/UrbanMsc.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ TEST_F(UrbanMscTest, TEST_IF_CELERITAS_DOUBLE(step_limit))
}
}

constexpr double step_is_range = -1;

TEST_F(UrbanMscTest, TEST_IF_CELERITAS_DOUBLE(msc_scattering))
{
// Test energies
Expand All @@ -575,7 +577,6 @@ TEST_F(UrbanMscTest, TEST_IF_CELERITAS_DOUBLE(msc_scattering))
// Calculate range instead of hardcoding to ensure step and range values
// are bit-for-bit identical when range limits the step. The first three
// steps are not limited by range
constexpr double step_is_range = -1;
std::vector<double> step = {0.00279169, 0.412343, 0.0376414}; // [cm]
step.resize(nsamples, step_is_range);

Expand Down
3 changes: 2 additions & 1 deletion test/celeritas/geo/HeuristicGeoTestBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void HeuristicGeoTestBase::run_host(size_type num_states, real_type tolerance)
ADD_FAILURE() << "Implement the following as "
"TestCase::reference_avg_path() const";

int precision_digits = std::ceil(-std::log10(tolerance) + 0.5);
int precision_digits
= static_cast<int>(std::ceil(-std::log10(tolerance) + 0.5));

std::cout << "/* REFERENCE PATH LENGTHS */\n"
"static real_type const paths[] = {"
Expand Down
13 changes: 3 additions & 10 deletions test/celeritas/grid/GenericGridInserter.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//---------------------------------------------------------------------------//
#include "celeritas/grid/GenericGridInserter.hh"

#include <array>

#include "corecel/OpaqueId.hh"
#include "celeritas/random/distribution/UniformRealDistribution.hh"

Expand All @@ -17,21 +19,12 @@ namespace celeritas
{
namespace test
{

/*
* Dummy opaque id tag to make sure GenericGridInserter doesn't rely on a
* specific type.
*/
struct GenericIndexTag
{
};

//---------------------------------------------------------------------------//

class GenericGridInserterTest : public ::celeritas::test::Test
{
protected:
using GridIndexType = OpaqueId<GenericIndexTag>;
using GridIndexType = OpaqueId<struct GenericIndexTag_>;
using RandomEngine = DiagnosticRngEngine<std::mt19937>;

void SetUp() override { rng_.reset_count(); }
Expand Down
6 changes: 3 additions & 3 deletions test/celeritas/optical/Cerenkov.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ TEST_F(CerenkovTest, TEST_IF_CELERITAS_DOUBLE(generator))
real_type costheta = dot_product(inc_dir, photon.direction);
avg_costheta += costheta;
// Remap from [-1,1] to [0,1]
int bin = (1 + costheta) / 2 * num_bins;
int bin = static_cast<int>((1 + costheta) / 2 * num_bins);
CELER_ASSERT(bin < num_bins);
++costheta_dist[bin];
}
// Bin photon energy
{
real_type energy = photon.energy.value();
avg_energy += energy;
int bin = (energy - emin) / edel;
int bin = static_cast<int>((energy - emin) / edel);
CELER_ASSERT(bin < num_bins);
++energy_dist[bin];
}
Expand All @@ -384,7 +384,7 @@ TEST_F(CerenkovTest, TEST_IF_CELERITAS_DOUBLE(generator))
real_type displacement
= distance(pre_step.pos, photon.position);
avg_displacement += displacement;
int bin = (displacement - dmin) / ddel;
int bin = static_cast<int>((displacement - dmin) / ddel);
CELER_ASSERT(bin < num_bins);
++displacement_dist[bin];
}
Expand Down
4 changes: 2 additions & 2 deletions test/celeritas/random/RngEngine.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class SequenceEngineTest : public Test
public:
void SetUp() override
{
double const inv_32 = std::ldexp(1.0, -32.0);
double const inv_64 = std::ldexp(1.0, -64.0);
double const inv_32 = std::ldexp(1.0, -32);
double const inv_64 = std::ldexp(1.0, -64);
/*!
* Note: even the lowest *normalized* float value (1e-38) is below
* 2**-64, so the "min" values for both double and float are
Expand Down
4 changes: 2 additions & 2 deletions test/celeritas/random/SequenceEngine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SequenceEngine SequenceEngine::from_reals(Span<double const> values)
CELER_EXPECT(v >= 0 && v < 1);
// Calculate first (big end) value
v *= range;
result_type second = std::floor(v);
auto second = static_cast<result_type>(std::floor(v));

// Calculate second (little end) value
v -= second;
Expand Down Expand Up @@ -197,7 +197,7 @@ T GenerateCanonical<test::SequenceEngine, T>::operator()(
// Range for sequence engine should be [0, 2^32 - 1) = 2^32
real_type const range = static_cast<real_type>(test::SequenceEngine::max())
+ real_type(1);
real_type result = rng();
real_type result = static_cast<real_type>(rng());
result += rng() * range;
result *= 1 / ipow<2>(range);
if (CELER_UNLIKELY(result == real_type(1)))
Expand Down
2 changes: 1 addition & 1 deletion test/corecel/cont/Range.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ TEST(TEST_IF_CELER_DEVICE(DeviceRangeTest), grid_stride)
input.num_threads = device().threads_per_warp();

// Calculate saxpy using CPU
std::vector<int> z_cpu(N, 0.0);
std::vector<int> z_cpu(N, 0);
for (auto i : range(N))
{
z_cpu[i] = input.a * input.x[i] + input.y[i];
Expand Down
2 changes: 1 addition & 1 deletion test/corecel/math/Algorithms.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ TEST(MathTest, diffsq)
EXPECT_DOUBLE_EQ(9.0, diffsq(5.0, 4.0));
EXPECT_DOUBLE_EQ(ipow<2>(std::sin(0.2)), diffsq(1.0, std::cos(0.2)));

float a{10000.001}, b{10000}, actual{20};
float a{10000.001f}, b{10000.f}, actual{20.f};
EXPECT_FLOAT_EQ(0.46875f, actual - diffsq(a, b));
EXPECT_LE(actual - diffsq(a, b), actual - (a * a - b * b));
}
Expand Down
21 changes: 12 additions & 9 deletions test/corecel/math/SoftEqual.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TYPED_TEST_SUITE(FloatingTest, FloatTypes, );
TYPED_TEST(FloatingTest, soft_equal)
{
using value_type = typename TestFixture::value_type;
using R = value_type;
using Limits_t = typename TestFixture::Limits_t;
using Comp = SoftEqual<value_type>;

Expand All @@ -73,11 +74,11 @@ TYPED_TEST(FloatingTest, soft_equal)
EXPECT_TRUE(comp(1, 1 + comp.rel() / 2));
EXPECT_FALSE(comp(1, 1 + comp.rel() * 2));
// Large scale
EXPECT_TRUE(comp(1e6, 1e6 * (1 + comp.rel() / 2)));
EXPECT_FALSE(comp(1e6, 1e6 * (1 + comp.rel() * 2)));
EXPECT_TRUE(comp(R(1e6), R(1e6) * (1 + comp.rel() / 2)));
EXPECT_FALSE(comp(R(1e6), R(1e6) * (1 + comp.rel() * 2)));
// Smaller scale
EXPECT_TRUE(comp(1e-5, 1e-5 * (1 + comp.rel() / 2)));
EXPECT_FALSE(comp(1e-5, 1e-6));
EXPECT_TRUE(comp(R(1e-5), R(1e-5) * (1 + comp.rel() / 2)));
EXPECT_FALSE(comp(R(1e-5), R(1e-6)));

if (std::is_same_v<double, value_type>)
{
Expand Down Expand Up @@ -121,21 +122,23 @@ TYPED_TEST(FloatingTest, equal_or_soft_equal)
using Limits_t = typename TestFixture::Limits_t;
value_type const nan = Limits_t::quiet_NaN();
value_type const inf = Limits_t::infinity();
value_type const one{1};
value_type const zero{0};

EqualOr<SoftEqual<value_type>> comp;

EXPECT_TRUE(comp(1, 1));
EXPECT_TRUE(comp(0, 0));
EXPECT_FALSE(comp(-1, 1));
EXPECT_FALSE(comp(1, -1));
EXPECT_TRUE(comp(one, one));
EXPECT_TRUE(comp(zero, zero));
EXPECT_FALSE(comp(-one, one));
EXPECT_FALSE(comp(one, -one));
EXPECT_FALSE(comp(inf, -inf));
EXPECT_FALSE(comp(-inf, inf));

EXPECT_TRUE(comp(inf, inf));
EXPECT_TRUE(comp(1e6, 1e6 * (1 + comp.rel() / 2)));
EXPECT_FALSE(comp(1e6, 1e6 * (1 + comp.rel() * 2)));

EXPECT_FALSE(comp(1, nan));
EXPECT_FALSE(comp(one, nan));
}

TYPED_TEST(FloatingTest, soft_zero)
Expand Down
2 changes: 1 addition & 1 deletion test/geocel/MockGeoTrackView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ MockGeoTrackView::operator=(Initializer_t const& init)
{
++init_count_;
this->state_ = init;
volume_id_ = std::floor(this->z());
volume_id_ = static_cast<int>(std::floor(this->z()));
on_boundary_ = false;
return *this;
}
Expand Down
Loading
Loading