mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-06-06 08:48:41 +02:00
test for filling with NDArray
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
|
||||
#include "aare/NDArray.hpp"
|
||||
#include "aare/hist/PixelHistogramImpl.hpp"
|
||||
|
||||
TEST_CASE("PixelHistogramImpl construct a small histogram and fill with a few "
|
||||
@@ -43,3 +44,30 @@ TEST_CASE("PixelHistogramImpl construct a small histogram and fill with a few "
|
||||
v(1, 1, 1) ==
|
||||
1); // At the edge should go to the bin with the edge as the lower bound
|
||||
}
|
||||
|
||||
TEST_CASE("Fill a small histogram from an NDArray") {
|
||||
int rows = 2;
|
||||
int cols = 3;
|
||||
int n_bins = 10;
|
||||
double xmin = 0.0;
|
||||
double xmax = 1.0;
|
||||
aare::PixelHistogramImpl<double, int64_t> hist(rows, cols, n_bins, xmin,
|
||||
xmax);
|
||||
|
||||
aare::NDArray<double> frame({rows, cols});
|
||||
frame(0, 0) = 0.05; // bin 0
|
||||
frame(0, 1) = 0.15; // bin 1
|
||||
frame(0, 2) = 0.25; // bin 2
|
||||
frame(1, 0) = 0.35; // bin 3
|
||||
frame(1, 1) = 0.45; // bin 4
|
||||
frame(1, 2) = 1.5; // out of range
|
||||
|
||||
hist.fill(frame.view());
|
||||
|
||||
auto v = hist.view();
|
||||
REQUIRE(v(0, 0, 0) == 1);
|
||||
REQUIRE(v(0, 1, 1) == 1);
|
||||
REQUIRE(v(0, 2, 2) == 1);
|
||||
REQUIRE(v(1, 0, 3) == 1);
|
||||
REQUIRE(v(1, 1, 4) == 1);
|
||||
}
|
||||
Reference in New Issue
Block a user