Skip to content

Commit

Permalink
Add meaningful tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apmypb committed Sep 9, 2024
1 parent 18d876c commit 070700b
Showing 1 changed file with 78 additions and 3 deletions.
81 changes: 78 additions & 3 deletions test/test_alternative_filters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 070700b

Please sign in to comment.