Files
Jungfraujoch/tests/ROIFilterTest.cpp

138 lines
3.2 KiB
C++

// Copyright (2019-2022) Paul Scherrer Institute
// SPDX-License-Identifier: GPL-3.0-or-later
#include <catch2/catch.hpp>
#include "../common/ROIFilter.h"
TEST_CASE("ROIFilter") {
int32_t width = 4;
int32_t height = 5;
std::vector<uint32_t> v(width * height, 1);
ROIFilter filter(width, height);
filter.SetRectangle(1, 1, 2, 3);
filter.Apply(v, (uint32_t) 55);
REQUIRE(v[0] == 55);
REQUIRE(v[2] == 55);
REQUIRE(v[width * 1 + 0] == 55);
REQUIRE(v[width * 1 + 1] == 1);
REQUIRE(v[width * 1 + 2] == 1);
REQUIRE(v[width * 1 + 3] == 55);
REQUIRE(v[width * 3 + 2] == 1);
REQUIRE(v[width * 4 + 2] == 55);
}
TEST_CASE("ROIFilter_out_of_bounds") {
int32_t width = 4;
int32_t height = 5;
std::vector<uint32_t> v(width * height, 1);
ROIFilter filter(width, height);
filter.SetRectangle(1, 5, 2, 3);
filter.SetRectangle(4, 1, 2, 3);
filter.Apply(v, (uint32_t) 55);
size_t diff = 0;
for (auto &i: v) {
if (i != 55)
diff++;
}
REQUIRE(diff == 0);
}
TEST_CASE("ROIFilter_negative_out_of_bounds") {
int32_t width = 4;
int32_t height = 5;
std::vector<uint32_t> v(width * height, 1);
ROIFilter filter(width, height);
filter.SetRectangle(1, -9, 2, 3);
filter.SetRectangle(-3, 1, 2, 3);
filter.Apply(v, (uint32_t) 55);
size_t diff = 0;
for (auto &i: v) {
if (i != 55)
diff++;
}
REQUIRE(diff == 0);
}
TEST_CASE("ROIFilter_on_bounds") {
int32_t width = 4;
int32_t height = 5;
std::vector<uint32_t> v(width * height, 1);
ROIFilter filter(width, height);
filter.SetRectangle(2, 3, 10, 10);
filter.Apply(v, (uint32_t) 55);
REQUIRE(v[1 * width + 0] == 55);
REQUIRE(v[1 * width + 1] == 55);
REQUIRE(v[1 * width + 2] == 55);
REQUIRE(v[1 * width + 3] == 55);
REQUIRE(v[2 * width + 0] == 55);
REQUIRE(v[2 * width + 1] == 55);
REQUIRE(v[2 * width + 2] == 55);
REQUIRE(v[2 * width + 3] == 55);
REQUIRE(v[3 * width + 0] == 55);
REQUIRE(v[3 * width + 1] == 55);
REQUIRE(v[3 * width + 2] == 1);
REQUIRE(v[3 * width + 3] == 1);
REQUIRE(v[4 * width + 0] == 55);
REQUIRE(v[4 * width + 1] == 55);
REQUIRE(v[4 * width + 2] == 1);
REQUIRE(v[4 * width + 3] == 1);
}
TEST_CASE("ROIFilter_negative_start") {
int32_t width = 4;
int32_t height = 5;
std::vector<uint32_t> v(width * height, 1);
ROIFilter filter(width, height);
filter.SetRectangle(-1, -1, 3, 4);
filter.Apply(v, (uint32_t) 55);
CHECK(v[0 * width + 0] == 1);
CHECK(v[0 * width + 1] == 1);
CHECK(v[0 * width + 2] == 55);
CHECK(v[0 * width + 3] == 55);
CHECK(v[1 * width + 0] == 1);
CHECK(v[1 * width + 1] == 1);
CHECK(v[1 * width + 2] == 55);
CHECK(v[1 * width + 3] == 55);
CHECK(v[2 * width + 0] == 1);
CHECK(v[2 * width + 1] == 1);
CHECK(v[2 * width + 2] == 55);
CHECK(v[2 * width + 3] == 55);
CHECK(v[3 * width + 0] == 55);
CHECK(v[3 * width + 1] == 55);
CHECK(v[3 * width + 2] == 55);
CHECK(v[3 * width + 3] == 55);
CHECK(v[4 * width + 0] == 55);
CHECK(v[4 * width + 1] == 55);
CHECK(v[4 * width + 2] == 55);
CHECK(v[4 * width + 3] == 55);
}