diff --git a/Project.toml b/Project.toml index c333c51..2b7fdcc 100644 --- a/Project.toml +++ b/Project.toml @@ -10,15 +10,17 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" [compat] OrdinaryDiffEq = "6, 7" RecursiveArrayTools = "3, 4" +SafeTestsets = "0.1, 1" SciMLBase = "2.152, 3" Test = "1" julia = "1.10" [extras] OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" [targets] -test = ["Test", "OrdinaryDiffEq", "Aqua", "JET"] +test = ["Test", "OrdinaryDiffEq", "Aqua", "JET", "SafeTestsets"] diff --git a/test/runtests.jl b/test/runtests.jl index fb1dec7..a9515e5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,75 +1,84 @@ -using Test -using SciMLIterators -using OrdinaryDiffEq +using SafeTestsets, Test const GROUP = get(ENV, "GROUP", "All") if GROUP == "All" || GROUP == "Core" - @testset "SciMLIterators.jl" begin - # Simple ODE: du/dt = -u + @safetestset "Solution tuples" begin + using SciMLIterators, OrdinaryDiffEq, Test f(u, p, t) = -u prob = ODEProblem(f, 1.0, (0.0, 1.0)) - @testset "Solution tuples" begin - sol = solve(prob, Tsit5()) - tups = tuples(sol) - @test length(tups) == length(sol.u) - @test tups[1] == (sol.u[1], sol.t[1]) - @test tups[end] == (sol.u[end], sol.t[end]) - end + sol = solve(prob, Tsit5()) + tups = tuples(sol) + @test length(tups) == length(sol.u) + @test tups[1] == (sol.u[1], sol.t[1]) + @test tups[end] == (sol.u[end], sol.t[end]) + end + + @safetestset "Integrator tuples" begin + using SciMLIterators, OrdinaryDiffEq, Test + f(u, p, t) = -u + prob = ODEProblem(f, 1.0, (0.0, 1.0)) - @testset "Integrator tuples" begin - integrator = init(prob, Tsit5()) - count = 0 - for (u, t) in tuples(integrator) - count += 1 - @test t >= 0.0 - @test t <= 1.0 + eps() - end - @test count > 0 + integrator = init(prob, Tsit5()) + count = 0 + for (u, t) in tuples(integrator) + count += 1 + @test t >= 0.0 + @test t <= 1.0 + eps() end + @test count > 0 + end - @testset "Integrator intervals" begin - integrator = init(prob, Tsit5()) - count = 0 - for (uprev, tprev, u, t) in intervals(integrator) - count += 1 - @test t > tprev || count == 1 # first step tprev == t == 0 - @test t >= 0.0 - end - @test count > 0 + @safetestset "Integrator intervals" begin + using SciMLIterators, OrdinaryDiffEq, Test + f(u, p, t) = -u + prob = ODEProblem(f, 1.0, (0.0, 1.0)) + + integrator = init(prob, Tsit5()) + count = 0 + for (uprev, tprev, u, t) in intervals(integrator) + count += 1 + @test t > tprev || count == 1 # first step tprev == t == 0 + @test t >= 0.0 end + @test count > 0 + end - @testset "TimeChoiceIterator" begin - integrator = init(prob, Tsit5()) - ts = 0.0:0.25:1.0 - iter = TimeChoiceIterator(integrator, ts) - @test length(iter) == length(ts) - results = collect(iter) - @test length(results) == length(ts) - for ((u, t), t_expected) in zip(results, ts) - @test t == t_expected - end + @safetestset "TimeChoiceIterator" begin + using SciMLIterators, OrdinaryDiffEq, Test + f(u, p, t) = -u + prob = ODEProblem(f, 1.0, (0.0, 1.0)) + + integrator = init(prob, Tsit5()) + ts = 0.0:0.25:1.0 + iter = TimeChoiceIterator(integrator, ts) + @test length(iter) == length(ts) + results = collect(iter) + @test length(results) == length(ts) + for ((u, t), t_expected) in zip(results, ts) + @test t == t_expected end + end - @testset "Inplace ODE" begin - f!(du, u, p, t) = (du .= -u) - prob_ip = ODEProblem(f!, [1.0, 2.0], (0.0, 1.0)) - sol = solve(prob_ip, Tsit5()) + @safetestset "Inplace ODE" begin + using SciMLIterators, OrdinaryDiffEq, Test + f!(du, u, p, t) = (du .= -u) + prob_ip = ODEProblem(f!, [1.0, 2.0], (0.0, 1.0)) + sol = solve(prob_ip, Tsit5()) - tups = tuples(sol) - @test length(tups) == length(sol.u) - @test tups[1][1] == sol.u[1] + tups = tuples(sol) + @test length(tups) == length(sol.u) + @test tups[1][1] == sol.u[1] - integrator = init(prob_ip, Tsit5()) - ts = [0.0, 0.5, 1.0] - iter = TimeChoiceIterator(integrator, ts) - results = collect(iter) - @test length(results) == 3 - end + integrator = init(prob_ip, Tsit5()) + ts = [0.0, 0.5, 1.0] + iter = TimeChoiceIterator(integrator, ts) + results = collect(iter) + @test length(results) == 3 end end if GROUP == "QA" - include(joinpath(@__DIR__, "qa", "qa.jl")) + @safetestset "Quality Assurance" include(joinpath(@__DIR__, "qa", "qa.jl")) end