Use new unit tests interface.

unit-tests
Stéphane Adjemian (Guts) 2023-01-02 16:57:08 +01:00 committed by Stéphane Adjemian (Ryûk)
parent aec0efa8f6
commit 5b72a3041c
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
31 changed files with 1424 additions and 1394 deletions

View File

@ -101,10 +101,10 @@ It's useful to contribute `.mod` files that test some aspect of Dynare that is n
### Unit tests ### Unit tests
So-called unit tests allow the test suite to check the correct functioning of the MATLAB/Octave functions contained in Dynare. To add a unit test you need to So-called unit tests allow the test suite to check the correct functioning of the MATLAB/Octave functions contained in Dynare. To add a unit test you need to
1. add the keyword ` % --*-- Unitary tests --*--` at the end of the `function` header to tell the testsuite that the file contains unit tests. 1. add the `return % --*-- Unit tests --*--` at the end of the `function` to tell the testsuite that the file contains unit tests.
1. Add the particular tests at the end of the file after a `return` by 1. Add the particular tests at the end of the file after the `return` statement by
1. Starting a test with `%@test:INTEGER` 1. Starting a test with `%@test:INTEGER`
2. Adding a MATLAB/Octave test code that provides a pass/fail indicator `T` that takes on `true` if the test passed. 2. Adding a MATLAB/Octave test code that provides a pass/fail indicator `T` that takes on `true` if the test passed.
3. Closing the test with `%@eof:INTEGER` 3. Closing the test with `%@eof:INTEGER`
where `INTEGER` denotes the number of the test. where `INTEGER` denotes the number of the test.
@ -112,9 +112,9 @@ So-called unit tests allow the test suite to check the correct functioning of th
An example testing the correct functionality of mode-computations for a normal distribution is An example testing the correct functionality of mode-computations for a normal distribution is
``` ```
function m = compute_prior_mode(hyperparameters,shape) % --*-- Unitary tests --*-- function m = compute_prior_mode(hyperparameters,shape)
return return % --*-- Unit tests --*--
%@test:1 %@test:1
% Normal density % Normal density

View File

@ -1,4 +1,4 @@
function [nodes, weights] = cubature_with_gaussian_weight(d,n,method) % --*-- Unitary tests --*-- function [nodes, weights] = cubature_with_gaussian_weight(d, n, method)
% Computes nodes and weights for a n-order cubature with gaussian weight. % Computes nodes and weights for a n-order cubature with gaussian weight.
% %
@ -17,7 +17,7 @@ function [nodes, weights] = cubature_with_gaussian_weight(d,n,method) % --*-- U
% ∫ f(x) × e dx % ∫ f(x) × e dx
% -∞ % -∞
% Copyright © 2012-2019 Dynare Team % Copyright © 2012-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -108,7 +108,7 @@ m(:,2) = e(n,i)-e(n,j);
m(:,3) = -m(:,2); m(:,3) = -m(:,2);
m(:,4) = -m(:,1); m(:,4) = -m(:,1);
return return % --*-- Unit tests --*--
%@test:1 %@test:1
d = 4; d = 4;
@ -267,4 +267,4 @@ if t(1)
t(4) = dassert(m3,zeros(d,1),1e-12); t(4) = dassert(m3,zeros(d,1),1e-12);
T = all(t); T = all(t);
end end
%@eof:6 %@eof:6

View File

@ -1,4 +1,4 @@
function [a, b] = beta_specification(mu, sigma2, lb, ub, name) % --*-- Unitary tests --*-- function [a, b] = beta_specification(mu, sigma2, lb, ub, name)
% Returns the hyperparameters of the beta distribution given the expectation and variance. % Returns the hyperparameters of the beta distribution given the expectation and variance.
% %
@ -12,7 +12,7 @@ function [a, b] = beta_specification(mu, sigma2, lb, ub, name) % --*-- Unitary
% - a [double] First hyperparameter of the Beta density. % - a [double] First hyperparameter of the Beta density.
% - b [double] Second hyperparameter of the Beta density. % - b [double] Second hyperparameter of the Beta density.
% Copyright © 2015-2017 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -66,67 +66,69 @@ end
a = (1-mu)*mu*mu/sigma2-mu; a = (1-mu)*mu*mu/sigma2-mu;
b = a*(1/mu-1); b = a*(1/mu-1);
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ try try
%$ [a, b] = beta_specification(.5, .05); [a, b] = beta_specification(.5, .05);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(0.5-a/(a+b))<1e-12; t(2) = abs(0.5-a/(a+b))<1e-12;
%$ t(3) = abs(0.05-a*b/((a+b)^2*(a+b+1)))<1e-12; t(3) = abs(0.05-a*b/((a+b)^2*(a+b+1)))<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ try try
%$ [a, b] = beta_specification(0.5, .05, 1, 2); [a, b] = beta_specification(0.5, .05, 1, 2);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ try try
%$ [a, b] = beta_specification(2.5, .05, 1, 2); [a, b] = beta_specification(2.5, .05, 1, 2);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ try try
%$ [a, b] = beta_specification(.4, .6*.4+1e-4); [a, b] = beta_specification(.4, .6*.4+1e-4);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4
%@test:5 %@test:5
%$ try try
%$ [a, b] = beta_specification(.4, .6*.4+1e-6); [a, b] = beta_specification(.4, .6*.4+1e-6);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$ try try
%$ [a, b] = beta_specification(.4, .6*.4-1e-6); [a, b] = beta_specification(.4, .6*.4-1e-6);
%$ t(2) = true; t(2) = true;
%$ catch catch
%$ t(2) = false; t(2) = false;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:5 %@eof:5

View File

@ -1,4 +1,4 @@
function m = compute_prior_mode(hyperparameters,shape) % --*-- Unitary tests --*-- function m = compute_prior_mode(hyperparameters,shape)
% This function computes the mode of the prior distribution given the (two, three or four) hyperparameters % This function computes the mode of the prior distribution given the (two, three or four) hyperparameters
% of the prior distribution. % of the prior distribution.
% %
@ -23,7 +23,7 @@ function m = compute_prior_mode(hyperparameters,shape) % --*-- Unitary tests --*
% [3] The uniform distribution has an infinity of modes. In this case the function returns the prior mean. % [3] The uniform distribution has an infinity of modes. In this case the function returns the prior mean.
% [4] For the beta distribution we can have 1, 2 or an infinity of modes. % [4] For the beta distribution we can have 1, 2 or an infinity of modes.
% Copyright © 2009-2017 Dynare Team % Copyright © 2009-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -102,140 +102,142 @@ switch shape
error('Unknown prior shape!') error('Unknown prior shape!')
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ % Beta density % Beta density
%$ try try
%$ m1 = compute_prior_mode([2 1],1); m1 = compute_prior_mode([2 1],1);
%$ m2 = compute_prior_mode([2 5 1 4],1); % Wolfram Alpha: BetaDistribution[2,5] m2 = compute_prior_mode([2 5 1 4],1); % Wolfram Alpha: BetaDistribution[2,5]
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,1,1e-6); t(2) = dassert(m1,1,1e-6);
%$ t(3) = dassert(m2,1/5*3+1,1e-6); t(3) = dassert(m2,1/5*3+1,1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ % Gamma density % Gamma density
%$ try try
%$ m1 = compute_prior_mode([1 2],2); m1 = compute_prior_mode([1 2],2);
%$ m2 = compute_prior_mode([9 0.5 1],2); % Wolfram Alpha: GammaDistribution[9,0.5] m2 = compute_prior_mode([9 0.5 1],2); % Wolfram Alpha: GammaDistribution[9,0.5]
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,0,1e-6); t(2) = dassert(m1,0,1e-6);
%$ t(3) = dassert(m2,4+1,1e-6); t(3) = dassert(m2,4+1,1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ % Normal density % Normal density
%$ try try
%$ m1 = compute_prior_mode([1 1],3); m1 = compute_prior_mode([1 1],3);
%$ m2 = compute_prior_mode([2 5],3); m2 = compute_prior_mode([2 5],3);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,1,1e-6); t(2) = dassert(m1,1,1e-6);
%$ t(3) = dassert(m2,2,1e-6); t(3) = dassert(m2,2,1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ % Inverse Gamma I density % Inverse Gamma I density
%$ try try
%$ m1 = compute_prior_mode([8 2],4); m1 = compute_prior_mode([8 2],4);
%$ m2 = compute_prior_mode([8 2 1],4); m2 = compute_prior_mode([8 2 1],4);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,1.632993161855452,1e-6); t(2) = dassert(m1,1.632993161855452,1e-6);
%$ t(3) = dassert(m2,1.632993161855452+1,1e-6); t(3) = dassert(m2,1.632993161855452+1,1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4
%@test:5 %@test:5
%$ % Uniform density % Uniform density
%$ try try
%$ m1 = compute_prior_mode([0.5 1/sqrt(12)],5); m1 = compute_prior_mode([0.5 1/sqrt(12)],5);
%$ m2 = compute_prior_mode([2 5 1 2],5); m2 = compute_prior_mode([2 5 1 2],5);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,0.5,1e-6); t(2) = dassert(m1,0.5,1e-6);
%$ t(3) = dassert(m2,2,1e-6); t(3) = dassert(m2,2,1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:5 %@eof:5
%@test:6 %@test:6
%$ % Inverse Gamma II density, parameterized with s and nu where s=2*beta and nu=2*alpha % Inverse Gamma II density, parameterized with s and nu where s=2*beta and nu=2*alpha
%$ try try
%$ m1 = compute_prior_mode([8 2],6); % Wolfram Alpha, parameterized with alpha beta: InversegammaDistribution[1,4] m1 = compute_prior_mode([8 2],6); % Wolfram Alpha, parameterized with alpha beta: InversegammaDistribution[1,4]
%$ m2 = compute_prior_mode([8 4 1],6); % Wolfram Alpha, parameterized with alpha beta: InversegammaDistribution[2,4] m2 = compute_prior_mode([8 4 1],6); % Wolfram Alpha, parameterized with alpha beta: InversegammaDistribution[2,4]
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,2,1e-6); t(2) = dassert(m1,2,1e-6);
%$ t(3) = dassert(m2,1+4/3,1e-6); t(3) = dassert(m2,1+4/3,1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:6 %@eof:6
%@test:7 %@test:7
%$ % Weibull density % Weibull density
%$ try try
%$ m1 = compute_prior_mode([1 1],8); m1 = compute_prior_mode([1 1],8);
%$ m2 = compute_prior_mode([2 1 1],8); % Wolfram Alpha: WeibullDistribution[2,1] m2 = compute_prior_mode([2 1 1],8); % Wolfram Alpha: WeibullDistribution[2,1]
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = dassert(m1,0,1e-6); t(2) = dassert(m1,0,1e-6);
%$ t(3) = dassert(m2,1+1/sqrt(2),1e-6); t(3) = dassert(m2,1+1/sqrt(2),1e-6);
%$ end end
%$ T = all(t); T = all(t);
%@eof:7 %@eof:7
%@test:8 %@test:8
%$ % Unknown density % Unknown density
%$ try try
%$ m1 = compute_prior_mode([1 1],7); m1 = compute_prior_mode([1 1],7);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:8 %@eof:8

View File

@ -1,4 +1,4 @@
function [a, b] = gamma_specification(mu, sigma2, lb, name) % --*-- Unitary tests --*-- function [a, b] = gamma_specification(mu, sigma2, lb, name)
% Returns the hyperparameters of the gamma distribution given the expectation and variance. % Returns the hyperparameters of the gamma distribution given the expectation and variance.
% %
@ -12,7 +12,7 @@ function [a, b] = gamma_specification(mu, sigma2, lb, name) % --*-- Unitary te
% - a [double] First hyperparameter of the Gamma density (shape). % - a [double] First hyperparameter of the Gamma density (shape).
% - b [double] Second hyperparameter of the Gamma density (scale). % - b [double] Second hyperparameter of the Gamma density (scale).
% Copyright © 2015-2017 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -53,54 +53,56 @@ mu = mu-lb;
b = sigma2/mu; b = sigma2/mu;
a = mu/b; a = mu/b;
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ try try
%$ [a, b] = gamma_specification(.5, 1); [a, b] = gamma_specification(.5, 1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(0.5-a*b)<1e-12; t(2) = abs(0.5-a*b)<1e-12;
%$ t(3) = abs(1.0-a*b*b)<1e-12; t(3) = abs(1.0-a*b*b)<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ try try
%$ [a, b] = gamma_specification(2, 1); [a, b] = gamma_specification(2, 1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(2.0-a*b)<1e-12; t(2) = abs(2.0-a*b)<1e-12;
%$ t(3) = abs(1.0-a*b*b)<1e-12; t(3) = abs(1.0-a*b*b)<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ try try
%$ [a, b] = gamma_specification(2, 1, 3); [a, b] = gamma_specification(2, 1, 3);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ try try
%$ [a, b] = gamma_specification(2, Inf, 3); [a, b] = gamma_specification(2, Inf, 3);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4

View File

@ -1,4 +1,4 @@
function [s,nu] = inverse_gamma_specification(mu, sigma2, lb, type, use_fzero_flag, name) % --*-- Unitary tests --*-- function [s,nu] = inverse_gamma_specification(mu, sigma2, lb, type, use_fzero_flag, name)
% Computes the inverse Gamma hyperparameters from the prior mean and variance. % Computes the inverse Gamma hyperparameters from the prior mean and variance.
% %
@ -21,7 +21,7 @@ function [s,nu] = inverse_gamma_specification(mu, sigma2, lb, type, use_fzero_fl
% more often in finding an interval for nu containing a signe change because it expands the interval on both sides and eventually % more often in finding an interval for nu containing a signe change because it expands the interval on both sides and eventually
% violates the condition nu>2. % violates the condition nu>2.
% Copyright © 2003-2017 Dynare Team % Copyright © 2003-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -147,62 +147,64 @@ else
error('inverse_gamma_specification: unkown type') error('inverse_gamma_specification: unkown type')
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ try try
%$ [s, nu] = inverse_gamma_specification(.5, .05, 0, 1); [s, nu] = inverse_gamma_specification(.5, .05, 0, 1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(0.5-sqrt(.5*s)*gamma(.5*(nu-1))/gamma(.5*nu))<1e-12; t(2) = abs(0.5-sqrt(.5*s)*gamma(.5*(nu-1))/gamma(.5*nu))<1e-12;
%$ t(3) = abs(0.05-s/(nu-2)+.5^2)<1e-12; t(3) = abs(0.05-s/(nu-2)+.5^2)<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ try try
%$ [s, nu] = inverse_gamma_specification(.5, .05, 0, 2); [s, nu] = inverse_gamma_specification(.5, .05, 0, 2);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(0.5-s/(nu-2))<1e-12; t(2) = abs(0.5-s/(nu-2))<1e-12;
%$ t(3) = abs(0.05-2*.5^2/(nu-4))<1e-12; t(3) = abs(0.05-2*.5^2/(nu-4))<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ try try
%$ [s, nu] = inverse_gamma_specification(.5, Inf, 0, 1); [s, nu] = inverse_gamma_specification(.5, Inf, 0, 1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(0.5-sqrt(.5*s)*gamma(.5*(nu-1))/gamma(.5*nu))<1e-12; t(2) = abs(0.5-sqrt(.5*s)*gamma(.5*(nu-1))/gamma(.5*nu))<1e-12;
%$ t(3) = isequal(nu, 2); %abs(0.05-2*.5^2/(nu-4))<1e-12; t(3) = isequal(nu, 2); %abs(0.05-2*.5^2/(nu-4))<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ try try
%$ [s, nu] = inverse_gamma_specification(.5, Inf, 0, 2); [s, nu] = inverse_gamma_specification(.5, Inf, 0, 2);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(0.5-s/(nu-2))<1e-12; t(2) = abs(0.5-s/(nu-2))<1e-12;
%$ t(3) = isequal(nu, 4); t(3) = isequal(nu, 4);
%$ end end
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4

View File

@ -1,4 +1,4 @@
function [ldens,Dldens,D2ldens] = lpdfgweibull(x,a,b,c) % --*-- Unitary tests --*-- function [ldens,Dldens,D2ldens] = lpdfgweibull(x,a,b,c)
% Evaluates the logged Weibull PDF at x. % Evaluates the logged Weibull PDF at x.
% %
@ -16,7 +16,7 @@ function [ldens,Dldens,D2ldens] = lpdfgweibull(x,a,b,c) % --*-- Unitary tests -
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright © 2015-2020 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -96,344 +96,346 @@ if nargout>1
end end
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ try try
%$ lpdfgweibull(1.0); lpdfgweibull(1.0);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ try try
%$ lpdfgweibull(1.0, .5); lpdfgweibull(1.0, .5);
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ try try
%$ lpdfgweibull(ones(2,2), .5*ones(2,1), .1*ones(3,1)); lpdfgweibull(ones(2,2), .5*ones(2,1), .1*ones(3,1));
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ try try
%$ a = lpdfgweibull(-1, .5, .1); a = lpdfgweibull(-1, .5, .1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = isinf(a); t(2) = isinf(a);
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4
%@test:5 %@test:5
%$ try try
%$ a = lpdfgweibull(0, 1, 1); a = lpdfgweibull(0, 1, 1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(a-1.0)<1e-10; t(2) = abs(a-1.0)<1e-10;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:5 %@eof:5
%@test:6 %@test:6
%$ try try
%$ a = lpdfgweibull([0, -1], [1 1], [1 1]); a = lpdfgweibull([0, -1], [1 1], [1 1]);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(a(1)-1.0)<1e-10; t(2) = abs(a(1)-1.0)<1e-10;
%$ t(3) = isinf(a(2)); t(3) = isinf(a(2));
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:6 %@eof:6
%@test:7 %@test:7
%$ scale = 1; scale = 1;
%$ shape = 2; shape = 2;
%$ mode = scale*((shape-1)/shape)^(1/shape); mode = scale*((shape-1)/shape)^(1/shape);
%$
%$ try try
%$ [a, b, c] = lpdfgweibull(mode, shape, scale); [a, b, c] = lpdfgweibull(mode, shape, scale);
%$ p = rand(1000,1)*4; p = rand(1000,1)*4;
%$ am = lpdfgweibull(p, shape*ones(size(p)), scale*ones(size(p))); am = lpdfgweibull(p, shape*ones(size(p)), scale*ones(size(p)));
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$
%$ t(2) = abs(b)<1e-8; t(2) = abs(b)<1e-8;
%$ t(3) = c<0; t(3) = c<0;
%$ t(4) = all(am<a); t(4) = all(am<a);
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:7 %@eof:7
%@test:8 %@test:8
%$ scale = 1; scale = 1;
%$ shape = 2; shape = 2;
%$ density = @(x) exp(lpdfgweibull(x,shape,scale)); density = @(x) exp(lpdfgweibull(x,shape,scale));
%$
%$ try try
%$ if isoctave if isoctave
%$ s = quadl(density, .0000000001, 100000, 1e-10); s = quadl(density, .0000000001, 100000, 1e-10);
%$ else else
%$ s = integral(density, 0, 100000); s = integral(density, 0, 100000);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(s-1)<1e-6; t(2) = abs(s-1)<1e-6;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:8 %@eof:8
%@test:9 %@test:9
%$ scale = 1; scale = 1;
%$ shape = 1; shape = 1;
%$ density = @(x) exp(lpdfgweibull(x,shape,scale)); density = @(x) exp(lpdfgweibull(x,shape,scale));
%$
%$ try try
%$ if isoctave if isoctave
%$ s = quadl(density, .0000000001, 100000, 1e-10); s = quadl(density, .0000000001, 100000, 1e-10);
%$ else else
%$ s = integral(density, 0, 100000); s = integral(density, 0, 100000);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(s-1)<1e-6; t(2) = abs(s-1)<1e-6;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:9 %@eof:9
%@test:10 %@test:10
%$ scale = 1; scale = 1;
%$ shape = .5; shape = .5;
%$ density = @(x) exp(lpdfgweibull(x,shape,scale)); density = @(x) exp(lpdfgweibull(x,shape,scale));
%$
%$ try try
%$ if isoctave if isoctave
%$ s = quadl(density, .0000000001, 100000, 1e-10); s = quadl(density, .0000000001, 100000, 1e-10);
%$ else else
%$ s = integral(density, 0, 100000); s = integral(density, 0, 100000);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ if isoctave if isoctave
%$ t(2) = abs(s-1)<5e-5; t(2) = abs(s-1)<5e-5;
%$ else else
%$ t(2) = abs(s-1)<1e-6; t(2) = abs(s-1)<1e-6;
%$ end end
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:10 %@eof:10
%@test:11 %@test:11
%$ scale = 1; scale = 1;
%$ shape = 2; shape = 2;
%$ xdens = @(x) x.*exp(lpdfgweibull(x,shape,scale)); xdens = @(x) x.*exp(lpdfgweibull(x,shape,scale));
%$
%$ try try
%$ if isoctave if isoctave
%$ s = quadgk(xdens, .0000000001, 100000, 1e-10); s = quadgk(xdens, .0000000001, 100000, 1e-10);
%$ else else
%$ s = integral(xdens, 0, 100000); s = integral(xdens, 0, 100000);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(s-scale*gamma(1+1/shape))<1e-6; t(2) = abs(s-scale*gamma(1+1/shape))<1e-6;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:11 %@eof:11
%@test:12 %@test:12
%$ scale = 1; scale = 1;
%$ shape = 1; shape = 1;
%$ xdens = @(x) x.*exp(lpdfgweibull(x,shape,scale)); xdens = @(x) x.*exp(lpdfgweibull(x,shape,scale));
%$
%$ try try
%$ if isoctave if isoctave
%$ s = quadl(xdens, .0000000001, 100000, 1e-10); s = quadl(xdens, .0000000001, 100000, 1e-10);
%$ else else
%$ s = integral(xdens, 0, 100000); s = integral(xdens, 0, 100000);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(s-scale*gamma(1+1/shape))<1e-6; t(2) = abs(s-scale*gamma(1+1/shape))<1e-6;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:12 %@eof:12
%@test:13 %@test:13
%$ scale = 1; scale = 1;
%$ shape = .5; shape = .5;
%$ xdens = @(x) x.*exp(lpdfgweibull(x,shape,scale)); xdens = @(x) x.*exp(lpdfgweibull(x,shape,scale));
%$
%$ try try
%$ if isoctave if isoctave
%$ s = quadl(xdens, .0000000001, 100000, 1e-10); s = quadl(xdens, .0000000001, 100000, 1e-10);
%$ else else
%$ s = integral(xdens, 0, 100000); s = integral(xdens, 0, 100000);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = abs(s-scale*gamma(1+1/shape))<1e-6; t(2) = abs(s-scale*gamma(1+1/shape))<1e-6;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:13 %@eof:13
%@test:14 %@test:14
%$ scale = 1; scale = 1;
%$ shape = 2; shape = 2;
%$ density = @(x) exp(lpdfgweibull(x,shape,scale)); density = @(x) exp(lpdfgweibull(x,shape,scale));
%$ n = 200; n = 200;
%$
%$ try try
%$ s = NaN(n, 1); s = NaN(n, 1);
%$ for i=1:n for i=1:n
%$ if isoctave if isoctave
%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10); s(i) = quadl(density, .0000000001, .1*i, 1e-10);
%$ else else
%$ s(i) = integral(density, 0, .1*i); s(i) = integral(density, 0, .1*i);
%$ end end
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ for i=1:n for i=1:n
%$ x = .1*i; x = .1*i;
%$ q = 1-exp(-(x/scale)^shape); q = 1-exp(-(x/scale)^shape);
%$ t(i+1) = abs(s(i)-q)<1e-6; t(i+1) = abs(s(i)-q)<1e-6;
%$ end end
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:14 %@eof:14
%@test:15 %@test:15
%$ scale = 1; scale = 1;
%$ shape = 1; shape = 1;
%$ density = @(x) exp(lpdfgweibull(x,shape,scale)); density = @(x) exp(lpdfgweibull(x,shape,scale));
%$ n = 200; n = 200;
%$
%$ try try
%$ s = NaN(n, 1); s = NaN(n, 1);
%$ for i=1:n for i=1:n
%$ if isoctave if isoctave
%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10); s(i) = quadl(density, .0000000001, .1*i, 1e-10);
%$ else else
%$ s(i) = integral(density, 0, .1*i); s(i) = integral(density, 0, .1*i);
%$ end end
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ for i=1:n for i=1:n
%$ x = .1*i; x = .1*i;
%$ q = 1-exp(-(x/scale)^shape); q = 1-exp(-(x/scale)^shape);
%$ t(i+1) = abs(s(i)-q)<1e-6; t(i+1) = abs(s(i)-q)<1e-6;
%$ end end
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:15 %@eof:15
%@test:16 %@test:16
%$ scale = 1; scale = 1;
%$ shape = .5; shape = .5;
%$ density = @(x) exp(lpdfgweibull(x,shape,scale)); density = @(x) exp(lpdfgweibull(x,shape,scale));
%$ n = 200; n = 200;
%$
%$ try try
%$ s = NaN(n, 1); s = NaN(n, 1);
%$ for i=1:n for i=1:n
%$ if isoctave if isoctave
%$ s(i) = quadl(density, .0000000001, .1*i, 1e-10); s(i) = quadl(density, .0000000001, .1*i, 1e-10);
%$ else else
%$ s(i) = integral(density, 0, .1*i); s(i) = integral(density, 0, .1*i);
%$ end end
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ for i=1:n for i=1:n
%$ x = .1*i; x = .1*i;
%$ q = 1-exp(-(x/scale)^shape); q = 1-exp(-(x/scale)^shape);
%$ if isoctave if isoctave
%$ t(i+1) = abs(s(i)-q)<5e-5; t(i+1) = abs(s(i)-q)<5e-5;
%$ else else
%$ t(i+1) = abs(s(i)-q)<1e-6; t(i+1) = abs(s(i)-q)<1e-6;
%$ end end
%$ end end
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:16 %@eof:16

View File

@ -1,4 +1,4 @@
function [shape, scale] = weibull_specification(mu, sigma2, lb, name) % --*-- Unitary tests --*-- function [shape, scale] = weibull_specification(mu, sigma2, lb, name)
% Returns the hyperparameters of the Weibull distribution given the expectation and variance. % Returns the hyperparameters of the Weibull distribution given the expectation and variance.
% %
@ -9,7 +9,7 @@ function [shape, scale] = weibull_specification(mu, sigma2, lb, name) % --*--
% %
% %
% Copyright © 2015-2017 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -65,78 +65,80 @@ end
scale = mu/gamma(1+1/shape); scale = mu/gamma(1+1/shape);
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ debug = false; debug = false;
%$ scales = 1:.01:5; scales = 1:.01:5;
%$ shapes = .5:.01:2; shapes = .5:.01:2;
%$ n_scales = length(scales); n_scales = length(scales);
%$ n_shapes = length(shapes); n_shapes = length(shapes);
%$ mu = NaN(n_scales, n_shapes); mu = NaN(n_scales, n_shapes);
%$ s2 = NaN(n_scales, n_shapes); s2 = NaN(n_scales, n_shapes);
%$ for i=1:n_shapes for i=1:n_shapes
%$ g1 = gamma(1+1/shapes(i)); g1 = gamma(1+1/shapes(i));
%$ g2 = gamma(1+2/shapes(i)); g2 = gamma(1+2/shapes(i));
%$ g3 = g1*g1; g3 = g1*g1;
%$ for j=1:n_scales for j=1:n_scales
%$ mu(j, i) = scales(j)*g1; mu(j, i) = scales(j)*g1;
%$ s2(j, i) = scales(j)*scales(j)*(g2-g3); s2(j, i) = scales(j)*scales(j)*(g2-g3);
%$ end end
%$ end end
%$ if debug if debug
%$ success = []; success = [];
%$ failed1 = []; failed1 = [];
%$ failed1_ = []; failed1_ = [];
%$ failed2 = []; failed2 = [];
%$ end end
%$ try try
%$ for i=1:n_shapes for i=1:n_shapes
%$ for j=1:n_scales for j=1:n_scales
%$ if debug if debug
%$ disp(sprintf('... mu=%s and s2=%s', num2str(mu(j,i)),num2str(s2(j,i)))) disp(sprintf('... mu=%s and s2=%s', num2str(mu(j,i)),num2str(s2(j,i))))
%$ end end
%$ if ~isnan(mu(j,i)) && ~isnan(s2(j,i)) && ~isinf(mu(j,i)) && ~isinf(s2(j,i)) if ~isnan(mu(j,i)) && ~isnan(s2(j,i)) && ~isinf(mu(j,i)) && ~isinf(s2(j,i))
%$ [shape, scale] = weibull_specification(mu(j,i), s2(j,i)); [shape, scale] = weibull_specification(mu(j,i), s2(j,i));
%$ if isnan(scale) if isnan(scale)
%$ t = false; t = false;
%$ else else
%$ if abs(scales(j)-scale)<1e-9 && abs(shapes(i)-shape)<1e-9 if abs(scales(j)-scale)<1e-9 && abs(shapes(i)-shape)<1e-9
%$ t = true; t = true;
%$ else else
%$ t = false; t = false;
%$ end end
%$ end end
%$ if ~t && debug if ~t && debug
%$ failed1 = [failed1; mu(j,i) s2(j,i)]; failed1 = [failed1; mu(j,i) s2(j,i)];
%$ failed1_ = [failed1_; shapes(i) scales(j)]; failed1_ = [failed1_; shapes(i) scales(j)];
%$ error('UnitTest','Cannot compute scale and shape hyperparameters for mu=%s and s2=%s', num2str(mu(j,i)), num2str(s2(j,i))) error('UnitTest','Cannot compute scale and shape hyperparameters for mu=%s and s2=%s', num2str(mu(j,i)), num2str(s2(j,i)))
%$ end end
%$ if debug if debug
%$ success = [success; mu(j,i) s2(j,i)]; success = [success; mu(j,i) s2(j,i)];
%$ end end
%$ else else
%$ failed2 = [failed2; shapes(i) scales(j)]; failed2 = [failed2; shapes(i) scales(j)];
%$ continue % Pass this test continue % Pass this test
%$ end end
%$ end end
%$ end end
%$ catch catch
%$ t = false; t = false;
%$ end end
%$
%$ if debug if debug
%$ figure(1) figure(1)
%$ plot(success(:,1),success(:,2),'ok'); plot(success(:,1),success(:,2),'ok');
%$ if ~isempty(failed1) if ~isempty(failed1)
%$ hold on hold on
%$ plot(failed1(:,1),failed1(:,2),'or'); plot(failed1(:,1),failed1(:,2),'or');
%$ hold off hold off
%$ figure(2) figure(2)
%$ plot(failed1_(:,1),failed1_(:,2),'or') plot(failed1_(:,1),failed1_(:,2),'or')
%$ end end
%$ if ~isempty(failed2) if ~isempty(failed2)
%$ figure(2) figure(2)
%$ plot(failed2(:,1),failed2(:,2),'or'); plot(failed2(:,1),failed2(:,2),'or');
%$ end end
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function hessian_mat = hessian(func,x, gstep, varargin) % --*-- Unitary tests --*-- function hessian_mat = hessian(func,x, gstep, varargin)
% Computes second order partial derivatives % Computes second order partial derivatives
% %
@ -26,7 +26,7 @@ function hessian_mat = hessian(func,x, gstep, varargin) % --*-- Unitary tests --
% none % none
% %
% Copyright © 2001-2017 Dynare Team % Copyright © 2001-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -98,53 +98,54 @@ for i=1:n
end end
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ % Create a function. % Create a function.
%$ fid = fopen('exfun.m','w+'); fid = fopen('exfun.m','w+');
%$ fprintf(fid,'function [f,g,H] = exfun(xvar)\\n'); fprintf(fid,'function [f,g,H] = exfun(xvar)\\n');
%$ fprintf(fid,'x = xvar(1);\\n'); fprintf(fid,'x = xvar(1);\\n');
%$ fprintf(fid,'y = xvar(2);\\n'); fprintf(fid,'y = xvar(2);\\n');
%$ fprintf(fid,'f = x^2* log(y);\\n'); fprintf(fid,'f = x^2* log(y);\\n');
%$ fprintf(fid,'if nargout>1\\n'); fprintf(fid,'if nargout>1\\n');
%$ fprintf(fid,' g = zeros(2,1);\\n'); fprintf(fid,' g = zeros(2,1);\\n');
%$ fprintf(fid,' g(1) = 2*x*log(y);\\n'); fprintf(fid,' g(1) = 2*x*log(y);\\n');
%$ fprintf(fid,' g(2) = x*x/y;\\n'); fprintf(fid,' g(2) = x*x/y;\\n');
%$ fprintf(fid,'end\\n'); fprintf(fid,'end\\n');
%$ fprintf(fid,'if nargout>2\\n'); fprintf(fid,'if nargout>2\\n');
%$ fprintf(fid,' H = zeros(2,2);\\n'); fprintf(fid,' H = zeros(2,2);\\n');
%$ fprintf(fid,' H(1,1) = 2*log(y);\\n'); fprintf(fid,' H(1,1) = 2*log(y);\\n');
%$ fprintf(fid,' H(1,2) = 2*x/y;\\n'); fprintf(fid,' H(1,2) = 2*x/y;\\n');
%$ fprintf(fid,' H(2,1) = H(1,2);\\n'); fprintf(fid,' H(2,1) = H(1,2);\\n');
%$ fprintf(fid,' H(2,2) = -x*x/(y*y);\\n'); fprintf(fid,' H(2,2) = -x*x/(y*y);\\n');
%$ fprintf(fid,' H = H(:);\\n'); fprintf(fid,' H = H(:);\\n');
%$ fprintf(fid,'end\\n'); fprintf(fid,'end\\n');
%$ fclose(fid); fclose(fid);
%$
%$ rehash; rehash;
%$
%$ t = zeros(5,1); t = zeros(5,1);
%$
%$ % Evaluate the Hessian at (1,e) % Evaluate the Hessian at (1,e)
%$ try try
%$ H = hessian('exfun',[1; exp(1)],[1e-2; 1]); H = hessian('exfun',[1; exp(1)],[1e-2; 1]);
%$ t(1) = 1; t(1) = 1;
%$ catch catch
%$ t(1) = 0; t(1) = 0;
%$ end end
%$
%$ % Compute the true Hessian matrix % Compute the true Hessian matrix
%$ [f, g, Htrue] = exfun([1 exp(1)]); [f, g, Htrue] = exfun([1 exp(1)]);
%$
%$ % Delete exfun routine from disk. % Delete exfun routine from disk.
%$ delete('exfun.m'); delete('exfun.m');
%$
%$ % Compare the values in H and Htrue % Compare the values in H and Htrue
%$ if t(1) if t(1)
%$ t(2) = dassert(abs(H(1)-Htrue(1))<1e-6,true); t(2) = dassert(abs(H(1)-Htrue(1))<1e-6,true);
%$ t(3) = dassert(abs(H(2)-Htrue(2))<1e-6,true); t(3) = dassert(abs(H(2)-Htrue(2))<1e-6,true);
%$ t(4) = dassert(abs(H(3)-Htrue(3))<1e-6,true); t(4) = dassert(abs(H(3)-Htrue(3))<1e-6,true);
%$ t(5) = dassert(abs(H(4)-Htrue(4))<1e-6,true); t(5) = dassert(abs(H(4)-Htrue(4))<1e-6,true);
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -4,13 +4,13 @@ function internals(flag, varargin)
%! @deftypefn {Function File} internals (@var{flag},@var{a},@var{b}, ...) %! @deftypefn {Function File} internals (@var{flag},@var{a},@var{b}, ...)
%! @anchor{internals} %! @anchor{internals}
%! @sp 1 %! @sp 1
%! This command provides internal documentation and unitary tests for the matlab routines. %! This command provides internal documentation and unit tests for the matlab routines.
%! @sp 2 %! @sp 2
%! @strong{Inputs} %! @strong{Inputs}
%! @sp 1 %! @sp 1
%! @table @ @var %! @table @ @var
%! @item flag %! @item flag
%! Mandatory argument: --doc (for displaying internal documentation) or --test (for performing unitary tests). %! Mandatory argument: --doc (for displaying internal documentation) or --test (for performing unit tests).
%! @item b %! @item b
%! Name of the routine to be tested or for which internal documentation is needed. %! Name of the routine to be tested or for which internal documentation is needed.
%! @item c %! @item c
@ -36,13 +36,13 @@ function internals(flag, varargin)
%! @example %! @example
%! internals --test particle/local_state_iteration %! internals --test particle/local_state_iteration
%! @end example %! @end example
%! will execute the unitary tests associated the routine local_state_iteration. %! will execute the unit tests associated the routine local_state_iteration.
%! @sp 2 %! @sp 2
%! @strong{Remarks} %! @strong{Remarks}
%! @sp 1 %! @sp 1
%! [1] It is not possible to display the internal documentation of more than one routine. %! [1] It is not possible to display the internal documentation of more than one routine.
%! @sp 1 %! @sp 1
%! [2] It is possible to perform unitary tests on a list of routines. %! [2] It is possible to perform unit tests on a list of routines.
%! @sp 1 %! @sp 1
%! [3] For displaying the internal documentation, matlab calls texinfo which has to be installed. %! [3] For displaying the internal documentation, matlab calls texinfo which has to be installed.
%! @sp 2 %! @sp 2
@ -56,7 +56,7 @@ function internals(flag, varargin)
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright © 2011-2014 Dynare Team % Copyright © 2011-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %

View File

@ -1,4 +1,4 @@
function b = isolder(f, F) % --*-- Unitary tests --*-- function b = isolder(f, F)
% Returns true if f is older than any file in folder (and subfolders) F. % Returns true if f is older than any file in folder (and subfolders) F.
% %
@ -9,7 +9,7 @@ function b = isolder(f, F) % --*-- Unitary tests --*--
% OUTPUT % OUTPUT
% - b [logical] % - b [logical]
% Copyright © 2015-2017 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -56,38 +56,40 @@ for i=1:length(files)
end end
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ t = false(3,1); t = false(3,1);
%$ mkdir toto; mkdir toto;
%$ cd toto cd toto
%$ mkdir titi; mkdir titi;
%$ mkdir tata; mkdir tata;
%$ cd tata cd tata
%$ mkdir tutu; mkdir tutu;
%$ cd tutu cd tutu
%$ system('touch a.m'); system('touch a.m');
%$ cd .. cd ..
%$ system('touch b.m'); system('touch b.m');
%$ system('touch c.m'); system('touch c.m');
%$ cd ../titi cd ../titi
%$ system('touch d.m'); system('touch d.m');
%$ cd .. cd ..
%$ pause(1) pause(1)
%$ system('touch e.m'); system('touch e.m');
%$ t(1) = isequal(isolder('e.m'), false); t(1) = isequal(isolder('e.m'), false);
%$ pause(1) pause(1)
%$ system('touch tata/tutu/a.m'); system('touch tata/tutu/a.m');
%$ system('touch tata/b.m'); system('touch tata/b.m');
%$ system('touch tata/c.m'); system('touch tata/c.m');
%$ system('touch titi/d.m'); system('touch titi/d.m');
%$ t(2) = isequal(isolder('e.m'), true); t(2) = isequal(isolder('e.m'), true);
%$ pause(1) pause(1)
%$ system('touch e.m'); system('touch e.m');
%$ t(3) = isequal(isolder('e.m'), false); t(3) = isequal(isolder('e.m'), false);
%$ cd .. cd ..
%$ if isoctave() if isoctave()
%$ confirm_recursive_rmdir(false, 'local'); confirm_recursive_rmdir(false, 'local');
%$ end end
%$ rmdir('toto','s'); rmdir('toto','s');
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,6 +1,6 @@
function o2WysrOISH = load_m_file_data_legacy(datafile, U7ORsJ0vy3) % --*-- Unitary tests --*-- function o2WysrOISH = load_m_file_data_legacy(datafile, U7ORsJ0vy3)
% Copyright © 2014-2017 Dynare Team % Copyright © 2014-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -78,7 +78,7 @@ JSmvfqTSXT = repmat(' vec(%s) ', 1, length(U7ORsJ0vy3));
VbO4y7zOlh = sprintf('[%s]', JSmvfqTSXT); VbO4y7zOlh = sprintf('[%s]', JSmvfqTSXT);
o2WysrOISH = dseries(eval(sprintf(VbO4y7zOlh, U7ORsJ0vy3{:})), [], U7ORsJ0vy3); o2WysrOISH = dseries(eval(sprintf(VbO4y7zOlh, U7ORsJ0vy3{:})), [], U7ORsJ0vy3);
return return % --*-- Unit tests --*--
%@test:1 %@test:1
% Write a data file % Write a data file

View File

@ -1,4 +1,4 @@
function P=lyapunov_solver(T,R,Q,DynareOptions) % --*-- Unitary tests --*-- function P=lyapunov_solver(T,R,Q,DynareOptions)
% function P=lyapunov_solver(T,R,Q,DynareOptions) % function P=lyapunov_solver(T,R,Q,DynareOptions)
% Solves the Lyapunov equation P-T*P*T' = R*Q*R' arising in a state-space % Solves the Lyapunov equation P-T*P*T' = R*Q*R' arising in a state-space
% system, where P is the variance of the states % system, where P is the variance of the states
@ -23,7 +23,7 @@ function P=lyapunov_solver(T,R,Q,DynareOptions) % --*-- Unitary tests --*--
% Square-root solver for discrete-time Lyapunov equations (requires Matlab System Control toolbox % Square-root solver for discrete-time Lyapunov equations (requires Matlab System Control toolbox
% or Octave control package) % or Octave control package)
% Copyright © 2016-2022 Dynare Team % Copyright © 2016-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -65,122 +65,124 @@ else
P = lyapunov_symm(T,R*Q*R',DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold, [], DynareOptions.debug); P = lyapunov_symm(T,R*Q*R',DynareOptions.lyapunov_fixed_point_tol,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold, [], DynareOptions.debug);
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ t = NaN(13,1); t = NaN(13,1);
%$ options_.lyapunov_complex_threshold = 1e-15; options_.lyapunov_complex_threshold = 1e-15;
%$ options_.qz_zero_threshold = 1e-6; options_.qz_zero_threshold = 1e-6;
%$ options_.qz_criterium=1-options_.qz_zero_threshold; options_.qz_criterium=1-options_.qz_zero_threshold;
%$ options_.lyapunov_fixed_point_tol = 1e-10; options_.lyapunov_fixed_point_tol = 1e-10;
%$ options_.lyapunov_doubling_tol = 1e-16; options_.lyapunov_doubling_tol = 1e-16;
%$ options_.debug=false; options_.debug=false;
%$
%$ n_small=8; n_small=8;
%$ m_small=10; m_small=10;
%$ T_small=randn(n_small,n_small); T_small=randn(n_small,n_small);
%$ T_small=0.99*T_small/max(abs(eigs(T_small))); T_small=0.99*T_small/max(abs(eigs(T_small)));
%$ tmp2=randn(m_small,m_small); tmp2=randn(m_small,m_small);
%$ Q_small=tmp2*tmp2'; Q_small=tmp2*tmp2';
%$ R_small=randn(n_small,m_small); R_small=randn(n_small,m_small);
%$
%$ n_large=9; n_large=9;
%$ m_large=11; m_large=11;
%$ T_large=randn(n_large,n_large); T_large=randn(n_large,n_large);
%$ T_large=0.99*T_large/max(abs(eigs(T_large))); T_large=0.99*T_large/max(abs(eigs(T_large)));
%$ tmp2=randn(m_large,m_large); tmp2=randn(m_large,m_large);
%$ Q_large=tmp2*tmp2'; Q_large=tmp2*tmp2';
%$ R_large=randn(n_large,m_large); R_large=randn(n_large,m_large);
%$
%$ % DynareOptions.lyapunov_fp == 1 % DynareOptions.lyapunov_fp == 1
%$ options_.lyapunov_fp = true; options_.lyapunov_fp = true;
%$ try try
%$ Pstar1_small = lyapunov_solver(T_small,R_small,Q_small,options_); Pstar1_small = lyapunov_solver(T_small,R_small,Q_small,options_);
%$ Pstar1_large = lyapunov_solver(T_large,R_large,Q_large,options_); Pstar1_large = lyapunov_solver(T_large,R_large,Q_large,options_);
%$ t(1) = 1; t(1) = 1;
%$ catch catch
%$ t(1) = 0; t(1) = 0;
%$ end end
%$
%$ % Dynareoptions.lyapunov_db == 1 % Dynareoptions.lyapunov_db == 1
%$ options_.lyapunov_fp = false; options_.lyapunov_fp = false;
%$ options_.lyapunov_db = true; options_.lyapunov_db = true;
%$ try try
%$ Pstar2_small = lyapunov_solver(T_small,R_small,Q_small,options_); Pstar2_small = lyapunov_solver(T_small,R_small,Q_small,options_);
%$ Pstar2_large = lyapunov_solver(T_large,R_large,Q_large,options_); Pstar2_large = lyapunov_solver(T_large,R_large,Q_large,options_);
%$ t(2) = 1; t(2) = 1;
%$ catch catch
%$ t(2) = 0; t(2) = 0;
%$ end end
%$
%$ % Dynareoptions.lyapunov_srs == 1 % Dynareoptions.lyapunov_srs == 1
%$ if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox')) if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
%$ options_.lyapunov_db = false; options_.lyapunov_db = false;
%$ options_.lyapunov_srs = true; options_.lyapunov_srs = true;
%$ try try
%$ Pstar3_small = lyapunov_solver(T_small,R_small,Q_small,options_); Pstar3_small = lyapunov_solver(T_small,R_small,Q_small,options_);
%$ Pstar3_large = lyapunov_solver(T_large,R_large,Q_large,options_); Pstar3_large = lyapunov_solver(T_large,R_large,Q_large,options_);
%$ t(3) = 1; t(3) = 1;
%$ catch catch
%$ t(3) = 0; t(3) = 0;
%$ end end
%$ else else
%$ t(3) = 1; t(3) = 1;
%$ end end
%$
%$ % Standard % Standard
%$ options_.lyapunov_srs = false; options_.lyapunov_srs = false;
%$ try try
%$ Pstar4_small = lyapunov_solver(T_small,R_small,Q_small,options_); Pstar4_small = lyapunov_solver(T_small,R_small,Q_small,options_);
%$ Pstar4_large = lyapunov_solver(T_large,R_large,Q_large,options_); Pstar4_large = lyapunov_solver(T_large,R_large,Q_large,options_);
%$ t(4) = 1; t(4) = 1;
%$ catch catch
%$ t(4) = 0; t(4) = 0;
%$ end end
%$
%$ % Test the results. % Test the results.
%$
%$ if max(max(abs(Pstar1_small-Pstar2_small)))>1e-8 if max(max(abs(Pstar1_small-Pstar2_small)))>1e-8
%$ t(5) = 0; t(5) = 0;
%$ else else
%$ t(5) = 1; t(5) = 1;
%$ end end
%$
%$ if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox')) if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
%$ if max(max(abs(Pstar1_small-Pstar3_small)))>1e-8 if max(max(abs(Pstar1_small-Pstar3_small)))>1e-8
%$ t(6) = 0; t(6) = 0;
%$ else else
%$ t(6) = 1; t(6) = 1;
%$ end end
%$ else else
%$ t(6) = 1; t(6) = 1;
%$ end end
%$
%$ if max(max(abs(Pstar1_small-Pstar4_small)))>1e-8 if max(max(abs(Pstar1_small-Pstar4_small)))>1e-8
%$ t(7) = 0; t(7) = 0;
%$ else else
%$ t(7) = 1; t(7) = 1;
%$ end end
%$
%$ if max(max(abs(Pstar1_large-Pstar2_large)))>2e-8 if max(max(abs(Pstar1_large-Pstar2_large)))>2e-8
%$ t(8) = 0; t(8) = 0;
%$ else else
%$ t(8) = 1; t(8) = 1;
%$ end end
%$
%$ if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox')) if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
%$ if max(max(abs(Pstar1_large-Pstar3_large)))>1e-8 if max(max(abs(Pstar1_large-Pstar3_large)))>1e-8
%$ t(9) = 0; t(9) = 0;
%$ else else
%$ t(9) = 1; t(9) = 1;
%$ end end
%$ else else
%$ t(9) = 1; t(9) = 1;
%$ end end
%$
%$ if max(max(abs(Pstar1_large-Pstar4_large)))>2e-8 if max(max(abs(Pstar1_large-Pstar4_large)))>2e-8
%$ t(10) = 0; t(10) = 0;
%$ else else
%$ t(10) = 1; t(10) = 1;
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function [x,u] = lyapunov_symm(a,b,lyapunov_fixed_point_tol,qz_criterium,lyapunov_complex_threshold,method,debug) % --*-- Unitary tests --*-- function [x,u] = lyapunov_symm(a,b,lyapunov_fixed_point_tol,qz_criterium,lyapunov_complex_threshold,method,debug)
% Solves the Lyapunov equation x-a*x*a' = b, for b and x symmetric matrices. % Solves the Lyapunov equation x-a*x*a' = b, for b and x symmetric matrices.
% If a has some unit roots, the function computes only the solution of the stable subsystem. % If a has some unit roots, the function computes only the solution of the stable subsystem.
% %
@ -25,7 +25,7 @@ function [x,u] = lyapunov_symm(a,b,lyapunov_fixed_point_tol,qz_criterium,lyapuno
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% None % None
% Copyright © 2006-2017 Dynare Team % Copyright © 2006-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -163,4 +163,4 @@ if i == 1
x(1,1) = (B(1,1)+c)/(1-T(1,1)*T(1,1)); x(1,1) = (B(1,1)+c)/(1-T(1,1)*T(1,1));
end end
x = U(:,k+1:end)*x*U(:,k+1:end)'; x = U(:,k+1:end)*x*U(:,k+1:end)';
u = U(:,1:k); u = U(:,1:k);

View File

@ -1,4 +1,4 @@
function [X, info] = cycle_reduction(A0, A1, A2, cvg_tol, ch) % --*-- Unitary tests --*-- function [X, info] = cycle_reduction(A0, A1, A2, cvg_tol, ch)
%@info: %@info:
%! @deftypefn {Function File} {[@var{X}, @var{info}] =} cycle_reduction (@var{A0},@var{A1},@var{A2},@var{cvg_tol},@var{ch}) %! @deftypefn {Function File} {[@var{X}, @var{info}] =} cycle_reduction (@var{A0},@var{A1},@var{A2},@var{cvg_tol},@var{ch})
@ -43,7 +43,7 @@ function [X, info] = cycle_reduction(A0, A1, A2, cvg_tol, ch) % --*-- Unitary te
%! @end deftypefn %! @end deftypefn
%@eod: %@eod:
% Copyright © 2013-2017 Dynare Team % Copyright © 2013-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -112,40 +112,42 @@ if (nargin == 5 && ~isempty(ch) )
end end
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$
%$ t = zeros(3,1); t = zeros(3,1);
%$
%$ % Set the dimension of the problem to be solved. % Set the dimension of the problem to be solved.
%$ n = 500; n = 500;
%$
%$ % Set the equation to be solved % Set the equation to be solved
%$ A = eye(n); A = eye(n);
%$ B = diag(30*ones(n,1)); B(1,1) = 20; B(end,end) = 20; B = B - diag(10*ones(n-1,1),-1); B = B - diag(10*ones(n-1,1),1); B = diag(30*ones(n,1)); B(1,1) = 20; B(end,end) = 20; B = B - diag(10*ones(n-1,1),-1); B = B - diag(10*ones(n-1,1),1);
%$ C = diag(15*ones(n,1)); C = C - diag(5*ones(n-1,1),-1); C = C - diag(5*ones(n-1,1),1); C = diag(15*ones(n,1)); C = C - diag(5*ones(n-1,1),-1); C = C - diag(5*ones(n-1,1),1);
%$
%$ % Solve the equation with the cycle reduction algorithm % Solve the equation with the cycle reduction algorithm
%$ try try
%$ tic; X1 = cycle_reduction(C,B,A,1e-7); elapsedtime = toc; tic; X1 = cycle_reduction(C,B,A,1e-7); elapsedtime = toc;
%$ disp(['Elapsed time for cycle reduction algorithm is: ' num2str(elapsedtime) ' (n=' int2str(n) ').']) disp(['Elapsed time for cycle reduction algorithm is: ' num2str(elapsedtime) ' (n=' int2str(n) ').'])
%$ t(1) = 1; t(1) = 1;
%$ catch catch
%$ % nothing to do here. % nothing to do here.
%$ end end
%$
%$ % Solve the equation with the logarithmic reduction algorithm % Solve the equation with the logarithmic reduction algorithm
%$ try try
%$ tic; X2 = logarithmic_reduction(A,B,C,1e-16,100); elapsedtime = toc; tic; X2 = logarithmic_reduction(A,B,C,1e-16,100); elapsedtime = toc;
%$ disp(['Elapsed time for logarithmic reduction algorithm is: ' num2str(elapsedtime) ' (n=' int2str(n) ').']) disp(['Elapsed time for logarithmic reduction algorithm is: ' num2str(elapsedtime) ' (n=' int2str(n) ').'])
%$ t(2) = 1; t(2) = 1;
%$ catch catch
%$ % nothing to do here. % nothing to do here.
%$ end end
%$
%$ % Check the results. % Check the results.
%$ if t(1) && t(2) if t(1) && t(2)
%$ t(3) = dassert(X1,X2,1e-12); t(3) = dassert(X1,X2,1e-12);
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function [y, y_] = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, a, b, c) % --*-- Unitary tests --*-- function [y, y_] = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, a, b, c)
% Given the demeaned states (yhat) and structural innovations (epsilon), this routine computes the level of selected endogenous variables when the % Given the demeaned states (yhat) and structural innovations (epsilon), this routine computes the level of selected endogenous variables when the
% model is approximated by an order two taylor expansion around the deterministic steady state. Depending on the number of input/output % model is approximated by an order two taylor expansion around the deterministic steady state. Depending on the number of input/output
@ -26,7 +26,7 @@ function [y, y_] = local_state_space_iteration_2(yhat, epsilon, ghx, ghu, consta
% 1. If the function has more than nine input arguments (pruning) then it must have two output arguments (otherwise only one input). % 1. If the function has more than nine input arguments (pruning) then it must have two output arguments (otherwise only one input).
% 2. Ninth input argument is not used, it is here only to have a common interface with the mex version. % 2. Ninth input argument is not used, it is here only to have a common interface with the mex version.
% Copyright © 2011-2022 Dynare Team % Copyright © 2011-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -77,7 +77,7 @@ else
end end
end end
return return % --*-- Unit tests --*--
%@test:1 %@test:1
n = 2; n = 2;

View File

@ -1,4 +1,4 @@
function [ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhreshold) % --*-- Unitary tests --*-- function [ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhreshold)
% %
% INPUTS % INPUTS
% e [double] real square (n*n) matrix. % e [double] real square (n*n) matrix.
@ -18,7 +18,7 @@ function [ss, tt, zz, sdim, eigval, info] = mjdgges(e, d, qz_criterium, zhreshol
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none. % none.
% Copyright © 1996-2022 Dynare Team % Copyright © 1996-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -66,18 +66,20 @@ catch
info = 1; % Not as precise as lapack's info! info = 1; % Not as precise as lapack's info!
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ try try
%$ E =[0,0,0,0,0,0,0,-1,0,0;0,0,0,0,0,0,0,0,-1,0;0,0,0,0,0,0,0,0,0,-0.990099009900990;0,0,0,0,0,0,0,0,0,0.0990099009900990;0,0,0,-1.01010101010101,0,0.0427672955974843,0,0,0,0;0,0,0,0,0,0.128301886792453,-1,0,0,0;0.800000000000000,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,1,0,0,0;0,0,0.900000000000000,0,0,0,0,0,0,0;0,0,0,-1.01010101010101,-1,0,2,0,-1,0]; E =[0,0,0,0,0,0,0,-1,0,0;0,0,0,0,0,0,0,0,-1,0;0,0,0,0,0,0,0,0,0,-0.990099009900990;0,0,0,0,0,0,0,0,0,0.0990099009900990;0,0,0,-1.01010101010101,0,0.0427672955974843,0,0,0,0;0,0,0,0,0,0.128301886792453,-1,0,0,0;0.800000000000000,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,1,0,0,0;0,0,0.900000000000000,0,0,0,0,0,0,0;0,0,0,-1.01010101010101,-1,0,2,0,-1,0];
%$ D=[0,0,0,0,-1,0,0,-0.792000000000000,0,0;0,0,0,0,0,0,0,0,-0.990000000000000,0;0,0,0,-0.000493818030899887,0,0,0,0,0,-0.882178217821782;0,0,0,-1.00493818030900,0,0,0,0,0,0.0882178217821782;0,0,0,-1,0.128301886792453,0,0,0,0,0;-1,0,0,0,0,0,-0.990000000000000,0,0,0;1,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0,0,0;0,0,1,0,0,0,0,0,0,0;0,0,0,0,-1,0,0,0,0,0]; D=[0,0,0,0,-1,0,0,-0.792000000000000,0,0;0,0,0,0,0,0,0,0,-0.990000000000000,0;0,0,0,-0.000493818030899887,0,0,0,0,0,-0.882178217821782;0,0,0,-1.00493818030900,0,0,0,0,0,0.0882178217821782;0,0,0,-1,0.128301886792453,0,0,0,0,0;-1,0,0,0,0,0,-0.990000000000000,0,0,0;1,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0,0,0;0,0,1,0,0,0,0,0,0,0;0,0,0,0,-1,0,0,0,0,0];
%$ [ss, tt, w, sdim, dr.eigval, info1]=mjdgges(E, D, 1.000001, 1e-06); [ss, tt, w, sdim, dr.eigval, info1]=mjdgges(E, D, 1.000001, 1e-06);
%$ if sdim==5 if sdim==5
%$ t(1) = 1; t(1) = 1;
%$ else else
%$ t(1) = 0; t(1) = 0;
%$ end end
%$ catch catch
%$ t(1) = 0; t(1) = 0;
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function retval = corr(x, y) % --*-- Unitary tests --*-- function retval = corr(x, y)
%@info: %@info:
%! @deftypefn {Function File} {} corr (@var{x}) %! @deftypefn {Function File} {} corr (@var{x})
%! @deftypefnx {Function File} {} corr (@var{x}, @var{y}) %! @deftypefnx {Function File} {} corr (@var{x}, @var{y})
@ -39,7 +39,7 @@ function retval = corr(x, y) % --*-- Unitary tests --*--
% Copyright © 1993-1996 Kurt Hornik % Copyright © 1993-1996 Kurt Hornik
% Copyright © 1996-2015 John W. Eaton % Copyright © 1996-2015 John W. Eaton
% Copyright © 2013-2015 Julien Bect % Copyright © 2013-2015 Julien Bect
% Copyright © 2016-2017 Dynare Team % Copyright © 2016-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -110,79 +110,77 @@ c = x'*y;
s = sx'*sy; s = sx'*sy;
retval = c./(n * s); retval = c./(n * s);
return % --*-- Unit tests --*--
end
%@test:1 %@test:1
%$ x = rand (10); x = rand (10);
%$ cc1 = corr(x); cc1 = corr(x);
%$ cc2 = corr(x, x); cc2 = corr(x, x);
%$ t(1) = dassert(size(cc1),[10, 10]); t(1) = dassert(size(cc1),[10, 10]);
%$ t(2) = dassert(size (cc2),[10, 10]); t(2) = dassert(size (cc2),[10, 10]);
%$ t(3) = dassert(cc1, cc2, sqrt (eps)); t(3) = dassert(cc1, cc2, sqrt (eps));
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ x = [1:3]'; x = [1:3]';
%$ y = [3:-1:1]'; y = [3:-1:1]';
%$ t = zeros(3,1); t = zeros(3,1);
%$ t(1) = dassert(corr(x, y), -1, 5*eps); t(1) = dassert(corr(x, y), -1, 5*eps);
%$ t(2) = dassert(corr(x, flipud (y)), 1, 5*eps); t(2) = dassert(corr(x, flipud (y)), 1, 5*eps);
%$ t(3) = dassert(corr([x, y]), [1 -1; -1 1], 5*eps); t(3) = dassert(corr([x, y]), [1 -1; -1 1], 5*eps);
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ if ~isoctave() if ~isoctave()
%$ t = zeros(3,1); t = zeros(3,1);
%$ t(1) = dassert(corr(5), NaN); t(1) = dassert(corr(5), NaN);
%$ t(2) = dassert(corr([1 2 3],5),NaN(3,1)); t(2) = dassert(corr([1 2 3],5),NaN(3,1));
%$ t(3) = dassert(corr(5,[1 2 3]),NaN(1,3)); t(3) = dassert(corr(5,[1 2 3]),NaN(1,3));
%$ else else
%$ t = 1; t = 1;
%$ end end
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ t = zeros(6,1); t = zeros(6,1);
%$ try try
%$ corr() corr()
%$ t(1) = false; t(1) = false;
%$ catch catch
%$ t(1) = true; t(1) = true;
%$ end end
%$ try try
%$ corr(1, 2, 3) corr(1, 2, 3)
%$ t(2) = false; t(2) = false;
%$ catch catch
%$ t(2) = true; t(2) = true;
%$ end end
%$ try try
%$ corr([1; 2], ['A', 'B']) corr([1; 2], ['A', 'B'])
%$ t(3) = false; t(3) = false;
%$ catch catch
%$ t(3) = true; t(3) = true;
%$ end end
%$ try try
%$ corr([1; 2], ['A', 'B']) corr([1; 2], ['A', 'B'])
%$ t(4) = false; t(4) = false;
%$ catch catch
%$ t(4) = true; t(4) = true;
%$ end end
%$ try try
%$ corr(ones (2,2,2)) corr(ones (2,2,2))
%$ t(5) = false; t(5) = false;
%$ catch catch
%$ t(5) = true; t(5) = true;
%$ end end
%$ try try
%$ corr(ones (2,2), ones (2,2,2)) corr(ones (2,2), ones (2,2,2))
%$ t(6) = false; t(6) = false;
%$ catch catch
%$ t(6) = true; t(6) = true;
%$ end end
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4

View File

@ -1,4 +1,4 @@
function rnd = gamrnd(a, b, method) % --*-- Unitary tests --*-- function rnd = gamrnd(a, b, method)
% This function produces independent random variates from the Gamma distribution. % This function produces independent random variates from the Gamma distribution.
% %
@ -126,7 +126,7 @@ if ~isempty(ddx)
end end
end end
return return % --*-- Unit tests --*--
%@test:1 %@test:1
if ~isoctave && ~user_has_matlab_license('statistics_toolbox') if ~isoctave && ~user_has_matlab_license('statistics_toolbox')

View File

@ -1,4 +1,4 @@
function [q,N] = quantile(X, p, dim, method, weights) % --*-- Unitary tests --*-- function [q,N] = quantile(X, p, dim, method, weights)
% Quantiles of a sample via various methods. % Quantiles of a sample via various methods.
% %
@ -49,7 +49,7 @@ function [q,N] = quantile(X, p, dim, method, weights) % --*-- Unitary tests --*-
% http://fr.mathworks.com/matlabcentral/fileexchange/46555-quantile-calculation % http://fr.mathworks.com/matlabcentral/fileexchange/46555-quantile-calculation
% %
% Copyright © 2014-2016 University of Surrey (Christopher Hummersone) % Copyright © 2014-2016 University of Surrey (Christopher Hummersone)
% Copyright © 2016-2017 Dynare Team % Copyright © 2016-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -234,24 +234,25 @@ function y = irearrange(x,order,shape)
y = reshape(x,shape); y = reshape(x,shape);
y = ipermute(y,order); y = ipermute(y,order);
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ X = randn(10000000, 1); X = randn(10000000, 1);
%$
%$ try try
%$ q = quantile(X, [.25, .5, .75, .95 ]); q = quantile(X, [.25, .5, .75, .95 ]);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ e = [-0.674489750196082, 0, 0.674489750196082, 1.644853626951472]; e = [-0.674489750196082, 0, 0.674489750196082, 1.644853626951472];
%$
%$ if t(1) if t(1)
%$ for i=1:4 for i=1:4
%$ t(i+1) = abs(q(i)-e(i))<2e-3; t(i+1) = abs(q(i)-e(i))<2e-3;
%$ end end
%$ end end
%$
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function p = wblcdf(x, scale, shape) % --*-- Unitary tests --*-- function p = wblcdf(x, scale, shape)
% Cumulative distribution function for the Weibull distribution. % Cumulative distribution function for the Weibull distribution.
% %
@ -10,7 +10,7 @@ function p = wblcdf(x, scale, shape) % --*-- Unitary tests --*--
% OUTPUTS % OUTPUTS
% - p [double] Positive scalar between % - p [double] Positive scalar between
% Copyright © 2015-2017 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -63,86 +63,86 @@ end
p = 1-exp(-(x/scale)^shape); p = 1-exp(-(x/scale)^shape);
%@test:1 %@test:1
%$ try try
%$ p = wblcdf(-1, .5, .1); p = wblcdf(-1, .5, .1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = isequal(p, 0); t(2) = isequal(p, 0);
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ try try
%$ p = wblcdf(Inf, .5, .1); p = wblcdf(Inf, .5, .1);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = isequal(p, 1); t(2) = isequal(p, 1);
%$ end end
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ % Set the hyperparameters of a Weibull definition. % Set the hyperparameters of a Weibull definition.
%$ scale = .5; scale = .5;
%$ shape = 1.5; shape = 1.5;
%$
%$ % Compute the median of the weibull distribution. % Compute the median of the weibull distribution.
%$ m = scale*log(2)^(1/shape); m = scale*log(2)^(1/shape);
%$
%$ try try
%$ p = wblcdf(m, scale, shape); p = wblcdf(m, scale, shape);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ t(2) = abs(p-.5)<1e-12; t(2) = abs(p-.5)<1e-12;
%$ end end
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ % Consistency check between wblinv and wblcdf. % Consistency check between wblinv and wblcdf.
%$
%$ % Set the hyperparameters of a Weibull definition. % Set the hyperparameters of a Weibull definition.
%$ scale = .5; scale = .5;
%$ shape = 1.5; shape = 1.5;
%$
%$ % Compute quatiles of the weibull distribution. % Compute quatiles of the weibull distribution.
%$ q = 0:.05:1; q = 0:.05:1;
%$ m = zeros(size(q)); m = zeros(size(q));
%$ p = zeros(size(q)); p = zeros(size(q));
%$ for i=1:length(q) for i=1:length(q)
%$ m(i) = wblinv(q(i), scale, shape); m(i) = wblinv(q(i), scale, shape);
%$ end end
%$
%$ try try
%$ for i=1:length(q) for i=1:length(q)
%$ p(i) = wblcdf(m(i), scale, shape); p(i) = wblcdf(m(i), scale, shape);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ % Check the results % Check the results
%$ if t(1) if t(1)
%$ for i=1:length(q) for i=1:length(q)
%$ t(i+1) = abs(p(i)-q(i))<1e-12; t(i+1) = abs(p(i)-q(i))<1e-12;
%$ end end
%$ end end
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4

View File

@ -1,4 +1,4 @@
function t = wblinv(proba, scale, shape) % --*-- Unitary tests --*-- function t = wblinv(proba, scale, shape)
% Inverse cumulative distribution function. % Inverse cumulative distribution function.
% %
@ -10,7 +10,7 @@ function t = wblinv(proba, scale, shape) % --*-- Unitary tests --*--
% OUTPUTS % OUTPUTS
% - t [double] scalar such that P(X<=t)=proba % - t [double] scalar such that P(X<=t)=proba
% Copyright © 2015-2020 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -58,110 +58,112 @@ end
t = exp(log(scale)+log(-log(1-proba))/shape); t = exp(log(scale)+log(-log(1-proba))/shape);
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ try try
%$ x = wblinv(0, 1, 2); x = wblinv(0, 1, 2);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = isequal(x, 0); t(2) = isequal(x, 0);
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
%$ try try
%$ x = wblinv(1, 1, 2); x = wblinv(1, 1, 2);
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = isinf(x); t(2) = isinf(x);
%$ end end
%$ T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
%$ scales = [.5, 1, 5]; scales = [.5, 1, 5];
%$ shapes = [.1, 1, 2]; shapes = [.1, 1, 2];
%$ x = NaN(9,1); x = NaN(9,1);
%$
%$ try try
%$ k = 0; k = 0;
%$ for i=1:3 for i=1:3
%$ for j=1:3 for j=1:3
%$ k = k+1; k = k+1;
%$ x(k) = wblinv(.5, scales(i), shapes(j)); x(k) = wblinv(.5, scales(i), shapes(j));
%$ end end
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ k = 1; k = 1;
%$ for i=1:3 for i=1:3
%$ for j=1:3 for j=1:3
%$ k = k+1; k = k+1;
%$ t(k) = abs(x(k-1)-scales(i)*log(2)^(1/shapes(j)))<1e-12; t(k) = abs(x(k-1)-scales(i)*log(2)^(1/shapes(j)))<1e-12;
%$ end end
%$ end end
%$ end end
%$ T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
%$ debug = false; debug = false;
%$ scales = [ .5, 1, 5]; scales = [ .5, 1, 5];
%$ shapes = [ 1, 2, 3]; shapes = [ 1, 2, 3];
%$ x = NaN(9,1); x = NaN(9,1);
%$ p = 1e-1; p = 1e-1;
%$
%$ try try
%$ k = 0; k = 0;
%$ for i=1:3 for i=1:3
%$ for j=1:3 for j=1:3
%$ k = k+1; k = k+1;
%$ x(k) = wblinv(p, scales(i), shapes(j)); x(k) = wblinv(p, scales(i), shapes(j));
%$ end end
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ k = 1; k = 1;
%$ for i=1:3 for i=1:3
%$ for j=1:3 for j=1:3
%$ k = k+1; k = k+1;
%$ shape = shapes(j); shape = shapes(j);
%$ scale = scales(i); scale = scales(i);
%$ density = @(z) exp(lpdfgweibull(z,shape,scale)); density = @(z) exp(lpdfgweibull(z,shape,scale));
%$ if debug if debug
%$ [shape, scale, x(k-1)] [shape, scale, x(k-1)]
%$ end end
%$ if isoctave if isoctave
%$ s = quadv(density, 0, x(k-1),1e-10); s = quadv(density, 0, x(k-1),1e-10);
%$ else else
%$ s = integral(density, 0, x(k-1)); s = integral(density, 0, x(k-1));
%$ end end
%$ if debug if debug
%$ [s, abs(p-s)] [s, abs(p-s)]
%$ end end
%$ if isoctave if isoctave
%$ t(k) = abs(p-s)<1e-9; t(k) = abs(p-s)<1e-9;
%$ else else
%$ t(k) = abs(p-s)<1e-12; t(k) = abs(p-s)<1e-12;
%$ end end
%$ end end
%$ end end
%$ end end
%$ T = all(t); T = all(t);
%@eof:4 %@eof:4

@ -1 +1 @@
Subproject commit a519e8a68177e2a5beccff3d04ddcb9e4f64030d Subproject commit f2960bf774113d278eeb43faf9a30c31495e6843

View File

@ -1,4 +1,4 @@
function pdraw = prior_draw(BayesInfo, prior_trunc, uniform) % --*-- Unitary tests --*-- function pdraw = prior_draw(BayesInfo, prior_trunc, uniform)
% This function generate one draw from the joint prior distribution and % This function generate one draw from the joint prior distribution and
% allows sampling uniformly from the prior support (uniform==1 when called with init==1) % allows sampling uniformly from the prior support (uniform==1 when called with init==1)
@ -26,7 +26,7 @@ function pdraw = prior_draw(BayesInfo, prior_trunc, uniform) % --*-- Unitary tes
% NOTE 3. This code relies on bayestopt_ as created in the base workspace % NOTE 3. This code relies on bayestopt_ as created in the base workspace
% by the preprocessor (or as updated in subsequent pieces of code and handed to the base workspace) % by the preprocessor (or as updated in subsequent pieces of code and handed to the base workspace)
% %
% Copyright © 2006-2017 Dynare Team % Copyright © 2006-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -174,101 +174,103 @@ if weibull_draws
end end
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ % Fill global structures with required fields... % Fill global structures with required fields...
%$ prior_trunc = 1e-10; prior_trunc = 1e-10;
%$ p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
%$ p1 = .4*ones(14,1); % Prior mean p1 = .4*ones(14,1); % Prior mean
%$ p2 = .2*ones(14,1); % Prior std. p2 = .2*ones(14,1); % Prior std.
%$ p3 = NaN(14,1); p3 = NaN(14,1);
%$ p4 = NaN(14,1); p4 = NaN(14,1);
%$ p5 = NaN(14,1); p5 = NaN(14,1);
%$ p6 = NaN(14,1); p6 = NaN(14,1);
%$ p7 = NaN(14,1); p7 = NaN(14,1);
%$
%$ for i=1:14 for i=1:14
%$ switch p0(i) switch p0(i)
%$ case 1 case 1
%$ % Beta distribution % Beta distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = 1; p4(i) = 1;
%$ [p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i)); [p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 1); p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
%$ case 2 case 2
%$ % Gamma distribution % Gamma distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i)); [p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 2); p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
%$ case 3 case 3
%$ % Normal distribution % Normal distribution
%$ p3(i) = -Inf; p3(i) = -Inf;
%$ p4(i) = Inf; p4(i) = Inf;
%$ p6(i) = p1(i); p6(i) = p1(i);
%$ p7(i) = p2(i); p7(i) = p2(i);
%$ p5(i) = p1(i); p5(i) = p1(i);
%$ case 4 case 4
%$ % Inverse Gamma (type I) distribution % Inverse Gamma (type I) distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false); [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 4); p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
%$ case 5 case 5
%$ % Uniform distribution % Uniform distribution
%$ [p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i)); [p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
%$ p3(i) = p6(i); p3(i) = p6(i);
%$ p4(i) = p7(i); p4(i) = p7(i);
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 5); p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
%$ case 6 case 6
%$ % Inverse Gamma (type II) distribution % Inverse Gamma (type II) distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false); [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 6); p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
%$ case 8 case 8
%$ % Weibull distribution % Weibull distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i)); [p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 8); p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
%$ otherwise otherwise
%$ error('This density is not implemented!') error('This density is not implemented!')
%$ end end
%$ end end
%$
%$ BayesInfo.pshape = p0; BayesInfo.pshape = p0;
%$ BayesInfo.p1 = p1; BayesInfo.p1 = p1;
%$ BayesInfo.p2 = p2; BayesInfo.p2 = p2;
%$ BayesInfo.p3 = p3; BayesInfo.p3 = p3;
%$ BayesInfo.p4 = p4; BayesInfo.p4 = p4;
%$ BayesInfo.p5 = p5; BayesInfo.p5 = p5;
%$ BayesInfo.p6 = p6; BayesInfo.p6 = p6;
%$ BayesInfo.p7 = p7; BayesInfo.p7 = p7;
%$
%$ ndraws = 1e5; ndraws = 1e5;
%$ m0 = BayesInfo.p1; %zeros(14,1); m0 = BayesInfo.p1; %zeros(14,1);
%$ v0 = diag(BayesInfo.p2.^2); %zeros(14); v0 = diag(BayesInfo.p2.^2); %zeros(14);
%$
%$ % Call the tested routine % Call the tested routine
%$ try try
%$ % Initialization of prior_draws. % Initialization of prior_draws.
%$ prior_draw(BayesInfo, prior_trunc, false); prior_draw(BayesInfo, prior_trunc, false);
%$ % Do simulations in a loop and estimate recursively the mean and teh variance. % Do simulations in a loop and estimate recursively the mean and teh variance.
%$ for i = 1:ndraws for i = 1:ndraws
%$ draw = transpose(prior_draw()); draw = transpose(prior_draw());
%$ m1 = m0 + (draw-m0)/i; m1 = m0 + (draw-m0)/i;
%$ m2 = m1*m1'; m2 = m1*m1';
%$ v0 = v0 + ((draw*draw'-m2-v0) + (i-1)*(m0*m0'-m2'))/i; v0 = v0 + ((draw*draw'-m2-v0) + (i-1)*(m0*m0'-m2'))/i;
%$ m0 = m1; m0 = m1;
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = all(abs(m0-BayesInfo.p1)<3e-3); t(2) = all(abs(m0-BayesInfo.p1)<3e-3);
%$ t(3) = all(all(abs(v0-diag(BayesInfo.p2.^2))<5e-3)); t(3) = all(all(abs(v0-diag(BayesInfo.p2.^2))<5e-3));
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function [logged_prior_density, dlprior, d2lprior, info] = priordens(x, pshape, p6, p7, p3, p4, initialization) % --*-- Unitary tests --*-- function [logged_prior_density, dlprior, d2lprior, info] = priordens(x, pshape, p6, p7, p3, p4, initialization)
% Computes a prior density for the structural parameters of DSGE models % Computes a prior density for the structural parameters of DSGE models
% %
% INPUTS % INPUTS
@ -15,7 +15,7 @@ function [logged_prior_density, dlprior, d2lprior, info] = priordens(x, pshape,
% info [double] error code for index of Inf-prior parameter % info [double] error code for index of Inf-prior parameter
% %
% Copyright © 2003-2017 Dynare Team % Copyright © 2003-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -191,85 +191,87 @@ if nargout==3
d2lprior = diag(d2lprior); d2lprior = diag(d2lprior);
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ % Fill global structures with required fields... % Fill global structures with required fields...
%$ prior_trunc = 1e-10; prior_trunc = 1e-10;
%$ p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape p0 = repmat([1; 2; 3; 4; 5; 6; 8], 2, 1); % Prior shape
%$ p1 = .4*ones(14,1); % Prior mean p1 = .4*ones(14,1); % Prior mean
%$ p2 = .2*ones(14,1); % Prior std. p2 = .2*ones(14,1); % Prior std.
%$ p3 = NaN(14,1); p3 = NaN(14,1);
%$ p4 = NaN(14,1); p4 = NaN(14,1);
%$ p5 = NaN(14,1); p5 = NaN(14,1);
%$ p6 = NaN(14,1); p6 = NaN(14,1);
%$ p7 = NaN(14,1); p7 = NaN(14,1);
%$
%$ for i=1:14 for i=1:14
%$ switch p0(i) switch p0(i)
%$ case 1 case 1
%$ % Beta distribution % Beta distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = 1; p4(i) = 1;
%$ [p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i)); [p6(i), p7(i)] = beta_specification(p1(i), p2(i)^2, p3(i), p4(i));
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 1); p5(i) = compute_prior_mode([p6(i) p7(i)], 1);
%$ case 2 case 2
%$ % Gamma distribution % Gamma distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i)); [p6(i), p7(i)] = gamma_specification(p1(i), p2(i)^2, p3(i), p4(i));
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 2); p5(i) = compute_prior_mode([p6(i) p7(i)], 2);
%$ case 3 case 3
%$ % Normal distribution % Normal distribution
%$ p3(i) = -Inf; p3(i) = -Inf;
%$ p4(i) = Inf; p4(i) = Inf;
%$ p6(i) = p1(i); p6(i) = p1(i);
%$ p7(i) = p2(i); p7(i) = p2(i);
%$ p5(i) = p1(i); p5(i) = p1(i);
%$ case 4 case 4
%$ % Inverse Gamma (type I) distribution % Inverse Gamma (type I) distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false); [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 1, false);
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 4); p5(i) = compute_prior_mode([p6(i) p7(i)], 4);
%$ case 5 case 5
%$ % Uniform distribution % Uniform distribution
%$ [p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i)); [p1(i), p2(i), p6(i), p7(i)] = uniform_specification(p1(i), p2(i), p3(i), p4(i));
%$ p3(i) = p6(i); p3(i) = p6(i);
%$ p4(i) = p7(i); p4(i) = p7(i);
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 5); p5(i) = compute_prior_mode([p6(i) p7(i)], 5);
%$ case 6 case 6
%$ % Inverse Gamma (type II) distribution % Inverse Gamma (type II) distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false); [p6(i), p7(i)] = inverse_gamma_specification(p1(i), p2(i)^2, p3(i), 2, false);
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 6); p5(i) = compute_prior_mode([p6(i) p7(i)], 6);
%$ case 8 case 8
%$ % Weibull distribution % Weibull distribution
%$ p3(i) = 0; p3(i) = 0;
%$ p4(i) = Inf; p4(i) = Inf;
%$ [p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i)); [p6(i), p7(i)] = weibull_specification(p1(i), p2(i)^2, p3(i));
%$ p5(i) = compute_prior_mode([p6(i) p7(i)], 8); p5(i) = compute_prior_mode([p6(i) p7(i)], 8);
%$ otherwise otherwise
%$ error('This density is not implemented!') error('This density is not implemented!')
%$ end end
%$ end end
%$
%$ % Call the tested routine % Call the tested routine
%$ try try
%$ % Initialization of priordens. % Initialization of priordens.
%$ lpdstar = priordens(p5, p0, p6, p7, p3, p4, true); lpdstar = priordens(p5, p0, p6, p7, p3, p4, true);
%$ % Do simulations in a loop and estimate recursively the mean and teh variance. % Do simulations in a loop and estimate recursively the mean and teh variance.
%$ LPD = NaN(10000,1); LPD = NaN(10000,1);
%$ for i = 1:10000 for i = 1:10000
%$ draw = p5+randn(size(p5))*.02; draw = p5+randn(size(p5))*.02;
%$ LPD(i) = priordens(p5, p0, p6, p7, p3, p4); LPD(i) = priordens(p5, p0, p6, p7, p3, p4);
%$ end end
%$ t(1) = true; t(1) = true;
%$ catch catch
%$ t(1) = false; t(1) = false;
%$ end end
%$
%$ if t(1) if t(1)
%$ t(2) = all(LPD<=lpdstar); t(2) = all(LPD<=lpdstar);
%$ end end
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

View File

@ -1,4 +1,4 @@
function C = compare_vectors(f, A, B) % --*-- Unitary tests --*-- function C = compare_vectors(f, A, B)
% Performs lexicographical comparison of vectors. % Performs lexicographical comparison of vectors.
% %
@ -13,7 +13,7 @@ function C = compare_vectors(f, A, B) % --*-- Unitary tests --*--
% REMARKS % REMARKS
% o It is assumed that vectors A and B have the same number of elements. % o It is assumed that vectors A and B have the same number of elements.
% Copyright © 2013-2017 Dynare Team % Copyright © 2013-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -76,19 +76,21 @@ else
end end
end end
return % --*-- Unit tests --*--
%@test:1 %@test:1
%$ t(1) = dassert(compare_vectors(@lt, [1990 3], [1991 3]), 1); t(1) = dassert(compare_vectors(@lt, [1990 3], [1991 3]), 1);
%$ t(2) = dassert(compare_vectors(@lt, [1990 3], [1990 3]), 0); t(2) = dassert(compare_vectors(@lt, [1990 3], [1990 3]), 0);
%$ t(3) = dassert(compare_vectors(@le, [1990 3], [1990 3]), 1); t(3) = dassert(compare_vectors(@le, [1990 3], [1990 3]), 1);
%$ t(4) = dassert(compare_vectors(@lt, [1990 3], [1990 4]), 1); t(4) = dassert(compare_vectors(@lt, [1990 3], [1990 4]), 1);
%$ t(5) = dassert(compare_vectors(@le, [1990 3], [1990 4]), 1); t(5) = dassert(compare_vectors(@le, [1990 3], [1990 4]), 1);
%$ t(6) = dassert(compare_vectors(@gt, [1990 3], [1991 3]), 0); t(6) = dassert(compare_vectors(@gt, [1990 3], [1991 3]), 0);
%$ t(7) = dassert(compare_vectors(@gt, [1990 3], [1990 3]), 0); t(7) = dassert(compare_vectors(@gt, [1990 3], [1990 3]), 0);
%$ t(8) = dassert(compare_vectors(@ge, [1990 3], [1990 3]), 1); t(8) = dassert(compare_vectors(@ge, [1990 3], [1990 3]), 1);
%$ t(9) = dassert(compare_vectors(@gt, [1990 3], [1990 4]), 0); t(9) = dassert(compare_vectors(@gt, [1990 3], [1990 4]), 0);
%$ t(10) = dassert(compare_vectors(@ge, [1990 3], [1990 4]), 0); t(10) = dassert(compare_vectors(@ge, [1990 3], [1990 4]), 0);
%$ t(11) = dassert(compare_vectors(@le, [1991 3], [1990 4]), 0); t(11) = dassert(compare_vectors(@le, [1991 3], [1990 4]), 0);
%$ t(12) = dassert(compare_vectors(@le, [1991 3], [1990 2]), 0); t(12) = dassert(compare_vectors(@le, [1991 3], [1990 2]), 0);
%$ t(13) = dassert(compare_vectors(@le, [1945 2], [1950, 1]),1); t(13) = dassert(compare_vectors(@le, [1945 2], [1950, 1]),1);
%$ T = all(t); T = all(t);
%@eof:1 %@eof:1

@ -1 +1 @@
Subproject commit 343d9e13654a07c348fad863f7f79a03896c6bc9 Subproject commit 3c4079a8e1e495be50be3cd81855eb37189fceab

View File

@ -1,4 +1,4 @@
function tf = ver_greater_than(ver1, ver2) % --*-- Unitary tests --*-- function tf = ver_greater_than(ver1, ver2)
%function tf = ver_greater_than(ver1, ver2) %function tf = ver_greater_than(ver1, ver2)
% ver1 > ver2 ? 1 : 0; % ver1 > ver2 ? 1 : 0;
% %
@ -12,7 +12,7 @@ function tf = ver_greater_than(ver1, ver2) % --*-- Unitary tests --*--
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright © 2015-2021 Dynare Team % Copyright © 2015-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -30,7 +30,8 @@ function tf = ver_greater_than(ver1, ver2) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
tf = ~ver_less_than(ver1, ver2) && ~strcmp(ver1, ver2); tf = ~ver_less_than(ver1, ver2) && ~strcmp(ver1, ver2);
return
return % --*-- Unit tests --*--
%@test:1 %@test:1
ver2='4.4'; ver2='4.4';
@ -38,18 +39,21 @@ ver1='4.5.2';
t(1)=dassert(ver_greater_than(ver1,ver2),true); t(1)=dassert(ver_greater_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
ver1='6-unstable-2021-12-15-1737-21a8a579'; ver1='6-unstable-2021-12-15-1737-21a8a579';
ver2='4.4'; ver2='4.4';
t(1)=dassert(ver_greater_than(ver1,ver2),true); t(1)=dassert(ver_greater_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
ver2='5.0'; ver2='5.0';
ver1='5.1'; ver1='5.1';
t(1)=dassert(ver_greater_than(ver1,ver2),true); t(1)=dassert(ver_greater_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
ver2='6-unstable-2021-12-18-1227-c43777f6'; ver2='6-unstable-2021-12-18-1227-c43777f6';
ver1='6-unstable-2021-12-19-1953-d841fc7c'; ver1='6-unstable-2021-12-19-1953-d841fc7c';

View File

@ -1,4 +1,4 @@
function tf = ver_less_than(ver1, ver2) % --*-- Unitary tests --*-- function tf = ver_less_than(ver1, ver2)
%function tf = ver_less_than(ver1, ver2) %function tf = ver_less_than(ver1, ver2)
% ver1 < ver2 ? 1 : 0; % ver1 < ver2 ? 1 : 0;
% %
@ -54,7 +54,7 @@ elseif (maj_ver1 == maj_ver2) && (min_ver1 > min_ver2)
end end
%deal with revision in Dynare 4 and unstable versions involved %deal with revision in Dynare 4 and unstable versions involved
if min(maj_ver1,maj_ver2)<5 %old versioning scheme with three digits if min(maj_ver1,maj_ver2)<5 %old versioning scheme with three digits
if (length(ver1) == length(ver2) && length(ver1) == 3) if (length(ver1) == length(ver2) && length(ver1) == 3)
%check if master branch (unstable) or stable %check if master branch (unstable) or stable
ismaster1 = isnan(str2double(ver1{3})); ismaster1 = isnan(str2double(ver1{3}));
@ -63,7 +63,7 @@ if min(maj_ver1,maj_ver2)<5 %old versioning scheme with three digits
%ver2 is the unstable %ver2 is the unstable
return return
end end
if ~ismaster1 && ~ismaster2 %both are stable versions if ~ismaster1 && ~ismaster2 %both are stable versions
rev_ver1 = str2double(ver1{3}); rev_ver1 = str2double(ver1{3});
rev_ver2 = str2double(ver2{3}); rev_ver2 = str2double(ver2{3});
@ -76,7 +76,7 @@ if min(maj_ver1,maj_ver2)<5 %old versioning scheme with three digits
%ver1 is an unstable version %ver1 is an unstable version
error('Case is undefined, please contact the developers') error('Case is undefined, please contact the developers')
end end
elseif min(maj_ver1,maj_ver2)>=5 %new versioning scheme with three digits elseif min(maj_ver1,maj_ver2)>=5 %new versioning scheme with three digits
if strcmp(ver1{2},'x') || strcmp(ver1{2},'unstable') if strcmp(ver1{2},'x') || strcmp(ver1{2},'unstable')
date_number_1=datenum([ver1{3} ver1{4} ver1{5}],'YYYYMMDD'); date_number_1=datenum([ver1{3} ver1{4} ver1{5}],'YYYYMMDD');
stable_version_indicator_1=0; stable_version_indicator_1=0;
@ -102,7 +102,7 @@ elseif min(maj_ver1,maj_ver2)>=5 %new versioning scheme with three digits
end end
tf = false; tf = false;
return return % --*-- Unit tests --*--
%@test:1 %@test:1
ver1='4.4'; ver1='4.4';
@ -110,26 +110,24 @@ ver2='4.5.2';
t(1)=dassert(ver_less_than(ver1,ver2),true); t(1)=dassert(ver_less_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:1 %@eof:1
%@test:2 %@test:2
ver1='4.4'; ver1='4.4';
ver2='6-unstable-2021-12-15-1737-21a8a579'; ver2='6-unstable-2021-12-15-1737-21a8a579';
t(1)=dassert(ver_less_than(ver1,ver2),true); t(1)=dassert(ver_less_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:2 %@eof:2
%@test:3 %@test:3
ver1='5.0'; ver1='5.0';
ver2='5.1'; ver2='5.1';
t(1)=dassert(ver_less_than(ver1,ver2),true); t(1)=dassert(ver_less_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:3 %@eof:3
%@test:4 %@test:4
ver1='6-unstable-2021-12-18-1227-c43777f6'; ver1='6-unstable-2021-12-18-1227-c43777f6';
ver2='6-unstable-2021-12-19-1953-d841fc7c'; ver2='6-unstable-2021-12-19-1953-d841fc7c';
t(1)=dassert(ver_less_than(ver1,ver2),true); t(1)=dassert(ver_less_than(ver1,ver2),true);
T = all(t); T = all(t);
%@eof:4 %@eof:4
% %@test:5
% ver1='5.0';
% ver2='5.x-2021-12-14-1101-25c1e0c0';
% t(5)=dassert(ver_less_than(ver1,ver2),true)

View File

@ -1259,7 +1259,7 @@ M_TRS_FILES = $(patsubst %.mod, %.m.trs, $(MODFILES))
M_TRS_FILES += $(patsubst %.mod, %.m.trs, $(PARTICLEFILES)) M_TRS_FILES += $(patsubst %.mod, %.m.trs, $(PARTICLEFILES))
M_TRS_FILES += run_block_byte_tests_matlab.m.trs \ M_TRS_FILES += run_block_byte_tests_matlab.m.trs \
run_reporting_test_matlab.m.trs \ run_reporting_test_matlab.m.trs \
run_all_unitary_tests.m.trs \ run_all_unit_tests.m.trs \
histval_initval_file_unit_tests.m.trs \ histval_initval_file_unit_tests.m.trs \
test_aggregate_routine_1_2.m.trs \ test_aggregate_routine_1_2.m.trs \
test_aggregate_routine_1_2_3.m.trs \ test_aggregate_routine_1_2_3.m.trs \
@ -1276,7 +1276,7 @@ O_TRS_FILES = $(patsubst %.mod, %.o.trs, $(MODFILES))
O_TRS_FILES += $(patsubst %.mod, %.o.trs, $(PARTICLEFILES)) O_TRS_FILES += $(patsubst %.mod, %.o.trs, $(PARTICLEFILES))
O_TRS_FILES += run_block_byte_tests_octave.o.trs \ O_TRS_FILES += run_block_byte_tests_octave.o.trs \
run_reporting_test_octave.o.trs \ run_reporting_test_octave.o.trs \
run_all_unitary_tests.o.trs \ run_all_unit_tests.o.trs \
histval_initval_file_unit_tests.o.trs \ histval_initval_file_unit_tests.o.trs \
run_kronecker_tests.o.trs \ run_kronecker_tests.o.trs \
nonlinearsolvers.o.trs \ nonlinearsolvers.o.trs \
@ -1306,7 +1306,7 @@ EXTRA_DIST = \
run_block_byte_tests_octave.m \ run_block_byte_tests_octave.m \
run_reporting_test_matlab.m \ run_reporting_test_matlab.m \
run_reporting_test_octave.m \ run_reporting_test_octave.m \
run_all_unitary_tests.m \ run_all_unit_tests.m \
+matlab/+namespace/y_k.m \ +matlab/+namespace/y_k.m \
reporting/AnnualTable.m \ reporting/AnnualTable.m \
reporting/CommResidTablePage.m \ reporting/CommResidTablePage.m \

View File

@ -1,4 +1,4 @@
% Copyright © 2013-2022 Dynare Team % Copyright © 2013-2023 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -52,7 +52,7 @@ counter = 0;
for i = 1:length(mlist) for i = 1:length(mlist)
f = [top_test_dir filesep mlist{i} ]; f = [top_test_dir filesep mlist{i} ];
if is_unitary_test_available(f) if is_unit_test_available(f)
[check, info] = mtest(f); [check, info] = mtest(f);
for j = 1:size(info, 1) for j = 1:size(info, 1)
counter = counter + 1; counter = counter + 1;
@ -65,9 +65,9 @@ end
cd(getenv('TOP_TEST_DIR')); cd(getenv('TOP_TEST_DIR'));
if isoctave if isoctave
fid = fopen('run_all_unitary_tests.o.trs', 'w+'); fid = fopen('run_all_unit_tests.o.trs', 'w+');
else else
fid = fopen('run_all_unitary_tests.m.trs', 'w+'); fid = fopen('run_all_unit_tests.m.trs', 'w+');
end end
if length(failedtests) > 0 if length(failedtests) > 0
fprintf(fid,':test-result: FAIL\n'); fprintf(fid,':test-result: FAIL\n');