@@ -265,3 +265,49 @@ GTEST_TEST(detray_material, trapezoid_map) {
265265 EXPECT_FALSE (trapezoid_map.at (199 , 0 ) ==
266266 material_t (aluminium<scalar>{}, 201 .f * unit<scalar>::mm));
267267}
268+
269+ // / Unittest: Test the material grid comparisons
270+ GTEST_TEST (detray_material, material_grid_comparison) {
271+
272+ /* * Allows to create a regular grid to check the equality opeartor
273+ * grids can differ in:
274+ * - type (will never be compared)
275+ * - bins/axes
276+ * - entries (i.e. material data)
277+ */
278+ auto createGrid = [](const scalar hx, const scalar hy, unsigned int bx,
279+ unsigned int by, bool distort_entries) {
280+ mask<rectangle2D> r2{0u , hx, hy};
281+ auto material_grid = mat_map_factory.new_grid (r2, {bx, by});
282+
283+ // Fill the material grid with some data
284+ scalar thickness = 2 .f * unit<scalar>::mm;
285+ for (dindex gbin = 0 ; gbin < material_grid.nbins (); ++gbin) {
286+ material_grid.template populate <replace<>>(
287+ gbin, material_t (oxygen_gas<scalar>{}, thickness));
288+ thickness += 1 .f * unit<scalar>::mm;
289+ if (distort_entries) {
290+ thickness += 1 .f * unit<scalar>::mm;
291+ }
292+ }
293+ // Return it
294+ return material_grid;
295+ };
296+
297+ // Two equal grids
298+ auto grid_ref = createGrid (10 .f , 20 .f , 10u , 20u , false );
299+ auto grid_eq = createGrid (10 .f , 20 .f , 10u , 20u , false );
300+ EXPECT_EQ (grid_ref, grid_eq);
301+
302+ // One grid with different size
303+ auto grid_neq_size = createGrid (11 .f , 21 .f , 10u , 20u , false );
304+ EXPECT_NE (grid_ref, grid_neq_size);
305+
306+ // One grid with different binning
307+ auto grid_neq_bins = createGrid (10 .f , 20 .f , 11u , 21u , false );
308+ EXPECT_NE (grid_ref, grid_neq_bins);
309+
310+ // One grid with different entries
311+ auto grid_neq_entries = createGrid (10 .f , 20 .f , 10u , 20u , true );
312+ EXPECT_NE (grid_ref, grid_neq_entries);
313+ }
0 commit comments