| 1 |
function [testFailed, testResults] = test_check_steady_state(M_, options_, steady_state, testFailed, testResults) |
| 2 |
%test_check_steady_state Tests for heterogeneity.check_steady_state_input |
| 3 |
% |
| 4 |
% Comprehensive tests for the steady-state input validation function |
| 5 |
% |
| 6 |
% INPUTS: |
| 7 |
% M_ [struct] Dynare model structure |
| 8 |
% options_ [struct] Dynare options structure |
| 9 |
% steady_state [struct] Steady state structure |
| 10 |
% testFailed [scalar] Number of tests failed so far |
| 11 |
% testResults [array] Array of test result structures |
| 12 |
% |
| 13 |
% OUTPUTS: |
| 14 |
% testFailed [scalar] Updated number of tests failed |
| 15 |
% testResults [array] Updated array of test results |
| 16 |
|
| 17 |
fprintf('\n'); |
| 18 |
fprintf('Testing heterogeneity.check_steady_state_input\n'); |
| 19 |
fprintf('=============================================\n'); |
| 20 |
|
| 21 |
verbose = true; |
| 22 |
|
| 23 |
%% === OUTPUTS === |
| 24 |
[testFailed, result] = run_test('sizes output validation', @() test_sizes_output(M_, options_, steady_state), testFailed); |
| 25 |
testResults = [testResults; result]; |
| 26 |
|
| 27 |
[testFailed, result] = run_test('out_ss output validation', @() test_out_ss_output(M_, options_, steady_state), testFailed); |
| 28 |
testResults = [testResults; result]; |
| 29 |
|
| 30 |
function test_sizes_output(M_, options_, steady_state) |
| 31 |
[out_ss, sizes] = heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, steady_state); |
| 32 |
assert(sizes.n_e == numel(fieldnames(steady_state.shocks.grids)), 'sizes.n_e incorrect'); |
| 33 |
assert(sizes.n_a == numel(fieldnames(steady_state.pol.grids)), 'sizes.n_a incorrect'); |
| 34 |
assert(sizes.N_e == numel(steady_state.shocks.grids.e), 'sizes.N_e incorrect'); |
| 35 |
assert(sizes.n_pol == M_.heterogeneity(1).endo_nbr, 'sizes.n_pol incorrect'); |
| 36 |
assert(sizes.agg == numel(fieldnames(steady_state.agg)), 'sizes.agg incorrect'); |
| 37 |
assert(sizes.shocks.e == numel(steady_state.shocks.grids.e), 'sizes.shocks.e incorrect'); |
| 38 |
assert(sizes.pol.N_a == numel(steady_state.pol.grids.a), 'sizes.pol.N_a incorrect'); |
| 39 |
assert(sizes.pol.states.a == sizes.pol.N_a, 'sizes.pol.states.a incorrect'); |
| 40 |
assert(sizes.d.N_a == sizes.pol.N_a, 'sizes.d.N_a incorrect'); |
| 41 |
assert(sizes.d.states.a == sizes.pol.states.a, 'sizes.d.states.a incorrect'); |
| 42 |
end |
| 43 |
|
| 44 |
function test_out_ss_output(M_, options_, steady_state) |
| 45 |
[out_ss, sizes] = heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, steady_state); |
| 46 |
assert(iscolumn(out_ss.shocks.grids.e), 'out_ss.shocks.grids.e not column'); |
| 47 |
assert(iscolumn(out_ss.pol.grids.a), 'out_ss.pol.grids.a not column'); |
| 48 |
assert(iscolumn(out_ss.d.grids.a), 'out_ss.d.grids.a not column'); |
| 49 |
assert(size(out_ss.shocks.grids.e,1) == sizes.shocks.e, 'out_ss.shocks.grids.e size mismatch'); |
| 50 |
assert(size(out_ss.pol.grids.a,1) == sizes.pol.states.a, 'out_ss.pol.grids.a size mismatch'); |
| 51 |
assert(size(out_ss.d.grids.a,1) == sizes.d.states.a, 'out_ss.d.grids.a size mismatch'); |
| 52 |
assert(numel(fieldnames(out_ss.agg)) == sizes.agg, 'out_ss.agg field count mismatch'); |
| 53 |
end |
| 54 |
|
| 55 |
%% === NON-STRUCT FIELDS === |
| 56 |
|
| 57 |
% steady_state is not a struct |
| 58 |
ss_test = 123; |
| 59 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), 'steady_state is not a struct', testFailed, verbose); |
| 60 |
testResults = [testResults; result]; |
| 61 |
|
| 62 |
% steady_state.shocks is not a struct |
| 63 |
ss_test = steady_state; |
| 64 |
ss_test.shocks = 1; |
| 65 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), 'steady_state.shocks is not a struct', testFailed, verbose); |
| 66 |
testResults = [testResults; result]; |
| 67 |
|
| 68 |
% steady_state.shocks.grids is not a struct |
| 69 |
ss_test = steady_state; |
| 70 |
ss_test.shocks.grids = 42; |
| 71 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 72 |
'steady_state.shocks.grids is not a struct', testFailed, verbose); |
| 73 |
testResults = [testResults; result]; |
| 74 |
|
| 75 |
% steady_state.shocks.Pi is not a struct |
| 76 |
ss_test = steady_state; |
| 77 |
ss_test.shocks.Pi = "not_a_struct"; |
| 78 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 79 |
'steady_state.shocks.Pi is not a struct', testFailed, verbose); |
| 80 |
testResults = [testResults; result]; |
| 81 |
|
| 82 |
% steady_state.pol is not a struct |
| 83 |
ss_test = steady_state; |
| 84 |
ss_test.pol = pi; |
| 85 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 86 |
'steady_state.pol is not a struct', testFailed, verbose); |
| 87 |
testResults = [testResults; result]; |
| 88 |
|
| 89 |
% steady_state.pol.grids is not a struct |
| 90 |
ss_test = steady_state; |
| 91 |
ss_test.pol.grids = "grid"; |
| 92 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 93 |
'steady_state.pol.grids is not a struct', testFailed, verbose); |
| 94 |
testResults = [testResults; result]; |
| 95 |
|
| 96 |
% steady_state.pol.values is not a struct |
| 97 |
ss_test = steady_state; |
| 98 |
ss_test.pol.values = "values"; |
| 99 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 100 |
'steady_state.pol.values is not a struct', testFailed, verbose); |
| 101 |
testResults = [testResults; result]; |
| 102 |
|
| 103 |
% steady_state.d is not a struct |
| 104 |
ss_test = steady_state; |
| 105 |
ss_test.d = 1; |
| 106 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 107 |
'steady_state.d is not a struct', testFailed, verbose); |
| 108 |
testResults = [testResults; result]; |
| 109 |
|
| 110 |
% steady_state.d.grids is not a struct |
| 111 |
ss_test = steady_state; |
| 112 |
ss_test.d.grids = "grid"; |
| 113 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 114 |
'steady_state.d.grids is not a struct', testFailed, verbose); |
| 115 |
testResults = [testResults; result]; |
| 116 |
|
| 117 |
% steady_state.agg is not a struct |
| 118 |
ss_test = steady_state; |
| 119 |
ss_test.agg = 0; |
| 120 |
[testFailed, result] = expect_error(@() heterogeneity.check_steady_state_input(M_, options_.heterogeneity.check, ss_test), ... |
| 121 |
'steady_state.agg is not a struct', testFailed, verbose); |
| 122 |
testResults = [testResults; result]; |
| 123 |
|
| 124 |
end |