Skip to content

Commit 932b4d8

Browse files
committed
Better test cases
1 parent 370631f commit 932b4d8

3 files changed

Lines changed: 35 additions & 34 deletions

File tree

lib/BoundaryValueDiffEqCore/test/runtests.jl

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,4 @@ using InteractiveUtils, Test
1111
Aqua.test_piracies(BoundaryValueDiffEqCore)
1212
Aqua.test_ambiguities(BoundaryValueDiffEqCore; recursive = false)
1313
end
14-
15-
@testset "__extract_lcons_ucons length" begin
16-
# Regression test: the function must return vectors matching the actual
17-
# constraint vector length (= length(resid_prototype)), not a reconstruction
18-
# from (M, N, ...) which was wrong for several solvers.
19-
using BoundaryValueDiffEqCore: __extract_lcons_ucons
20-
using SciMLBase: BVProblem
21-
22-
f!(du, u, p, t) = (du[1] = u[2]; du[2] = -u[1])
23-
bc!(res, u, p, t) = (res[1] = u(0.0)[1]; res[2] = u(1.0)[1])
24-
25-
# Fallback path (isnothing(prob.lcons)): both vectors have length == constraint_length
26-
prob = BVProblem(f!, bc!, [0.0, 0.0], (0.0, 1.0); bcresid_prototype = zeros(2))
27-
lc, uc = __extract_lcons_ucons(prob, Float64, 42)
28-
@test length(lc) == 42
29-
@test length(uc) == 42
30-
@test all(iszero, lc)
31-
@test all(iszero, uc)
32-
33-
# User-provided lcons/ucons: values preserved, padded with zeros to constraint_length
34-
prob2 = BVProblem(f!, bc!, [0.0, 0.0], (0.0, 1.0);
35-
bcresid_prototype = zeros(2),
36-
lcons = [-1.0, -2.0], ucons = [1.0, 2.0])
37-
lc2, uc2 = __extract_lcons_ucons(prob2, Float64, 10)
38-
@test length(lc2) == 10
39-
@test length(uc2) == 10
40-
@test lc2[1:2] == [-1.0, -2.0]
41-
@test uc2[1:2] == [1.0, 2.0]
42-
@test all(iszero, lc2[3:end])
43-
@test all(iszero, uc2[3:end])
44-
end
4514
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@testset "__extract_lcons_ucons length" begin
2+
# Regression test: the function must return vectors matching the actual
3+
# constraint vector length (= length(resid_prototype)), not a reconstruction
4+
# from (M, N, ...) which was wrong for several solvers.
5+
using BoundaryValueDiffEqCore: __extract_lcons_ucons
6+
using SciMLBase: BVProblem
7+
8+
f!(du, u, p, t) = (du[1] = u[2]; du[2] = -u[1])
9+
bc!(res, u, p, t) = (res[1] = u(0.0)[1]; res[2] = u(1.0)[1])
10+
11+
# Fallback path (isnothing(prob.lcons)): both vectors have length == constraint_length
12+
prob = BVProblem(f!, bc!, [0.0, 0.0], (0.0, 1.0); bcresid_prototype = zeros(2))
13+
lc, uc = __extract_lcons_ucons(prob, Float64, 42)
14+
@test length(lc) == 42
15+
@test length(uc) == 42
16+
@test all(iszero, lc)
17+
@test all(iszero, uc)
18+
19+
# User-provided lcons/ucons: values preserved, padded with zeros to constraint_length
20+
prob2 = BVProblem(
21+
f!, bc!, [0.0, 0.0], (0.0, 1.0);
22+
bcresid_prototype = zeros(2),
23+
lcons = [-1.0, -2.0], ucons = [1.0, 2.0]
24+
)
25+
lc2, uc2 = __extract_lcons_ucons(prob2, Float64, 10)
26+
@test length(lc2) == 10
27+
@test length(uc2) == 10
28+
@test lc2[1:2] == [-1.0, -2.0]
29+
@test uc2[1:2] == [1.0, 2.0]
30+
@test all(iszero, lc2[3:end])
31+
@test all(iszero, uc2[3:end])
32+
end

lib/BoundaryValueDiffEqMIRK/test/mirk_basic_tests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ end
648648
@test_nowarn sol = solve(prob, MIRK4(; optimize = IpoptOptimizer()), dt = 0.05)
649649
end
650650

651+
# https://github.com/SciML/BoundaryValueDiffEq.jl/pull/473
651652
@testitem "StandardBVProblem optimize path without user lcons/ucons" begin
652653
# Regression test: previously, `__extract_lcons_ucons` in the Nothing-
653654
# f_prototype dispatch returned vectors of length N*M (decision-variable
@@ -662,13 +663,12 @@ end
662663
du[2] = -9.81 * sin(u[1])
663664
end
664665
function bc!(residual, u, p, t)
665-
residual[1] = u(0.0)[1] - pi / 2
666+
residual[1] = u(pi / 4)[1] + pi / 2
666667
residual[2] = u(pi / 2)[1] - pi / 2
667668
end
668669
# StandardBVProblem, no lcons/ucons — hits the fallback branch.
669670
prob = BVProblem(
670-
simplependulum!, bc!, [pi / 2, pi / 2], tspan;
671-
bcresid_prototype = zeros(2)
671+
simplependulum!, bc!, [pi / 2, pi / 2], tspan
672672
)
673673
@test_nowarn solve(prob, MIRK4(; optimize = IpoptOptimizer()), dt = 0.05)
674674
end

0 commit comments

Comments
 (0)