Verified Commit 31f81d5f authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Added unit tests.

parent 638d114e
function ts = dseries2M(ds, method)
function ts = dseries2M(ds, method) % --*-- Unitary tests --*--
% INPUTS
% - ds [dseries] daily frequency object with n elements.
......@@ -11,7 +11,7 @@ function ts = dseries2M(ds, method)
% OUTPUTS
% - ts [dseries] monthly frequency object with m<n elements.
% Copyright © 2020 Dynare Team
% Copyright © 2020-2021 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
......@@ -71,9 +71,72 @@ end
ts = dseries(tdata, dM, ds.name, ds.tex);
return
%@test:1
try
ts = dseries(randn(366, 1), '2020-01-01');
ds = dseries2M(ts, 'arithmetic-average');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==12;
t(3) = ds.nobs==12;
end
T = all(t);
%@eof:1
%@test:2
try
ts = dseries(1.02-rand(366, 1)*0.05, '2020-01-01');
ds = dseries2M(ts, 'geometric-average');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==12;
t(3) = ds.nobs==12;
end
T = all(t);
%@eof:2
%@test:3
try
ts = dseries(randn(366, 1), '2020-01-01');
ds = dseries2M(ts, 'sum');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==12;
t(3) = ds.nobs==12;
end
T = all(t);
%@eof:3
%@test:4
try
ts = dseries(randn(366, 1), '2020-01-01');
ds = dseries2M(ts, 'end-of-period');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==12;
t(3) = ds.nobs==12;
end
T = all(t);
%@eof:4
function ts = dseries2Q(ds, method)
function ts = dseries2Q(ds, method) % --*-- Unitary tests --*--
% INPUTS
% - ds [dseries] daily or monthly frequency object with n elements.
......@@ -11,7 +11,7 @@ function ts = dseries2Q(ds, method)
% OUTPUTS
% - ts [dseries] quaterly frequency object with m<n elements.
% Copyright © 2020 Dynare Team
% Copyright © 2020-2021 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
......@@ -86,4 +86,142 @@ switch method
error('Unknow method.')
end
ts = dseries(tdata, dQ, ds.name, ds.tex);
\ No newline at end of file
ts = dseries(tdata, dQ, ds.name, ds.tex);
return
%@test:1
try
ts = dseries(randn(366, 1), '2020-01-01');
ds = dseries2Q(ts, 'arithmetic-average');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:1
%@test:2
try
ts = dseries(1.02-rand(366, 1)*0.05, '2020-01-01');
ds = dseries2Q(ts, 'geometric-average');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:2
%@test:3
try
ts = dseries(randn(366, 1), '2020-01-01');
ds = dseries2Q(ts, 'sum');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:3
%@test:4
try
ts = dseries(randn(366, 1), '2020-01-01');
ds = dseries2Q(ts, 'end-of-period');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:4
%@test:5
try
ts = dseries(randn(12, 1), '2020M1');
ds = dseries2Q(ts, 'arithmetic-average');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:5
%@test:6
try
ts = dseries(1.02-rand(12, 1)*0.5, '2020M1');
ds = dseries2Q(ts, 'geometric-average');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:6
%@test:7
try
ts = dseries(randn(12, 1), '2020M1');
ds = dseries2Q(ts, 'sum');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:7
%@test:8
try
ts = dseries(randn(12, 1), '2020M1');
ds = dseries2Q(ts, 'end-of-period');
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = ds.freq==4;
t(3) = ds.nobs==4;
end
T = all(t);
%@eof:8
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment