|
| 1 | +module IOTests |
| 2 | + |
| 3 | +using Base.Test |
| 4 | +using Interpolations |
| 5 | + |
| 6 | +SPACE = if VERSION < v"0.6.0-dev.2505" # julia PR #20288 |
| 7 | + "" |
| 8 | +else |
| 9 | + " " |
| 10 | +end |
| 11 | + |
| 12 | +@testset "BSpline" begin |
| 13 | + A = rand(8,20) |
| 14 | + |
| 15 | + itp = interpolate(A, BSpline(Constant()), OnCell()) |
| 16 | + @test summary(itp) == "8×20 interpolate(::Array{Float64,2}, BSpline(Constant()), OnCell()) with element type Float64" |
| 17 | + |
| 18 | + itp = interpolate(A, BSpline(Constant()), OnGrid()) |
| 19 | + @test summary(itp) == "8×20 interpolate(::Array{Float64,2}, BSpline(Constant()), OnGrid()) with element type Float64" |
| 20 | + |
| 21 | + itp = interpolate(A, BSpline(Linear()), OnGrid()) |
| 22 | + @test summary(itp) == "8×20 interpolate(::Array{Float64,2}, BSpline(Linear()), OnGrid()) with element type Float64" |
| 23 | + |
| 24 | + itp = interpolate(A, BSpline(Quadratic(Reflect())), OnCell()) |
| 25 | + @test summary(itp) == "8×20 interpolate(::Array{Float64,2}, BSpline(Quadratic(Reflect())), OnCell()) with element type Float64" |
| 26 | + |
| 27 | + itp = interpolate(A, (BSpline(Linear()), NoInterp()), OnGrid()) |
| 28 | + @test summary(itp) == "8×20 interpolate(::Array{Float64,2}, (BSpline(Linear()), NoInterp()), OnGrid()) with element type Float64" |
| 29 | + |
| 30 | + itp = interpolate!(copy(A), BSpline(Quadratic(InPlace())), OnCell()) |
| 31 | + @test summary(itp) == "8×20 interpolate(::Array{Float64,2}, BSpline(Quadratic(InPlace())), OnCell()) with element type Float64" |
| 32 | +end |
| 33 | + |
| 34 | +@testset "Gridded" begin |
| 35 | + A = rand(20) |
| 36 | + A_x = collect(1.0:2.0:40.0) |
| 37 | + knots = (A_x,) |
| 38 | + itp = interpolate(knots, A, Gridded(Linear())) |
| 39 | + @test summary(itp) == "20-element interpolate((::Array{Float64,1},), ::Array{Float64,1}, Gridded(Linear())) with element type Float64" |
| 40 | + |
| 41 | + A = rand(8,20) |
| 42 | + knots = ([x^2 for x = 1:8], [0.2y for y = 1:20]) |
| 43 | + itp = interpolate(knots, A, Gridded(Linear())) |
| 44 | + @test summary(itp) == "8×20 interpolate((::Array{Int64,1},::Array{Float64,1}), ::Array{Float64,2}, Gridded(Linear())) with element type Float64" |
| 45 | + |
| 46 | + itp = interpolate(knots, A, (Gridded(Linear()),Gridded(Constant()))) |
| 47 | + @test summary(itp) == "8×20 interpolate((::Array{Int64,1},::Array{Float64,1}), ::Array{Float64,2}, (Gridded(Linear()), Gridded(Constant()))) with element type Float64" |
| 48 | +end |
| 49 | + |
| 50 | +@testset "scaled" begin |
| 51 | + itp = interpolate(1:1.0:10, BSpline(Linear()), OnGrid()) |
| 52 | + sitp = scale(itp, -3:.5:1.5) |
| 53 | + @test summary(sitp) == "10-element scale(interpolate(::Array{Float64,1}, BSpline(Linear()), OnGrid()), (-3.0:0.5:1.5,)) with element type Float64" |
| 54 | + |
| 55 | + gauss(phi, mu, sigma) = exp(-(phi-mu)^2 / (2sigma)^2) |
| 56 | + testfunction(x,y) = gauss(x, 0.5, 4) * gauss(y, -.5, 2) |
| 57 | + xs = -5:.5:5 |
| 58 | + ys = -4:.2:4 |
| 59 | + zs = Float64[testfunction(x,y) for x in xs, y in ys] |
| 60 | + itp2 = interpolate(zs, BSpline(Quadratic(Flat())), OnGrid()) |
| 61 | + sitp2 = scale(itp2, xs, ys) |
| 62 | + @test summary(sitp2) == "21×41 scale(interpolate(::Array{Float64,2}, BSpline(Quadratic(Flat())), OnGrid()), (-5.0:0.5:5.0,$SPACE-4.0:0.2:4.0)) with element type Float64" |
| 63 | +end |
| 64 | + |
| 65 | +@testset "Extrapolation" begin |
| 66 | + A = rand(8,20) |
| 67 | + |
| 68 | + itpg = interpolate(A, BSpline(Linear()), OnGrid()) |
| 69 | + etpg = extrapolate(itpg, Flat()) |
| 70 | + @test summary(etpg) == "8×20 extrapolate(interpolate(::Array{Float64,2}, BSpline(Linear()), OnGrid()), Flat()) with element type Float64" |
| 71 | + |
| 72 | + etpf = extrapolate(itpg, NaN) |
| 73 | + @test summary(etpf) == "8×20 extrapolate(interpolate(::Array{Float64,2}, BSpline(Linear()), OnGrid()), NaN) with element type Float64" |
| 74 | +end |
| 75 | + |
| 76 | + |
| 77 | +end # Module |
0 commit comments