// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include #include #include "../common/ResolutionShells.h" TEST_CASE("ResolutionShells_WrongInput") { REQUIRE_THROWS(ResolutionShells(-1,5,10)); REQUIRE_THROWS(ResolutionShells(7,5,10)); REQUIRE_THROWS(ResolutionShells(5,6,0)); REQUIRE_THROWS(ResolutionShells(5,6,-10)); } TEST_CASE("ResolutionShells") { ResolutionShells shells(1,50, 20); REQUIRE(!shells.GetShell(50.0111)); REQUIRE(shells.GetShell(50.0) == 0); REQUIRE(shells.GetShell(49.555) == 0); REQUIRE(shells.GetShell(1.001) == 19); REQUIRE(!shells.GetShell(1.0)); float one_over_d_sq = 1/(50. * 50.) + 10.2 * (1/(1 * 1) - 1/(50 * 50)) / 20; REQUIRE(shells.GetShell(1/sqrtf(one_over_d_sq)) == 10); } // An infinite d_max is "no low-resolution bound": the shells start at 1/d^2 = 0, so every finite // resolution coarser than d_min falls in shell 0 and the shell boundaries stay finite. TEST_CASE("ResolutionShells_NoLowBound") { const ResolutionShells shells(1, std::numeric_limits::infinity(), 20); REQUIRE(shells.GetShell(1e6f) == 0); REQUIRE(shells.GetShell(50.0) == 0); REQUIRE(shells.GetShell(1.001) == 19); REQUIRE(!shells.GetShell(1.0)); REQUIRE(!shells.GetShell(std::numeric_limits::infinity())); const auto min_res = shells.GetShellMinRes(); REQUIRE(min_res.size() == 20); for (const auto d: min_res) REQUIRE(std::isfinite(d)); // With the low bound at 1/d^2 = 0 the first boundary is at 1/20th of the sphere. REQUIRE(min_res.front() == Catch::Approx(std::sqrt(20.0))); }