// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include #include "../receiver/StillsSelection.h" TEST_CASE("StillsImageSelected_FractionAndPeriods", "[StillsSelection]") { constexpr int64_t first = 2000; constexpr int64_t images = 400000; for (const int64_t factor: {2, 3, 4, 10}) { INFO("factor " << factor); const double p = 1.0 / static_cast(factor); int64_t selected = 0; for (int64_t i = first; i < first + images; i++) selected += StillsImageSelected(i, factor, first) ? 1 : 0; // Within 5 standard deviations of the binomial CHECK(std::abs(static_cast(selected) / images - p) < 5 * std::sqrt(p * (1 - p) / images)); // Every phase of a period-2 and a period-F pattern (pump-probe on/off, a stride) gets its share for (const int64_t period: {int64_t(2), factor}) { for (int64_t phase = 0; phase < period; phase++) { INFO("period " << period << " phase " << phase); int64_t n = 0, s = 0; for (int64_t i = first + phase; i < first + images; i += period) { n++; s += StillsImageSelected(i, factor, first) ? 1 : 0; } CHECK(std::abs(static_cast(s) / n - p) < 5 * std::sqrt(p * (1 - p) / n)); } } } } TEST_CASE("StillsImageSelected_DeterministicAndPrePass", "[StillsSelection]") { for (int64_t i = 0; i < 10000; i++) { CHECK(StillsImageSelected(i, 1, 0)); // factor 1: every image CHECK(StillsImageSelected(i, 7, 10000)); // before all_before: every image CHECK(StillsImageSelected(i, 7, 0) == StillsImageSelected(i, 7, 0)); } }