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

Cosmetic change (unit tests).

parent 5536706d
......@@ -271,425 +271,427 @@ if ~isempty(S)
B = subsref(B, S);
end
return
%@test:1
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
%$ a = ts1(ts1.dates(2:9));
%$
%$ % Expected results.
%$ e.data = [transpose(2:9),2*transpose(2:9)];
%$ e.nobs = 8;
%$ e.vobs = 2;
%$ e.name = {'A1';'A2'};
%$ e.freq = 1;
%$ e.init = dates(1,2);
%$
%$ % Check the results.
%$ t(1) = dassert(a.data,e.data);
%$ t(2) = dassert(a.nobs,e.nobs);
%$ t(3) = dassert(a.vobs,e.vobs);
%$ t(4) = dassert(a.freq,e.freq);
%$ t(5) = dassert(a.init,e.init);
%$ T = all(t);
% Define a data set.
A = [transpose(1:10),2*transpose(1:10)];
% Define names
A_name = {'A1';'A2'};
% Instantiate a time series object.
ts1 = dseries(A,[],A_name,[]);
% Call the tested method.
a = ts1(ts1.dates(2:9));
% Expected results.
e.data = [transpose(2:9),2*transpose(2:9)];
e.nobs = 8;
e.vobs = 2;
e.name = {'A1';'A2'};
e.freq = 1;
e.init = dates(1,2);
% Check the results.
t(1) = dassert(a.data,e.data);
t(2) = dassert(a.nobs,e.nobs);
t(3) = dassert(a.vobs,e.vobs);
t(4) = dassert(a.freq,e.freq);
t(5) = dassert(a.init,e.init);
T = all(t);
%@eof:1
%@test:2
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
%$ a = ts1.A1;
%$
%$ % Expected results.
%$ e.data = transpose(1:10);
%$ e.nobs = 10;
%$ e.vobs = 1;
%$ e.name = {'A1'};
%$ e.freq = 1;
%$ e.init = dates(1,1);
%$
%$ % Check the results.
%$ t(1) = dassert(a.data,e.data);
%$ t(2) = dassert(a.init,e.init);
%$ t(3) = dassert(a.nobs,e.nobs);
%$ t(4) = dassert(a.vobs,e.vobs);
%$ t(5) = dassert(a.freq,e.freq);
%$ T = all(t);
% Define a data set.
A = [transpose(1:10),2*transpose(1:10)];
% Define names
A_name = {'A1';'A2'};
% Instantiate a time series object.
ts1 = dseries(A,[],A_name,[]);
% Call the tested method.
a = ts1.A1;
% Expected results.
e.data = transpose(1:10);
e.nobs = 10;
e.vobs = 1;
e.name = {'A1'};
e.freq = 1;
e.init = dates(1,1);
% Check the results.
t(1) = dassert(a.data,e.data);
t(2) = dassert(a.init,e.init);
t(3) = dassert(a.nobs,e.nobs);
t(4) = dassert(a.vobs,e.vobs);
t(5) = dassert(a.freq,e.freq);
T = all(t);
%@eof:2
%@test:3
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
%$ a = ts1.log;
%$
%$ % Expected results.
%$ e.data = log(A);
%$ e.nobs = 10;
%$ e.vobs = 2;
%$ e.name = {'A1';'A2'};
%$ e.freq = 1;
%$ e.init = dates(1,1);
%$
%$ % Check the results.
%$ t(1) = dassert(a.data,e.data);
%$ t(2) = dassert(a.nobs,e.nobs);
%$ t(3) = dassert(a.vobs,e.vobs);
%$ t(4) = dassert(a.freq,e.freq);
%$ t(5) = dassert(a.init,e.init);
%$ T = all(t);
% Define a data set.
A = [transpose(1:10),2*transpose(1:10)];
% Define names
A_name = {'A1';'A2'};
% Instantiate a time series object.
ts1 = dseries(A,[],A_name,[]);
% Call the tested method.
a = ts1.log;
% Expected results.
e.data = log(A);
e.nobs = 10;
e.vobs = 2;
e.name = {'A1';'A2'};
e.freq = 1;
e.init = dates(1,1);
% Check the results.
t(1) = dassert(a.data,e.data);
t(2) = dassert(a.nobs,e.nobs);
t(3) = dassert(a.vobs,e.vobs);
t(4) = dassert(a.freq,e.freq);
t(5) = dassert(a.init,e.init);
T = all(t);
%@eof:3
%@test:4
%$ % Create an empty dseries object.
%$ dataset = dseries();
%$
%$ t = zeros(5,1);
%$
%$ try
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data.csv','dynseries_test_data.csv');
%$ if ~status
%$ error()
%$ end
%$ A = dseries('dynseries_test_data.csv');
%$ delete('dynseries_test_data.csv');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ % Check the results.
%$ if length(t)>1
%$ t(2) = dassert(A.nobs,4);
%$ t(3) = dassert(A.vobs,4);
%$ t(4) = dassert(A.freq,4);
%$ t(5) = dassert(A.init,dates('1990Q1'));
%$ end
%$ T = all(t);
% Create an empty dseries object.
dataset = dseries();
t = zeros(5,1);
try
[strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data.csv','dynseries_test_data.csv');
if ~status
error()
end
A = dseries('dynseries_test_data.csv');
delete('dynseries_test_data.csv');
t(1) = 1;
catch
t = 0;
end
% Check the results.
if length(t)>1
t(2) = dassert(A.nobs,4);
t(3) = dassert(A.vobs,4);
t(4) = dassert(A.freq,4);
t(5) = dassert(A.init,dates('1990Q1'));
end
T = all(t);
%@eof:4
%@test:5
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10),3*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2';'B1'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
%$ a = ts1{'A1','B1'};
%$
%$ % Expected results.
%$ e.data = A(:,[1,3]);
%$ e.nobs = 10;
%$ e.vobs = 2;
%$ e.name = {'A1';'B1'};
%$ e.freq = 1;
%$ e.init = dates(1,1);
%$
%$ t(1) = dassert(e.data,a.data);
%$ t(2) = dassert(e.nobs,a.nobs);
%$ t(3) = dassert(e.vobs,a.vobs);
%$ t(4) = dassert(e.name,a.name);
%$ t(5) = dassert(e.init,a.init);
%$ T = all(t);
% Define a data set.
A = [transpose(1:10),2*transpose(1:10),3*transpose(1:10)];
% Define names
A_name = {'A1';'A2';'B1'};
% Instantiate a time series object.
ts1 = dseries(A,[],A_name,[]);
% Call the tested method.
a = ts1{'A1','B1'};
% Expected results.
e.data = A(:,[1,3]);
e.nobs = 10;
e.vobs = 2;
e.name = {'A1';'B1'};
e.freq = 1;
e.init = dates(1,1);
t(1) = dassert(e.data,a.data);
t(2) = dassert(e.nobs,a.nobs);
t(3) = dassert(e.vobs,a.vobs);
t(4) = dassert(e.name,a.name);
t(5) = dassert(e.init,a.init);
T = all(t);
%@eof:5
%@test:6
%$ % Define a data set.
%$ A = rand(10,24);
%$
%$ % Define names
%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
%$ try
%$ a = ts1{'[GDP_[0-9]]'};
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$ try
%$ b = ts1{'[[A-Z]*_1]'};
%$ t(2) = 1;
%$ catch
%$ t(2) = 0;
%$ end
%$ try
%$ warning off all
%$ c = ts1{'[A-Z]_1'};
%$ warning on all
%$ t(3) = 0;
%$ catch
%$ t(3) = 1;
%$ end
%$
%$ % Expected results.
%$ e1.data = A(:,1:9);
%$ e1.nobs = 10;
%$ e1.vobs = 9;
%$ e1.name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'};
%$ e1.freq = 1;
%$ e1.init = dates(1,1);
%$ e2.data = A(:,[1 13]);
%$ e2.nobs = 10;
%$ e2.vobs = 2;
%$ e2.name = {'GDP_1';'HICP_1'};
%$ e2.freq = 1;
%$ e2.init = dates(1,1);
%$
%$ % Check results.
%$ t(4) = dassert(e1.data,a.data);
%$ t(5) = dassert(e1.nobs,a.nobs);
%$ t(6) = dassert(e1.vobs,a.vobs);
%$ t(7) = dassert(e1.name,a.name);
%$ t(8) = dassert(e1.init,a.init);
%$ t(9) = dassert(e2.data,b.data);
%$ t(10) = dassert(e2.nobs,b.nobs);
%$ t(11) = dassert(e2.vobs,b.vobs);
%$ t(12) = dassert(e2.name,b.name);
%$ t(13) = dassert(e2.init,b.init);
%$ T = all(t);
% Define a data set.
A = rand(10,24);
% Define names
A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
% Instantiate a time series object.
ts1 = dseries(A,[],A_name,[]);
% Call the tested method.
try
a = ts1{'[GDP_[0-9]]'};
t(1) = 1;
catch
t(1) = 0;
end
try
b = ts1{'[[A-Z]*_1]'};
t(2) = 1;
catch
t(2) = 0;
end
try
warning off all
c = ts1{'[A-Z]_1'};
warning on all
t(3) = 0;
catch
t(3) = 1;
end
% Expected results.
e1.data = A(:,1:9);
e1.nobs = 10;
e1.vobs = 9;
e1.name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'};
e1.freq = 1;
e1.init = dates(1,1);
e2.data = A(:,[1 13]);
e2.nobs = 10;
e2.vobs = 2;
e2.name = {'GDP_1';'HICP_1'};
e2.freq = 1;
e2.init = dates(1,1);
% Check results.
t(4) = dassert(e1.data,a.data);
t(5) = dassert(e1.nobs,a.nobs);
t(6) = dassert(e1.vobs,a.vobs);
t(7) = dassert(e1.name,a.name);
t(8) = dassert(e1.init,a.init);
t(9) = dassert(e2.data,b.data);
t(10) = dassert(e2.nobs,b.nobs);
t(11) = dassert(e2.vobs,b.vobs);
t(12) = dassert(e2.name,b.name);
t(13) = dassert(e2.init,b.init);
T = all(t);
%@eof:6
%@test:7
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts1.save('ts1');
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ delete('ts1.mat');
%$
%$ T = all(t);
% Define a data set.
A = [transpose(1:10),2*transpose(1:10)];
% Define names
A_name = {'A1';'A2'};
% Instantiate a time series object.
try
ts1 = dseries(A,[],A_name,[]);
ts1.save('ts1');
t = 1;
catch
t = 0;
end
delete('ts1.mat');
T = all(t);
%@eof:7
%@test:8
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts1.save('test_generated_data_file','m');
%$ delete('test_generated_data_file.m');
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ T = all(t);
% Define a data set.
A = [transpose(1:10),2*transpose(1:10)];
% Define names
A_name = {'A1';'A2'};
% Instantiate a time series object.
try
ts1 = dseries(A,[],A_name,[]);
ts1.save('test_generated_data_file','m');
delete('test_generated_data_file.m');
t = 1;
catch
t = 0;
end
T = all(t);
%@eof:8
%@test:9
%$ % Define a data set.
%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
%$
%$ % Define names
%$ A_name = {'A1';'A2';'B1'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
%$
%$ % Define the range of a subsample.
%$ range = dates('1971Q2'):dates('1971Q4');
%$ % Call the tested method.
%$ a = ts1(range);
%$
%$ % Expected results.
%$ e.data = A(2:4,:);
%$ e.nobs = 3;
%$ e.vobs = 3;
%$ e.name = {'A1';'A2';'B1'};
%$ e.freq = 4;
%$ e.init = dates('1971Q2');
%$
%$ t(1) = dassert(e.data,a.data);
%$ t(2) = dassert(e.nobs,a.nobs);
%$ t(3) = dassert(e.vobs,a.vobs);
%$ t(4) = dassert(e.name,a.name);
%$ t(5) = dassert(e.init,a.init);
%$ T = all(t);
% Define a data set.
A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
% Define names
A_name = {'A1';'A2';'B1'};
% Instantiate a time series object.
ts1 = dseries(A,'1971Q1',A_name,[]);
% Define the range of a subsample.
range = dates('1971Q2'):dates('1971Q4');
% Call the tested method.
a = ts1(range);
% Expected results.
e.data = A(2:4,:);
e.nobs = 3;
e.vobs = 3;
e.name = {'A1';'A2';'B1'};
e.freq = 4;
e.init = dates('1971Q2');
t(1) = dassert(e.data,a.data);
t(2) = dassert(e.nobs,a.nobs);
t(3) = dassert(e.vobs,a.vobs);
t(4) = dassert(e.name,a.name);
t(5) = dassert(e.init,a.init);
T = all(t);
%@eof:9
%@test:10
%$ % Define a data set.
%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
%$
%$ % Define names
%$ A_name = {'A1';'A2';'B1'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,'1971Q1',A_name,[]);
%$
%$ % Test the size method.
%$ B = ts1.size();
%$ C = ts1.size(1);
%$ D = ts1.size(2);
%$ E = ts1.size;
%$
%$ t(1) = dassert(B,[60, 3]);
%$ t(2) = dassert(E,[60, 3]);
%$ t(3) = dassert(C,60);
%$ t(4) = dassert(D,3);
%$ T = all(t);
% Define a data set.
A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
% Define names
A_name = {'A1';'A2';'B1'};
% Instantiate a time series object.
ts1 = dseries(A,'1971Q1',A_name,[]);
% Test the size method.
B = ts1.size();
C = ts1.size(1);