added drop dimension test, added file calibration.test.cpp

This commit is contained in:
2025-07-25 10:18:55 +02:00
parent 1347158235
commit 1195a5e100
2 changed files with 67 additions and 1 deletions

View File

@@ -427,4 +427,21 @@ TEST_CASE("Construct an NDArray from an std::array") {
for (uint32_t i = 0; i < a.size(); ++i) { for (uint32_t i = 0; i < a.size(); ++i) {
REQUIRE(a(i) == b[i]); REQUIRE(a(i) == b[i]);
} }
} }
TEST_CASE("Drop dimension") {
NDArray<int, 3> array(std::array<ssize_t, 3>{2, 2, 2});
std::fill(array.begin(), array.begin() + 4, 0);
std::fill(array.begin() + 4, array.end(), 1);
auto new_array = std::move(array).drop_dimension();
CHECK(new_array.shape() == std::array<ssize_t, 2>{2, 2});
CHECK(new_array.size() == 4);
std::for_each(new_array.begin(), new_array.end(),
[](int &element) { CHECK(element == 0); });
CHECK(array.size() == 0); // array was moved
}

49
src/calibration.test.cpp Normal file
View File

@@ -0,0 +1,49 @@
/************************************************
* @file test-Cluster.cpp
* @short test case for generic Cluster, ClusterVector, and calculate_eta2
***********************************************/
#include "aare/calibration.hpp"
// #include "catch.hpp"
#include <array>
#include <catch2/catch_all.hpp>
#include <catch2/catch_test_macros.hpp>
using namespace aare;
TEST_CASE("Test Pedestal Generation", "[.calibration]") {
NDArray<uint16_t, 3> raw(std::array<ssize_t, 3>{3, 2, 2}, 0);
// gain 0
raw(0, 0, 0) = 100;
raw(1, 0, 0) = 200;
raw(2, 0, 0) = 300;
// gain 1
raw(0, 0, 1) = (1 << 14) + 100;
raw(1, 0, 1) = (1 << 14) + 200;
raw(2, 0, 1) = (1 << 14) + 300;
raw(0, 1, 0) = (1 << 14) + 37;
raw(1, 1, 0) = 38;
raw(2, 1, 0) = (3 << 14) + 39;
// gain 2
raw(0, 1, 1) = (3 << 14) + 100;
raw(1, 1, 1) = (3 << 14) + 200;
raw(2, 1, 1) = (3 << 14) + 300;
auto pedestal = calculate_pedestal<double>(raw.view(), 4);
REQUIRE(pedestal.size() == raw.size());
CHECK(pedestal(0, 0, 0) == 200);
CHECK(pedestal(1, 0, 0) == 0);
CHECK(pedestal(1, 0, 1) == 200);
auto pedestal_gain0 = calculate_pedestal_g0<double>(raw.view(), 4);
REQUIRE(pedestal_gain0.size() == 4);
CHECK(pedestal_gain0(0, 0) == 200);
CHECK(pedestal_gain0(1, 0) == 38);
}