Skip to content

Commit

Permalink
Fixed filtertest with the new normalize option
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Dec 15, 2023
1 parent 2324aff commit 665d71d
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions algorithms/test/filtertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,35 @@ TEST_CASE_TEMPLATE("filter", TypeParam, RasterFloatTypes)

SUBCASE("filterConstant")
{
// clang-format off
const Raster ras(RasterMetadata(2, 3, -1.0), convertTo<T>(std::vector<double>({
1, 1, 1,
1, 1, 2,
})));
const Raster ras(RasterMetadata(2, 3, -1.0), convertTo<T>(std::vector<double>({1, 1, 1,
1, 1, 2})));

const Raster expected(ras.metadata(), convertTo<T>(std::vector<double>({
1.0/3.0 + 1.0/4.0 + 1.0/3.0, 1.0/3.0 + 1.0/4.0 + 1.0/3.0 + 1.0 / 4.0, 1.0 / 4.0 + 1.0 / 3.0 + 2.0 / 3.0,
1.0/3.0 + 1.0/4.0 + 1.0/3.0, 1.0/3.0 + 1.0/4.0 + 2.0/3.0 + 1.0 / 4.0, 1.0 / 4.0 + 2.0 / 3.0 + 1.0 / 3.0,
})));
// clang-format on
SUBCASE("normalize = true")
{
// clang-format off
const Raster expected(ras.metadata(), convertTo<T>(std::vector<double>({
1.0/3.0 + 1.0/4.0 + 1.0/3.0, 1.0/3.0 + 1.0/4.0 + 1.0/3.0 + 1.0 / 4.0, 1.0 / 4.0 + 1.0 / 3.0 + 2.0 / 3.0,
1.0/3.0 + 1.0/4.0 + 1.0/3.0, 1.0/3.0 + 1.0/4.0 + 2.0/3.0 + 1.0 / 4.0, 1.0 / 4.0 + 2.0 / 3.0 + 1.0 / 3.0
})));
// clang-format on

auto actual = filter<Raster>(ras, FilterMode::Constant, 1, true);
CHECK_RASTER_NEAR_WITH_TOLERANCE(expected, actual, 10e-5);
CHECK(sum(actual) == Approx(sum(ras)).epsilon(10e-5));
}

SUBCASE("normalize = false")
{
// clang-format off
const Raster expected(ras.metadata(), convertTo<T>(std::vector<double>({
1.0 + 1.0 + 1.0, 1.0 + 1.0 + 1.0 + 1.0, 1.0 + 1.0 + 2.0 ,
1.0 + 1.0 + 1.0, 1.0 + 1.0 + 2.0 + 1.0, 1.0 + 2.0 + 1.0
})));
// clang-format on

auto actual = filter<Raster>(ras, FilterMode::Constant, 1, false);
CHECK_RASTER_NEAR_WITH_TOLERANCE(expected, actual, 10e-5);
CHECK(sum(actual) == Approx(sum(ras)).epsilon(10e-5));
auto actual = filter<Raster>(ras, FilterMode::Constant, 1, false);
CHECK_RASTER_NEAR_WITH_TOLERANCE(expected, actual, 10e-5);
}
}

SUBCASE("averageFilterSquare")
Expand Down

0 comments on commit 665d71d

Please sign in to comment.