From ea92243065506022a0d357ce9400e9ef064d7fd1 Mon Sep 17 00:00:00 2001 From: mnshkw Date: Wed, 4 Mar 2026 04:57:26 +0900 Subject: [PATCH 1/7] TEST(refactor): move `using QuantEcon` out of @testset and replace `QuantEcon.LQ` with `LQ` --- test/runtests.jl | 2 +- test/test_cdp.jl | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7177bb8..03289ed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using LinearAlgebra using ContinuousDPs -using QuantEcon: PFI, VFI, solve, stationary_values, qnwnorm +using QuantEcon: PFI, VFI, solve, stationary_values, qnwnorm, LQ using BasisMatrices: Basis, ChebParams, SplineParams, LinParams, nodes using Test using Random diff --git a/test/test_cdp.jl b/test/test_cdp.jl index 90d69c9..53052bc 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -81,8 +81,6 @@ end @testset "LQ control" begin - using QuantEcon - A = [1.0 0.0; -0.5 0.9]; @@ -104,7 +102,7 @@ point = (5.0, 0.0, 0.0); discount = 0.9; - lq = QuantEcon.LQ(Q, R, A, B, C, N, bet=discount); + lq = LQ(Q, R, A, B, C, N, bet=discount); P, F, d = stationary_values(lq); v_star(s) = -([1, s...]' * P * [1, s...] + d) x_star(s) = -(F * [1, s...])[1]; From 109efdb366d1bbfed4803c97aeec451c6627219c Mon Sep 17 00:00:00 2001 From: mnshkw Date: Wed, 4 Mar 2026 05:14:11 +0900 Subject: [PATCH 2/7] TEST(refactor): remove dead code and fix unused variable --- test/test_cdp.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_cdp.jl b/test/test_cdp.jl index 53052bc..94d9967 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -136,18 +136,16 @@ alpha = 0.2 bet = 0.5 gamm = 0.9 - sigma = 0.1 discount = 0.9; x_star = ((discount * bet) / (1 - discount * gamm))^(1 / (1 - bet)) s_star = gamm * x_star + x_star^bet - s_star, x_star f(s, x) = (s - x)^(1 - alpha) / (1 - alpha) g(s, x, e) = gamm * x .+ e * x^bet; n_shocks = 3 - shocks, weights = zeros(3), ones(3) / 3. + shocks, weights = zeros(n_shocks), ones(n_shocks) / n_shocks x_lb(s) = 0 x_ub(s) = 0.99 * s; From 5cb08a2023144f6dbf763ce1de971e994da2c2c7 Mon Sep 17 00:00:00 2001 From: mnshkw Date: Wed, 4 Mar 2026 05:36:20 +0900 Subject: [PATCH 3/7] TEST(fix): strengthen simulate path validation with initial value, length, and full-path check - change norm check to element-wise max abs error check - change atol from 1e-5 to 1e-4 to avoid test failure due to numerical precision issues --- test/test_cdp.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_cdp.jl b/test/test_cdp.jl index 94d9967..6a64e17 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -64,8 +64,10 @@ # simulate s_path = @inferred(simulate(res, s_init, ts_length)) - atol = 1e-5 - @test isapprox(s_path[end], s_path_star[end]; atol=atol) + atol = 1e-4 + @test s_path[1] == s_init + @test length(s_path) == ts_length + @test maximum(abs, s_path - s_path_star) <= atol end end From 9919ea747a33a48e6ace39880ac04ae12be185d7 Mon Sep 17 00:00:00 2001 From: mnshkw Date: Wed, 4 Mar 2026 05:46:11 +0900 Subject: [PATCH 4/7] TEST(refactor): add @testset nesting to basis x method loop in "Deterministic optimal growth" --- test/test_cdp.jl | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/test/test_cdp.jl b/test/test_cdp.jl index 6a64e17..c847a9c 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -43,31 +43,34 @@ push!(bases, Basis(SplineParams(breaks, s_min, s_max, k))) methods = [PFI, VFI] + basis_labels = ["Chebyshev", "Spline"] - for basis in bases + for (basis, label) in zip(bases, basis_labels) cdp = ContinuousDP(f, g, beta, shocks, weights, x_lb, x_ub, basis) for method in methods - # solve - tol = sqrt(eps()) - max_iter = 500 - res = @inferred(solve(cdp, method, tol=tol, max_iter=max_iter)) - - rtol = 1e-5 - @test isapprox(res.V, v_star.(cdp.interp.S); rtol=rtol) - @test isapprox(res.X, x_star.(cdp.interp.S); rtol=rtol) - - # set_eval_nodes! - grid_size = 200 - eval_nodes = collect(range(s_min, stop=s_max, length=grid_size)) - set_eval_nodes!(res, eval_nodes); - - # simulate - s_path = @inferred(simulate(res, s_init, ts_length)) - atol = 1e-4 - @test s_path[1] == s_init - @test length(s_path) == ts_length - @test maximum(abs, s_path - s_path_star) <= atol + @testset "Test $method with $label basis" begin + # solve + tol = sqrt(eps()) + max_iter = 500 + res = @inferred(solve(cdp, method, tol=tol, max_iter=max_iter)) + + rtol = 1e-5 + @test isapprox(res.V, v_star.(cdp.interp.S); rtol=rtol) + @test isapprox(res.X, x_star.(cdp.interp.S); rtol=rtol) + + # set_eval_nodes! + grid_size = 200 + eval_nodes = collect(range(s_min, stop=s_max, length=grid_size)) + set_eval_nodes!(res, eval_nodes); + + # simulate + s_path = @inferred(simulate(res, s_init, ts_length)) + atol = 1e-4 + @test s_path[1] == s_init + @test length(s_path) == ts_length + @test maximum(abs, s_path - s_path_star) <= atol + end end end From 3d9aa8fbaf370702079f04c9a20a1c8afd8f953e Mon Sep 17 00:00:00 2001 From: mnshkw Date: Fri, 6 Mar 2026 01:38:16 +0900 Subject: [PATCH 5/7] TEST(fix): remove remaining dead code and trailing whitespace in `test/test_cdp.jl` --- test/test_cdp.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/test_cdp.jl b/test/test_cdp.jl index c847a9c..6cef65d 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -68,7 +68,7 @@ s_path = @inferred(simulate(res, s_init, ts_length)) atol = 1e-4 @test s_path[1] == s_init - @test length(s_path) == ts_length + @test length(s_path) == ts_length @test maximum(abs, s_path - s_path_star) <= atol end end @@ -143,9 +143,6 @@ gamm = 0.9 discount = 0.9; - x_star = ((discount * bet) / (1 - discount * gamm))^(1 / (1 - bet)) - s_star = gamm * x_star + x_star^bet - f(s, x) = (s - x)^(1 - alpha) / (1 - alpha) g(s, x, e) = gamm * x .+ e * x^bet; From bfb2bd4062069e13cb277d99e1a7dc35c5b87fb7 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Fri, 6 Mar 2026 09:25:01 +0900 Subject: [PATCH 6/7] Revert "TEST(refactor): move `using QuantEcon` out of `@testset` and replace `QuantEcon.LQ` with `LQ`" This reverts commit ea92243065506022a0d357ce9400e9ef064d7fd1. --- test/runtests.jl | 2 +- test/test_cdp.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 03289ed..7177bb8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using LinearAlgebra using ContinuousDPs -using QuantEcon: PFI, VFI, solve, stationary_values, qnwnorm, LQ +using QuantEcon: PFI, VFI, solve, stationary_values, qnwnorm using BasisMatrices: Basis, ChebParams, SplineParams, LinParams, nodes using Test using Random diff --git a/test/test_cdp.jl b/test/test_cdp.jl index 6cef65d..82f8c22 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -86,6 +86,8 @@ end @testset "LQ control" begin + using QuantEcon + A = [1.0 0.0; -0.5 0.9]; @@ -107,7 +109,7 @@ point = (5.0, 0.0, 0.0); discount = 0.9; - lq = LQ(Q, R, A, B, C, N, bet=discount); + lq = QuantEcon.LQ(Q, R, A, B, C, N, bet=discount); P, F, d = stationary_values(lq); v_star(s) = -([1, s...]' * P * [1, s...] + d) x_star(s) = -(F * [1, s...])[1]; From db21cbac3637ff48561b707c7c40a8a267aba4b7 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Fri, 6 Mar 2026 09:26:27 +0900 Subject: [PATCH 7/7] TEST: Replace `using QuantEcon` with `import QuantEcon` --- test/test_cdp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_cdp.jl b/test/test_cdp.jl index 82f8c22..9d3cb04 100644 --- a/test/test_cdp.jl +++ b/test/test_cdp.jl @@ -86,7 +86,7 @@ end @testset "LQ control" begin - using QuantEcon + import QuantEcon A = [1.0 0.0; -0.5 0.9];