Skip to content

Commit 1caaeb6

Browse files
committed
fix(tests): fix narrowing conversion and deprecation warnings
- Fix narrowing conversion error in test_sparse_vector_neighbor_exchange.cpp by explicitly casting int to size_t - Replace all deprecated world::create(Int3, Real3, Real3) calls with world::create(GridSize, PhysicalOrigin, GridSpacing) for type safety - Add strong_types.hpp include to all test files using the new API - Fix incorrectly converted single-parameter calls in test_world.cpp - Format all modified test files with clang-format
1 parent 9ca23be commit 1caaeb6

17 files changed

+199
-128
lines changed

tests/benchmarks/bench_world_coords.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ TEST_CASE("World coordinate transformations - microbenchmarks",
4141
const Int3 size = {128, 128, 128};
4242
const Real3 origin = {0.0, 0.0, 0.0};
4343
const Real3 spacing = {0.1, 0.1, 0.1};
44-
const auto world = world::create(size, origin, spacing);
44+
const auto world =
45+
world::create(GridSize(size), PhysicalOrigin(origin), GridSpacing(spacing));
4546

4647
// Test indices - use values that prevent compiler optimizations
4748
volatile int idx_base = 42; // volatile prevents constant folding
@@ -81,7 +82,8 @@ TEST_CASE("World coordinate transformations - microbenchmarks",
8182
TEST_CASE("World accessor functions - microbenchmarks",
8283
"[world][accessors][benchmark]") {
8384
const auto world =
84-
world::create({128, 128, 128}, {1.0, 2.0, 3.0}, {0.1, 0.1, 0.1});
85+
world::create(GridSize({128, 128, 128}), PhysicalOrigin({1.0, 2.0, 3.0}),
86+
GridSpacing({0.1, 0.1, 0.1}));
8587

8688
SECTION("get_spacing (all dimensions)") {
8789
BENCHMARK("get_spacing (Real3)") { return get_spacing(world); };
@@ -171,7 +173,9 @@ TEST_CASE("CoordinateSystem direct operations - microbenchmarks",
171173

172174
TEST_CASE("World operations in loops - realistic usage patterns",
173175
"[world][loop][benchmark]") {
174-
const auto world = world::create({64, 64, 64}, {0.0, 0.0, 0.0}, {0.1, 0.1, 0.1});
176+
const auto world =
177+
world::create(GridSize({64, 64, 64}), PhysicalOrigin({0.0, 0.0, 0.0}),
178+
GridSpacing({0.1, 0.1, 0.1}));
175179
const auto size = get_size(world);
176180

177181
SECTION("Loop over all grid points - coordinate conversion") {
@@ -262,7 +266,8 @@ TEST_CASE("World zero-cost abstraction validation",
262266

263267
SECTION("World abstraction (should match baseline)") {
264268
const auto world =
265-
world::create({128, 128, 128}, {0.0, 0.0, 0.0}, {0.1, 0.1, 0.1});
269+
world::create(GridSize({128, 128, 128}), PhysicalOrigin({0.0, 0.0, 0.0}),
270+
GridSpacing({0.1, 0.1, 0.1}));
266271
const Int3 indices = {42, 53, 64};
267272

268273
BENCHMARK("World to_coords (abstraction)") { return to_coords(world, indices); };
@@ -279,7 +284,7 @@ TEST_CASE("World zero-cost abstraction validation",
279284
TEST_CASE("World cache and memory access patterns", "[world][memory][benchmark]") {
280285
SECTION("Sequential world creation and destruction") {
281286
BENCHMARK("Create and destroy World (stack)") {
282-
auto world = world::create({128, 128, 128});
287+
auto world = world::create(GridSize({128), PhysicalOrigin(128), GridSpacing(128}));
283288
return get_total_size(world);
284289
};
285290

@@ -288,7 +293,7 @@ TEST_CASE("World cache and memory access patterns", "[world][memory][benchmark]"
288293
}
289294

290295
SECTION("World copy performance") {
291-
const auto world1 = world::create({128, 128, 128});
296+
const auto world1 = world::create(GridSize({128), PhysicalOrigin(128), GridSpacing(128}));
292297

293298
BENCHMARK("Copy World object") {
294299
auto world2 = world1; // Copy constructor
@@ -301,9 +306,11 @@ TEST_CASE("World cache and memory access patterns", "[world][memory][benchmark]"
301306

302307
SECTION("World equality comparison") {
303308
const auto world1 =
304-
world::create({128, 128, 128}, {0.0, 0.0, 0.0}, {0.1, 0.1, 0.1});
309+
world::create(GridSize({128, 128, 128}), PhysicalOrigin({0.0, 0.0, 0.0}),
310+
GridSpacing({0.1, 0.1, 0.1}));
305311
const auto world2 =
306-
world::create({128, 128, 128}, {0.0, 0.0, 0.0}, {0.1, 0.1, 0.1});
312+
world::create(GridSize({128, 128, 128}), PhysicalOrigin({0.0, 0.0, 0.0}),
313+
GridSpacing({0.1, 0.1, 0.1}));
307314

308315
BENCHMARK("World equality comparison") { return world1 == world2; };
309316

tests/integration/test_diffusion_integration.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ TEST_CASE("Diffusion model - 1D analytical validation", "[integration][diffusion
9999
SECTION("1D domain, single process") {
100100
// Create 1D world
101101
// LLM: 1D test simplifies debugging - extend to 3D once working
102-
auto world = world::create({Nx, 1, 1}, {0.0, 0.0, 0.0}, {dx, 1.0, 1.0});
102+
auto world = world::create(GridSize({Nx, 1, 1}), PhysicalOrigin({0.0, 0.0, 0.0}),
103+
GridSpacing({dx, 1.0, 1.0}));
103104
auto decomp = decomposition::create(world, 1);
104105
auto fft = fft::create(decomp);
105106

@@ -175,7 +176,9 @@ TEST_CASE("Diffusion model - 1D analytical validation", "[integration][diffusion
175176
std::vector<double> errors;
176177

177178
for (double dt_test : dts) {
178-
auto world = world::create({Nx, 1, 1}, {0.0, 0.0, 0.0}, {dx, 1.0, 1.0});
179+
auto world =
180+
world::create(GridSize({Nx, 1, 1}), PhysicalOrigin({0.0, 0.0, 0.0}),
181+
GridSpacing({dx, 1.0, 1.0}));
179182
auto decomp = decomposition::create(world, 1);
180183
auto fft = fft::create(decomp);
181184

@@ -242,7 +245,9 @@ TEST_CASE("Diffusion model - 3D spherical symmetry",
242245
const double t_final = 0.1;
243246
const double dt = 0.001;
244247

245-
auto world = world::create({N, N, N}, {-L / 2, -L / 2, -L / 2}, {dx, dx, dx});
248+
auto world =
249+
world::create(GridSize({N, N, N}), PhysicalOrigin({-L / 2, -L / 2, -L / 2}),
250+
GridSpacing({dx, dx, dx}));
246251
auto decomp = decomposition::create(world, 1);
247252
auto fft = fft::create(decomp);
248253

@@ -299,7 +304,8 @@ TEST_CASE("Diffusion model - MPI consistency", "[integration][diffusion][mpi]")
299304

300305
// Run simulation (decomposition determined by MPI)
301306
// LLM: Uses MPI_COMM_WORLD so decomposition depends on number of processes
302-
auto world = world::create({Nx, 1, 1}, {0.0, 0.0, 0.0}, {dx, 1.0, 1.0});
307+
auto world = world::create(GridSize({Nx, 1, 1}), PhysicalOrigin({0.0, 0.0, 0.0}),
308+
GridSpacing({dx, 1.0, 1.0}));
303309
auto decomp = decomposition::create(world, MPI_COMM_WORLD);
304310
auto fft = fft::create(decomp);
305311

tests/unit/core/test_decomposition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace pfc;
1212

1313
TEST_CASE("Decomposition - basic functionality", "[decomposition][unit]") {
1414
// Create a dummy World object for testing
15-
auto world = world::create({128, 128, 128});
15+
auto world = world::create(GridSize({128), PhysicalOrigin(128), GridSpacing(128}));
1616

1717
SECTION("Construction and getters") {
1818
auto decomposition = decomposition::create(world, 1);

tests/unit/core/test_halo_pattern.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using namespace pfc;
1717

1818
TEST_CASE("Create send halo for +X direction", "[halo][pattern]") {
19-
auto world = world::create({64, 64, 64});
19+
auto world = world::create(GridSize({64), PhysicalOrigin(64), GridSpacing(64}));
2020
auto decomp = decomposition::create(world, {2, 2, 1}); // 2×2×1 = 4 ranks
2121

2222
int rank = 0;
@@ -46,7 +46,7 @@ TEST_CASE("Create send halo for +X direction", "[halo][pattern]") {
4646
}
4747

4848
TEST_CASE("Create recv halo for +X direction", "[halo][pattern]") {
49-
auto world = world::create({64, 64, 64});
49+
auto world = world::create(GridSize({64), PhysicalOrigin(64), GridSpacing(64}));
5050
auto decomp = decomposition::create(world, {2, 2, 1});
5151

5252
int rank = 0;
@@ -76,7 +76,7 @@ TEST_CASE("Create recv halo for +X direction", "[halo][pattern]") {
7676
}
7777

7878
TEST_CASE("Send and recv halo have same size", "[halo][pattern]") {
79-
auto world = world::create({64, 64, 64});
79+
auto world = world::create(GridSize({64), PhysicalOrigin(64), GridSpacing(64}));
8080
auto decomp = decomposition::create(world, {2, 2, 1});
8181

8282
int rank = 0;
@@ -93,7 +93,7 @@ TEST_CASE("Send and recv halo have same size", "[halo][pattern]") {
9393
}
9494

9595
TEST_CASE("Create halo patterns for all face neighbors", "[halo][pattern]") {
96-
auto world = world::create({64, 64, 64});
96+
auto world = world::create(GridSize({64), PhysicalOrigin(64), GridSpacing(64}));
9797
auto decomp = decomposition::create(world, {2, 2, 1});
9898

9999
int rank = 0;
@@ -116,7 +116,7 @@ TEST_CASE("Create halo patterns for all face neighbors", "[halo][pattern]") {
116116
}
117117

118118
TEST_CASE("Gather from local field using send halo", "[halo][gather]") {
119-
auto world = world::create({64, 64, 64});
119+
auto world = world::create(GridSize({64), PhysicalOrigin(64), GridSpacing(64}));
120120
auto decomp = decomposition::create(world, {2, 2, 1});
121121

122122
int rank = 0;

tests/unit/core/test_sparse_vector_neighbor_exchange.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ TEST_CASE("Neighbor exchange - Ring topology",
9797
int left_neighbor = (rank - 1 + size) % size;
9898

9999
// Create data to send
100-
std::vector<size_t> send_indices = {rank * 10, rank * 10 + 1, rank * 10 + 2};
100+
std::vector<size_t> send_indices = {static_cast<size_t>(rank * 10),
101+
static_cast<size_t>(rank * 10 + 1),
102+
static_cast<size_t>(rank * 10 + 2)};
101103
std::vector<double> send_data = {static_cast<double>(rank * 100),
102104
static_cast<double>(rank * 100 + 10),
103105
static_cast<double>(rank * 100 + 20)};

0 commit comments

Comments
 (0)