diff --git a/src/io.jl b/src/io.jl index cfec539f..e028c5b9 100644 --- a/src/io.jl +++ b/src/io.jl @@ -115,3 +115,8 @@ getknots(X::AbstractExtrapolation) = getknots(parent(X)) Base.show(io::IO, ::MIME{Symbol("text/plain")}, X::ScaledInterpolation) = show_ranged(io, X, getknots(X)) Base.show(io::IO, ::MIME{Symbol("text/plain")}, X::GriddedInterpolation) = show_ranged(io, X, getknots(X)) Base.show(io::IO, ::MIME{Symbol("text/plain")}, X::AbstractExtrapolation) = show_ranged(io, X, getknots(X)) + +# these are called by show(X) +Base.show(io::IO, X::ScaledInterpolation) = show_ranged(io, X, getknots(X)) +Base.show(io::IO, X::GriddedInterpolation) = show_ranged(io, X, getknots(X)) +Base.show(io::IO, X::AbstractExtrapolation) = show_ranged(io, X, getknots(X)) diff --git a/test/io.jl b/test/io.jl index 0d58c89f..1f19a5b0 100644 --- a/test/io.jl +++ b/test/io.jl @@ -48,6 +48,10 @@ using Test show(io, MIME("text/plain"), itp) str = String(take!(io)) @test str == "4-element interpolate((0.0:0.1:0.3,), ::Array{Float64,1}, Gridded(Linear())) with element type Float64:\n 0.25\n 0.5 \n 0.75\n 1.0 " + io2 = IOBuffer() + show(io2, itp) + str2 = String(take!(io2)) + @test str2 == "4-element interpolate((0.0:0.1:0.3,), ::Array{Float64,1}, Gridded(Linear())) with element type Float64:\n 0.25\n 0.5 \n 0.75\n 1.0 " end @testset "scaled" begin @@ -58,6 +62,10 @@ using Test show(io, MIME("text/plain"), sitp) str = String(take!(io)) @test str == "10-element scale(interpolate(::Array{Float64,1}, BSpline(Linear())), (-3.0:0.5:1.5,)) with element type Float64:\n 1.0\n 2.0\n 3.0\n 4.0\n 5.0\n 6.0\n 7.0\n 8.0\n 9.0\n 10.0" + io2 = IOBuffer() + show(io2, sitp) + str2 = String(take!(io2)) + @test str2 == "10-element scale(interpolate(::Array{Float64,1}, BSpline(Linear())), (-3.0:0.5:1.5,)) with element type Float64:\n 1.0\n 2.0\n 3.0\n 4.0\n 5.0\n 6.0\n 7.0\n 8.0\n 9.0\n 10.0" gauss(phi, mu, sigma) = exp(-(phi-mu)^2 / (2sigma)^2) testfunction(x,y) = gauss(x, 0.5, 4) * gauss(y, -.5, 2) @@ -66,7 +74,12 @@ using Test zs = Float64[testfunction(x,y) for x in xs, y in ys] itp2 = interpolate(zs, BSpline(Quadratic(Flat(OnGrid())))) sitp2 = scale(itp2, xs, ys) - @test summary(sitp2) == "21×41 scale(interpolate(OffsetArray(::Array{Float64,2}, 0:22, 0:42), BSpline(Quadratic(Flat(OnGrid())))), (-5.0:0.5:5.0,$SPACE-4.0:0.2:4.0)) with element type Float64" + teststring = "21×41 scale(interpolate(OffsetArray(::Array{Float64,2}, 0:22, 0:42), BSpline(Quadratic(Flat(OnGrid())))), (-5.0:0.5:5.0,$SPACE-4.0:0.2:4.0)) with element type Float64" + @test summary(sitp2) == teststring + io3 = IOBuffer() + show(io3, sitp2) + str3 = String(take!(io3)) + @test occursin(teststring, str3) end @testset "Monotonic" begin @@ -81,10 +94,20 @@ using Test itpg = interpolate(A, BSpline(Linear())) etpg = extrapolate(itpg, Flat()) - @test summary(etpg) == "8×20 extrapolate(interpolate(::Array{Float64,2}, BSpline(Linear())), Flat()) with element type Float64" + teststring = "8×20 extrapolate(interpolate(::Array{Float64,2}, BSpline(Linear())), Flat()) with element type Float64" + @test summary(etpg) == teststring + io = IOBuffer() + show(io, etpg) + str = String(take!(io)) + @test occursin(teststring, str) etpf = extrapolate(itpg, NaN) - @test summary(etpf) == "8×20 extrapolate(interpolate(::Array{Float64,2}, BSpline(Linear())), NaN) with element type Float64" + teststring2 = "8×20 extrapolate(interpolate(::Array{Float64,2}, BSpline(Linear())), NaN) with element type Float64" + @test summary(etpf) == teststring2 + io2 = IOBuffer() + show(io2, etpf) + str2 = String(take!(io2)) + @test occursin(teststring2, str2) end @testset "Combinations" begin