mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-06-06 05:48:41 +02:00
added bounds check
This commit is contained in:
@@ -70,4 +70,73 @@ TEST_CASE("Fill a small histogram from an NDArray") {
|
||||
REQUIRE(v(0, 2, 2) == 1);
|
||||
REQUIRE(v(1, 0, 3) == 1);
|
||||
REQUIRE(v(1, 1, 4) == 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Check that pixel histogram does not overflow"){
|
||||
int rows = 1;
|
||||
int cols = 1;
|
||||
int n_bins = 10;
|
||||
double xmin = 0.0;
|
||||
double xmax = 1.0;
|
||||
aare::PixelHistogramImpl<double, uint8_t> hist_u8(rows, cols, n_bins, xmin,
|
||||
xmax);
|
||||
|
||||
for (int i = 0; i < 255; ++i) {
|
||||
hist_u8.fill(0, 0, 0.05);
|
||||
}
|
||||
|
||||
auto v0 = hist_u8.view();
|
||||
REQUIRE(v0(0, 0, 0) == 255);
|
||||
|
||||
hist_u8.fill(0, 0, 0.05);
|
||||
REQUIRE(v0(0, 0, 0) == 255);
|
||||
|
||||
aare::PixelHistogramImpl<double, int8_t> hist_i8(rows, cols, n_bins, xmin,
|
||||
xmax);
|
||||
|
||||
for (int i = 0; i < 350; ++i) {
|
||||
hist_i8.fill(0, 0, 0.05);
|
||||
}
|
||||
|
||||
auto v1 = hist_i8.view();
|
||||
REQUIRE(v1(0, 0, 0) == 127);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Check that values outside the range do not affect the histogram") {
|
||||
int rows = 1;
|
||||
int cols = 1;
|
||||
int n_bins = 10;
|
||||
double xmin = 0.0;
|
||||
double xmax = 1.0;
|
||||
aare::PixelHistogramImpl<double, double> hist(rows, cols, n_bins, xmin,
|
||||
xmax);
|
||||
hist.fill(0, 0, -0.1); // below range
|
||||
hist.fill(0, 0, 1.0); // at upper edge (should be out of range)
|
||||
hist.fill(0, 0, 1.1); // above range
|
||||
|
||||
auto v = hist.view();
|
||||
auto total = std::accumulate(v.begin(), v.end(), 0);
|
||||
REQUIRE(total == 0);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Check that row and column bounds are checked") {
|
||||
int rows = 1;
|
||||
int cols = 1;
|
||||
int n_bins = 10;
|
||||
double xmin = 0.0;
|
||||
double xmax = 1.0;
|
||||
aare::PixelHistogramImpl<double, double> hist(rows, cols, n_bins, xmin,
|
||||
xmax);
|
||||
REQUIRE_THROWS_AS(hist.fill(0, 1, -0.1), std::out_of_range); // col out of range
|
||||
REQUIRE_THROWS_AS(hist.fill(1, 0, 1.0), std::out_of_range); // row out of range
|
||||
REQUIRE_THROWS_AS(hist.fill(58, -1, 1.1), std::out_of_range); // both out of range
|
||||
|
||||
auto v = hist.view();
|
||||
auto total = std::accumulate(v.begin(), v.end(), 0);
|
||||
REQUIRE(total == 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user