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