Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Mar 22, 2024
1 parent 7d673c2 commit c1d2270
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Pkg", "PyCall", "PythonCall", "SafeTestsets", "Test", "StaticArrays", "StochasticDiffEq", "Aqua", "Zygote", "PartialFunctions", "DataFrames", "ModelingToolkit", "OrdinaryDiffEq"]
test = ["Pkg", "Plots", "UnicodePlots", "PyCall", "PythonCall", "SafeTestsets", "Test", "StaticArrays", "StochasticDiffEq", "Aqua", "Zygote", "PartialFunctions", "DataFrames", "ModelingToolkit", "OrdinaryDiffEq"]
3 changes: 2 additions & 1 deletion src/solutions/solution_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,10 @@ function solplot_vecs_and_labels(dims, vars, plott, sol, plot_analytic,
push!(strs, "u[$(x[j])]")
end
else
global Main.debug[] = plot_analytic_timeseries
_tmp = Vector{eltype(sol[1])}(undef, length(plot_analytic_timeseries))
for n in 1:length(plot_analytic_timeseries)
_tmp[n] = plot_analytic_timeseries[n][j]
_tmp[n] = plot_analytic_timeseries[n][x[j]]

Check warning on line 496 in src/solutions/solution_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/solution_interface.jl#L493-L496

Added lines #L493 - L496 were not covered by tests
end
push!(tmp, _tmp)
if !isempty(varsyms) && x[j] isa Integer
Expand Down
24 changes: 24 additions & 0 deletions test/downstream/solution_interface.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ModelingToolkit, OrdinaryDiffEq, RecursiveArrayTools, StochasticDiffEq, Test
using ModelingToolkit: t_nounits as t, D_nounits as D
using Plots: Plots, plot

### Tests on non-layered model (everything should work). ###

Expand All @@ -25,6 +26,29 @@ sol = solve(oprob, Rodas4())
@test_throws Exception sol[population_model.a]
@test_throws Exception sol[:a]

@testset "plot ODE solution" begin
Plots.unicodeplots()
f = ODEFunction((u, p, t) -> -u, analytic = (u0, p, t) -> u0 * exp(-t))

# scalar
ode = ODEProblem(f, 1.0, (0.0, 1.0))
sol = solve(ode, Tsit5())
@test_nowarn plot(sol)
@test_nowarn plot(sol; plot_analytic = true)

# vector
ode = ODEProblem(f, [1.0, 2.0], (0.0, 1.0))
sol = solve(ode, Tsit5())
@test_nowarn plot(sol)
@test_nowarn plot(sol; plot_analytic = true)

# matrix
ode = ODEProblem(f, [1.0, 2.0; 3.0, 4.0], (0.0, 1.0))
sol = solve(ode, Tsit5())
@test_nowarn plot(sol)
@test_nowarn plot(sol; plot_analytic = true)
end

# Tests on SDEProblem
noiseeqs = [0.1 * s1,
0.1 * s2]
Expand Down

0 comments on commit c1d2270

Please sign in to comment.