Skip to content

Commit

Permalink
test: test passing nothing to u0 for all system types
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Sep 19, 2024
1 parent 861247e commit 9435576
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
8 changes: 8 additions & 0 deletions test/discrete_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,11 @@ end
k = ShiftIndex(t)
@named sys = DiscreteSystem([x ~ x^2 + y^2, y ~ x(k - 1) + y(k - 1)], t)
@test_throws ["algebraic equations", "not yet supported"] structural_simplify(sys)

@testset "Passing `nothing` to `u0`" begin
@variables x(t) = 1
k = ShiftIndex()
@mtkbuild sys = DiscreteSystem([x(k) ~ x(k - 1) + 1], t)
prob = @test_nowarn DiscreteProblem(sys, nothing, (0.0, 1.0))
@test_nowarn solve(prob, FunctionMap())
end
7 changes: 7 additions & 0 deletions test/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,10 @@ sys = structural_simplify(ns; conservative = true)
sol = solve(prob, NewtonRaphson())
@test sol[x] sol[y] sol[z] -3
end

@testset "Passing `nothing` to `u0`" begin
@variables x = 1
@mtkbuild sys = NonlinearSystem([0 ~ x^2 - x^3 + 3])
prob = @test_nowarn NonlinearProblem(sys, nothing)
@test_nowarn solve(prob)
end
2 changes: 1 addition & 1 deletion test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ end

@testset "Passing `nothing` to `u0`" begin
@variables x(t) = 1
@mtkbuild sys = ODEProblem(D(x) ~ t, t)
@mtkbuild sys = ODESystem(D(x) ~ t, t)
prob = @test_nowarn ODEProblem(sys, nothing, (0.0, 1.0))
@test_nowarn solve(prob)
end
7 changes: 7 additions & 0 deletions test/optimizationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,10 @@ end
prob.f.cons_h(H3, [1.0, 1.0], [1.0, 100.0])
@test prob.f.cons_h([1.0, 1.0], [1.0, 100.0]) == H3
end

@testset "Passing `nothing` to `u0`" begin
@variables x = 1.0
@mtkbuild sys = OptimizationSystem((x - 3)^2, [x], [])
prob = @test_nowarn OptimizationProblem(sys, nothing)
@test_nowarn solve(prob, NelderMead())
end
8 changes: 8 additions & 0 deletions test/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -776,3 +776,11 @@ end
prob = SDEProblem(de, u0map, (0.0, 100.0), parammap)
@test solve(prob, SOSRI()).retcode == ReturnCode.Success
end

@testset "Passing `nothing` to `u0`" begin
@variables x(t) = 1
@brownian b
@mtkbuild sys = System([D(x) ~ x + b], t)
prob = @test_nowarn SDEProblem(sys, nothing, (0.0, 1.0))
@test_nowarn solve(prob, ImplicitEM())
end

0 comments on commit 9435576

Please sign in to comment.