Skip to content

Commit

Permalink
Add tests for recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
oashour committed Feb 9, 2021
1 parent 9af4449 commit ba9a8f2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
x, δN
end
else
@error "Unknown Plotting Mode for NonlinearSchrodinger.jl Objects" mode
@error "Unknown Plotting Mode for NonlinearSchrodinger.jl Objects $mode"
end

return nothing
Expand Down
45 changes: 44 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NonlinearSchrodinger
using RecipesBase
using Test

@testset "NonlinearSchrodinger.jl" begin
Expand Down Expand Up @@ -131,7 +132,6 @@ using Test
# Test the solution is mirrored across the x=0 axis
@test abs.(calc.ψ[:,2]) abs.(calc.ψ[:,1])
end

end

# Simulation Tests using Solitons (easiest way to check validity)
Expand Down Expand Up @@ -181,4 +181,47 @@ using Test
@test abs.(sim.ψ[175:end, end]) abs.(ψ₀[175:end]) atol=5e-2
end
end
@testset "Plot Recipes" begin
λ = 0.75im
T = 20
xᵣ = 0=>1
box = Box(xᵣ, T, dx=1e-3, Nₜ = 256, n_periods = 1)
ψ₀ = Array{Complex{Float64}}(undef, box.Nₜ)
ψ₀ .= 2*imag(λ)./cosh.(2*imag(λ).*box.t)
sim = Sim(λ, box, ψ₀, T1A!)
solve!(sim)
compute_IoM!(sim)
xₛ = Int(ceil(sim.box.Nₓ/500))
tₛ = Int(ceil(sim.box.Nₜ/500))
x_ax = sim.box.t[1:tₛ:end]
y_ax = sim.box.x[1:xₛ:end]
ω_ax = sim.box.ω[1:tₛ:end]
ψ = sim.ψ[1:tₛ:end, 1:xₛ:end]
ψ̃ = sim.ψ̃[1:tₛ:end, 1:xₛ:end]

# Test plotting ψ
rec = RecipesBase.apply_recipe(Dict{Symbol, Any}(), sim, )
@test getfield(rec[1], 2)[1] == x_ax
@test getfield(rec[1], 2)[2] == y_ax
@test getfield(rec[1], 2)[3] == abs.(ψ')

# Test plotting ψ̃
rec = RecipesBase.apply_recipe(Dict{Symbol, Any}(), sim, :ψ̃)
@test getfield(rec[1], 2)[1] == y_ax
rec = RecipesBase.apply_recipe(Dict{Symbol, Any}(:seriestype => :heatmap), sim, :ψ̃)
@test getfield(rec[1], 2)[1] == ω_ax
@test getfield(rec[1], 2)[2] == y_ax
@test getfield(rec[1], 2)[3] == log.(abs.(ψ̃'))

# Test plotting IoM
rec = RecipesBase.apply_recipe(Dict{Symbol, Any}(), sim, :IoM)
@test getfield(rec[1], 2)[1] == y_ax
@test getfield(rec[2], 2)[1] == y_ax
@test getfield(rec[3], 2)[1] == y_ax
@test getfield(rec[4], 2)[1] == y_ax

# Test Error
@test_logs (:error, "Unknown Plotting Mode for NonlinearSchrodinger.jl Objects IoMM") RecipesBase.apply_recipe(Dict{Symbol, Any}(), sim, :IoMM)

end
end

0 comments on commit ba9a8f2

Please sign in to comment.