|
116 | 116 | end |
117 | 117 | end |
118 | 118 | end |
119 | | -end |
120 | 119 |
|
| 120 | + @testset "Constant periodic" begin |
| 121 | + # Constructors |
| 122 | + @test Constant() === Constant(Throw(OnGrid())) |
| 123 | + @test Constant() isa Constant{Nearest,Throw{OnGrid}} |
| 124 | + @test Constant(Periodic()) === Constant(Periodic(OnCell())) |
| 125 | + @test Constant(Periodic()) isa Constant{Nearest,Periodic{OnCell}} |
| 126 | + for T in (Nearest, Previous, Next) |
| 127 | + it = Constant{T}() |
| 128 | + @test it isa Constant{T, Throw{OnGrid}} |
| 129 | + @test "$it" == "Constant{$T}()" |
| 130 | + it = Constant{T}(Periodic()) |
| 131 | + @test it isa Constant{T, Periodic{OnCell}} |
| 132 | + @test "$it" == "Constant{$T}(Periodic(OnCell()))" |
| 133 | + end |
| 134 | + |
| 135 | + for (constructor, copier) in ((interpolate, x -> x), (interpolate!, copy)) |
| 136 | + isinplace = constructor == interpolate! |
| 137 | + itp_periodic = @inferred(constructor(copier(A1), BSpline(Constant(Periodic())))) |
| 138 | + itp_previous = @inferred(constructor(copier(A1), BSpline(Constant{Previous}(Periodic())))) |
| 139 | + itp_next = @inferred(constructor(copier(A1), BSpline(Constant{Next}(Periodic())))) |
| 140 | + |
| 141 | + for itp in (itp_periodic, itp_previous, itp_next) |
| 142 | + @test parent(itp) === itp.coefs |
| 143 | + @test all(Interpolations.lbounds(itp) .≈ (0.5,)) |
| 144 | + @test all(Interpolations.ubounds(itp) .≈ (N1 + 0.5,)) |
| 145 | + |
| 146 | + check_axes(itp, A1, isinplace) |
| 147 | + check_inbounds_values(itp, A1) |
| 148 | + check_oob(itp) |
| 149 | + can_eval_near_boundaries(itp) |
| 150 | + end |
| 151 | + |
| 152 | + # Evaluation between data points (tests constancy) |
| 153 | + for i in 2:N1-1 |
| 154 | + @test A1[i] == itp_periodic(i + .3) == itp_periodic(i - .3) |
| 155 | + @test A1[i] == itp_previous(i + .3) == itp_previous(i + .6) |
| 156 | + @test A1[i - 1] == itp_previous(i - .3) == itp_previous(i - .6) |
| 157 | + @test A1[i + 1] == itp_next(i + .3) == itp_next(i + .6) |
| 158 | + @test A1[i] == itp_next(i - .3) == itp_next(i - .6) |
| 159 | + end |
| 160 | + |
| 161 | + # Evaluation between data points in [0.5, 1.5], [N1 - 0.5, N1 + 0.5]. |
| 162 | + @test A1[1] == itp_periodic(1 - .3) == itp_periodic(1 + .3) |
| 163 | + @test A1[N1] == itp_periodic(N1 - .3) == itp_periodic(N1 + .3) |
| 164 | + @test A1[1] == itp_previous(1 + .3) |
| 165 | + @test A1[N1] == itp_previous(N1 + .3) == itp_previous(1 - .3) |
| 166 | + @test A1[1] == itp_next(1 - .3) == itp_next(N1 + .3) |
| 167 | + @test A1[N1] == itp_next(N1 - .3) |
| 168 | + end |
| 169 | + end |
| 170 | +end |
0 commit comments