Skip to content

Commit 7b1065e

Browse files
committed
add test for max filter
1 parent 59d55e9 commit 7b1065e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

test/APRTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,6 +3270,19 @@ bool test_min_filter(TestData &test_data) {
32703270
}
32713271

32723272

3273+
template<int size_y, int size_x, int size_z>
3274+
bool test_max_filter(TestData &test_data) {
3275+
3276+
ParticleData<float> output;
3277+
APRFilter::max_filter<size_y, size_x, size_z>(test_data.apr, test_data.particles_intensities, output);
3278+
3279+
ParticleData<float> output_gt;
3280+
FilterTestHelpers::compute_max_filter_gt(test_data.apr, test_data.particles_intensities, output_gt, size_y, size_x, size_z);
3281+
3282+
return compareParticles(output_gt, output) == 0;
3283+
}
3284+
3285+
32733286
bool test_convolve_pencil(TestData &test_data, const bool boundary = false, const std::vector<int>& stencil_size = {3, 3, 3}) {
32743287

32753288
auto it = test_data.apr.iterator();
@@ -4356,6 +4369,12 @@ TEST_F(CreateDiffDimsSphereTest, APR_FILTER) {
43564369
success1D = test_min_filter<7, 1, 1>(test_data);
43574370
ASSERT_TRUE(success3D && success2D && success1D);
43584371

4372+
// Max filter
4373+
success3D = test_max_filter<7, 5, 3>(test_data);
4374+
success2D = test_max_filter<5, 3, 1>(test_data);
4375+
success1D = test_max_filter<7, 1, 1>(test_data);
4376+
ASSERT_TRUE(success3D && success2D && success1D);
4377+
43594378
}
43604379

43614380
TEST_F(CreateAPRTest, READ_PARTICLE_TYPE){

test/FilterTestHelpers.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ T compute_median(std::vector<T>& input) {
2020
}
2121

2222
template<typename T>
23-
T compute_min(std::vector<T>& input){
23+
T compute_min(std::vector<T>& input) {
2424
return *std::min_element(input.begin(), input.end());
25+
}
2526

27+
template<typename T>
28+
T compute_max(std::vector<T>& input) {
29+
return *std::max_element(input.begin(), input.end());
2630
}
2731

32+
2833
namespace FilterTestHelpers {
2934

3035
template<typename InputType, typename StencilType, typename OutputType>
@@ -73,6 +78,20 @@ namespace FilterTestHelpers {
7378
compute_generic_filter_gt(apr, input_particles, tree_particles, output_particles, size_y, size_x, size_z, true, compute_min);
7479
}
7580

81+
82+
template<typename InputType, typename OutputType>
83+
void compute_max_filter_gt(APR& apr,
84+
ParticleData<InputType>& input_particles,
85+
ParticleData<OutputType>& output_particles,
86+
int size_y,
87+
int size_x,
88+
int size_z) {
89+
90+
ParticleData<OutputType> tree_particles;
91+
APRTreeNumerics::fill_tree_max(apr, input_particles, tree_particles);
92+
compute_generic_filter_gt(apr, input_particles, tree_particles, output_particles, size_y, size_x, size_z, true, compute_max);
93+
}
94+
7695
}
7796

7897

0 commit comments

Comments
 (0)