diff --git a/Project.toml b/Project.toml index c333c51..f84578b 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.0.1, 0.1" SciMLBase = "2.152, 3" +SciMLTesting = "1" Test = "1" julia = "1.10" [extras] OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283" 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", "SafeTestsets", "SciMLTesting"] diff --git a/test/inplace_ode.jl b/test/inplace_ode.jl new file mode 100644 index 0000000..e190d16 --- /dev/null +++ b/test/inplace_ode.jl @@ -0,0 +1,15 @@ +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] + +integrator = init(prob_ip, Tsit5()) +ts = [0.0, 0.5, 1.0] +iter = TimeChoiceIterator(integrator, ts) +results = collect(iter) +@test length(results) == 3 diff --git a/test/integrator_intervals.jl b/test/integrator_intervals.jl new file mode 100644 index 0000000..a0c7172 --- /dev/null +++ b/test/integrator_intervals.jl @@ -0,0 +1,13 @@ +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) + global count += 1 + @test t > tprev || count == 1 # first step tprev == t == 0 + @test t >= 0.0 +end +@test count > 0 diff --git a/test/integrator_tuples.jl b/test/integrator_tuples.jl new file mode 100644 index 0000000..497d396 --- /dev/null +++ b/test/integrator_tuples.jl @@ -0,0 +1,13 @@ +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 (u, t) in tuples(integrator) + global count += 1 + @test t >= 0.0 + @test t <= 1.0 + eps() +end +@test count > 0 diff --git a/test/qa/Project.toml b/test/qa/Project.toml index a3a1e9a..6f273e2 100644 --- a/test/qa/Project.toml +++ b/test/qa/Project.toml @@ -1,7 +1,9 @@ [deps] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" SciMLIterators = "efe4dcdd-3aed-4391-894d-a9dbd16a2f14" +SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [sources] @@ -10,5 +12,7 @@ SciMLIterators = {path = "../.."} [compat] Aqua = "0.8" JET = "0.9,0.10,0.11" +SafeTestsets = "0.0.1, 0.1" +SciMLTesting = "1" Test = "1" julia = "1.10" diff --git a/test/runtests.jl b/test/runtests.jl index fb1dec7..a18a7cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,75 +1,2 @@ -using Test -using SciMLIterators -using OrdinaryDiffEq - -const GROUP = get(ENV, "GROUP", "All") - -if GROUP == "All" || GROUP == "Core" - @testset "SciMLIterators.jl" begin - # Simple ODE: du/dt = -u - 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 - - @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 - 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 - 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 - 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()) - - 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 - end -end - -if GROUP == "QA" - include(joinpath(@__DIR__, "qa", "qa.jl")) -end +using SciMLTesting +run_tests() diff --git a/test/solution_tuples.jl b/test/solution_tuples.jl new file mode 100644 index 0000000..368232d --- /dev/null +++ b/test/solution_tuples.jl @@ -0,0 +1,10 @@ +using SciMLIterators, OrdinaryDiffEq, Test + +f(u, p, t) = -u +prob = ODEProblem(f, 1.0, (0.0, 1.0)) + +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]) diff --git a/test/time_choice_iterator.jl b/test/time_choice_iterator.jl new file mode 100644 index 0000000..87c2562 --- /dev/null +++ b/test/time_choice_iterator.jl @@ -0,0 +1,14 @@ +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