Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Marco Ratto
dynare
Commits
c2e43c00
Commit
c2e43c00
authored
Sep 20, 2020
by
MichelJuillard
Browse files
fix histval_initval_file unit tests
parent
57c94a1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
matlab/histvalf_initvalf.m
View file @
c2e43c00
...
...
@@ -133,7 +133,7 @@ last_obs_ispresent = false;
first_obs
=
periods
(
1
);
if
isfield
(
options
,
'first_obs'
)
&&
~
isempty
(
options
.
first_obs
)
if
options
.
first_obs
<
1
error
(
'
first_obs must be a positive number'
)
error
(
[
caller
,
'_FILE:
first_obs must be a positive number'
]
)
elseif
options
.
first_obs
>
nobs0
error
(
sprintf
([
caller
,
'_FILE: first_obs = %d is larger than the number'
,
...
' of observations in the data file (%d)'
],
...
...
...
@@ -146,7 +146,7 @@ if isfield(options, 'first_obs') && ~isempty(options.first_obs)
error
(
sprintf
([
caller
,
'_FILE: first_obs = %d and'
,
...
' first_simulation_period = %d have values'
,
...
' inconsistent with a maximum lag of %d periods'
],
...
options
.
first_obs
,
options
_
.
first_simulation_period
,
...
options
.
first_obs
,
options
.
first_simulation_period
,
...
M
.
orig_maximum_lag
))
end
elseif
isfield
(
options
,
'firstsimulationperiod'
)
...
...
@@ -157,11 +157,11 @@ if isfield(options, 'first_obs') && ~isempty(options.first_obs)
error
(
sprintf
([
caller
,
'_FILE: first_obs = %d and'
,
...
' first_simulation_period = %s have values'
,
...
' inconsistent with a maximum lag of %d periods'
],
...
options
.
first_obs
,
options
_
.
firstsimulationperiod
,
...
options
.
first_obs
,
options
.
firstsimulationperiod
,
...
M
.
orig_maximum_lag
))
end
else
first_obs
=
periods
(
options
_
.
first_obs
);
first_obs
=
periods
(
options
.
first_obs
);
end
first_obs_ispresent
=
true
;
end
...
...
@@ -172,10 +172,10 @@ if isfield(options, 'firstobs') && ~isempty(options.firstobs)
-
M
.
orig_maximum_lag
first_obs
=
options
.
firstobs
;
else
error
(
sprintf
([
caller
,
'_F
ile
: first_obs = %s and'
,
...
error
(
sprintf
([
caller
,
'_F
ILE
: first_obs = %s and'
,
...
' first_simulation_period = %d have values'
,
...
' inconsistent with a maximum lag of %d periods'
],
...
options
.
firstobs
,
options
_
.
first_simulation_period
,
...
options
.
firstobs
,
options
.
first_simulation_period
,
...
M
.
orig_maximum_lag
))
end
elseif
isfield
(
options
,
'firstsimulationperiod'
)
...
...
@@ -220,8 +220,8 @@ end
if
isfield
(
options
,
'last_obs'
)
if
options
.
last_obs
>
nobs0
error
(
sprintf
([
caller
,
'_FILE: last_obs is larger than the number'
,
...
'observations in the dataset (%d)'
],
...
error
(
sprintf
([
caller
,
'_FILE: last_obs
= %d
is larger than the number'
,
...
'
of
observations in the dataset (%d)'
],
...
options
.
last_obs
,
nobs0
))
elseif
first_obs_ispresent
if
nobs
>
0
&&
(
periods
(
options
.
last_obs
)
~=
first_obs
+
nobs
-
1
)
...
...
@@ -229,13 +229,20 @@ if isfield(options, 'last_obs')
' inconsistent information. Use only two of these'
,
...
' options.'
])
else
last_obs
=
periods
(
options
.
last_obs
)
last_obs
=
periods
(
options
.
last_obs
);
end
else
last_obs
=
periods
(
options
.
last_obs
);
if
nobs
>
0
first_obs
=
last_obs
-
nobs
+
1
;
else
first_obs
=
periods
(
1
);
end
end
elseif
isfield
(
options
,
'lastobs'
)
if
options
.
lastobs
>
series
.
last
error
(
sprintf
([
caller
,
'_FILE: last_obs = %s is larger than the number'
,
...
'observations in the dataset (%s)'
],
...
'
of
observations in the dataset (%s)'
],
...
options
.
lastobs
,
series
.
last
))
elseif
first_obs_ispresent
if
nobs
>
0
&&
(
options
.
lastobs
~=
first_obs
+
nobs
-
1
)
...
...
@@ -243,13 +250,20 @@ elseif isfield(options, 'lastobs')
' inconsistent information. Use only two of these'
,
...
' options.'
])
else
last_obs
=
options
.
last_obs
last_obs
=
options
.
last_obs
;
end
else
last_obs
=
options
.
last_obs
;
if
nobs
>
0
first_obs
=
last_obs
-
nobs
+
1
;
else
first_obs
=
periods
(
1
);
end
end
elseif
nobs
>
0
last_obs
=
first_obs
+
nobs
-
1
last_obs
=
first_obs
+
nobs
-
1
;
else
last_obs
=
series
.
last
last_obs
=
series
.
last
;
end
series
=
series
(
first_obs
:
last_obs
);
...
...
tests/histval_initval_file/my_assert.m
View file @
c2e43c00
function failed_tests = my_assert(failed_tests, success, test_name)
if ~success
failed_tests = cat(1,
test_
failed, test_name);
failed_tests = cat(1, failed
_tests
, test_name);
end
\ No newline at end of file
tests/histval_initval_file_unit_tests.m
View file @
c2e43c00
...
...
@@ -16,6 +16,7 @@ M.endo_names = {'Variable_1','Variable_2','Variable_3'};
M.exo_nbr = 1;
M.exo_names = {'Variable_4'};
M.exo_det_nbr = 0;
M.orig_maximum_lag = 2;
caller = 'INITVAL';
...
...
@@ -88,9 +89,9 @@ try
ds1 = histvalf_initvalf(caller, M, options);
error('This test didn''t catch the error')
catch me
if strcmp(me.message,
[
'INITVAL_FILE: FIST_OBS, LAST_OBS and NOBS contain', ...
' inconsistent information. Use only two of these', ...
' options.'
]) == false
if
~
strcmp(me.message,
strcat(
'INITVAL_FILE: FIST_OBS, LAST_OBS and NOBS contain', ...
' inconsistent information. Use only two of these', ...
' options.'
))
failed_tests = cat(1, failed_tests, 'Wrong nobs error message' );
end
end
...
...
@@ -98,14 +99,13 @@ num_tests = num_tests + 1;
options = struct();
options.series = ds;
options.first_obs =
-1
;
options.first_obs =
0
;
try
ds1 = histvalf_initvalf(caller, M, options);
error('This test didn''t catch the error')
catch me
if strcmp(me.message, [caller, '_FILE: the first requested period is', ...
' before available data.']) == false
if ~strcmp(me.message, strcat(caller, '_FILE: first_obs must be a positive number'))
failed_tests = cat(1, failed_tests, ...
'Wrong first period error message');
end
...
...
@@ -120,8 +120,8 @@ try
ds1 = histvalf_initvalf(caller, M, options);
error('This test didn''t catch the error')
catch me
if strcmp(me.message,
[
caller, '_FILE:
the
last
requested period is
', ...
' after available data.']) == false
if
~
strcmp(me.message,
strcat(
caller, '_FILE: last
_obs = 11 is larger than the number
', ...
' of observations in the dataset (10)'))
failed_tests = cat(1, failed_tests, ...
'Wrong last period error message');
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment