From 070700b0caa01cfbe66935129fed94330c8dcd29 Mon Sep 17 00:00:00 2001 From: apmypb Date: Mon, 9 Sep 2024 14:25:33 +0200 Subject: [PATCH] Add meaningful tests --- test/test_alternative_filters.jl | 81 ++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/test/test_alternative_filters.jl b/test/test_alternative_filters.jl index 2e09853..ff33be1 100644 --- a/test/test_alternative_filters.jl +++ b/test/test_alternative_filters.jl @@ -16,7 +16,32 @@ using Unitful # apply filter to signal @test_nowarn flt(wf) - @test isapprox(wf.signal[end], flt(wf).signal[end]; rtol=reltol) + + x = vcat(zeros(10), 10*ones(10)) + flt = WeightedSavitzkyGolayFilter(5, 4, 2) + res = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.4807384272286174e-15, + 1.592621449357092e-15, + 9.999999999999998, + 9.999999999999996, + 9.999999999999998, + 9.999999999999998, + 9.999999999999998, + 9.999999999999998, + 9.999999999999998, + 9.999999999999998, + 9.999999999999998, + 10.000000000000002 + ] + @test isapprox(res, flt(x)) end @testset "Test ModifiedSincFilter" begin @@ -31,7 +56,32 @@ end # apply filter to signal @test_nowarn flt(wf) - @test isapprox(wf.signal[end], flt(wf).signal[end]; rtol=reltol) + + x = vcat(zeros(10), 10*ones(10)) + flt = ModifiedSincFilter(2, 3) + res = [ + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -0.548368134165832, + 1.1885440629944422, + 1.1885440629944422, + 8.701152183830784, + 8.701152183830784, + 10.438064380991058, + 9.889696246825226, + 9.889696246825226, + 9.889696246825226, + 9.889696246825226, + 9.889696246825226, + 9.889696246825226, + 9.889696246825226 + ] + @test isapprox(res, flt(x)) end @testset "Test WhittakerHendersonFilter" begin @@ -46,5 +96,30 @@ end # apply filter to signal @test_nowarn flt(wf) - @test isapprox(wf.signal[end], flt(wf).signal[end]; rtol=reltol) + + x = vcat(zeros(10), 10*ones(10)) + flt = WhittakerHendersonFilter(p = 3) + res = [ + -0.02773818585540094, + 0.012639233969518396, + 0.06203483300722407, + 0.09271042540231514, + 0.03409068755810708, + -0.18030096074202678, + -0.4731960498109986, + -0.4498440659762424, + 0.5954235817600229, + 3.199433545249531, + 6.800566454750464, + 9.404576418239975, + 10.449844065976244, + 10.473196049810994, + 10.180300960742013, + 9.96590931244188, + 9.907289574597682, + 9.937965166992784, + 9.987360766030491, + 10.0277381858554 + ] + @test isapprox(res, flt(x)) end \ No newline at end of file