dseries.m 18.4 KB
Newer Older
1
classdef dseries<handle % --*-- Unitary tests --*--
2

3
% Class for time series.
4

5
% Copyright (C) 2013-2019 Dynare Team
6
%
7
% This code is free software: you can redistribute it and/or modify
8 9 10 11
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
12
% Dynare dseries submodule is distributed in the hope that it will be useful,
13 14 15 16 17 18 19
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

Stéphane Adjemian's avatar
Stéphane Adjemian committed
20 21 22 23 24
properties
    data  = [];         % Array of data (a column per variable, a row per observation)
    name  = {};         % Names of the variables.
    tex   = {};         % TeX names of the variables.
    dates = dates();    % Dates associated to the observations.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
25
    ops   = {};         % History of operations on the variables.
26
    tags  = struct();   % User defined tags on the variables.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
27
end
28

Stéphane Adjemian's avatar
Stéphane Adjemian committed
29
methods
30 31
        function o = dseries(varargin)
        % Constructor for the dseries class
Stéphane Adjemian's avatar
Stéphane Adjemian committed
32 33
        %
        % INPUTS
34 35 36 37 38 39
        %
        % - If no input arguments, the constructore returns an empty dseries object.
        %
        % - If only one input argument is provided, the behaviour of the constructor depends on the type of the argument:
        %  + varargin{1}  [dates]   Constructor will return a dseries object without data. The dseries object can be populated later using dseries' methods.
        %  + varargin{1}  [char]    The name of a csv, m, mat or xlsx file containing data. A dseries object is created from these data.
Stéphane Adjemian's avatar
Stéphane Adjemian committed
40
        %  + varargin{1}  [double]  A T*N array of data. A dseries object is created from the array (T observations, N variables).
41 42 43 44 45 46 47
        %
        % - If only one two, three or four arguments are provided, we must have:
        %  + varargin{1}  [double]      A T*N array of data.
        %  + varargin{2}  [dates, char] A single element dates object or a string representing a date, the initial date of the database.
        %  + varargin{3}  [cell]        A N*1 cell of char or a N*q array of char, the names of  the variables.
        %  + varargin{4}  [cell]        A N*1 cell of char or a N*q array of char, the TeX names of  the variables.
        %
Stéphane Adjemian's avatar
Stéphane Adjemian committed
48
        % OUTPUTS
49
        % - o [dseries]
Stéphane Adjemian's avatar
Stéphane Adjemian committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63
        switch nargin
          case 0
            % Return empty object.
            return
          case 1
            if isdates(varargin{1})
                switch length(varargin{1})
                  case 0
                    error('dseries:WrongInputArguments', 'Input (identified as a dates object) must be non empty!');
                  case 1
                    % Create an empty dseries object with an initial date.
                    o.dates = varargin{1};
                  otherwise
                    error('dseries:WrongInputArguments', 'Input (identified as a dates object) must have a unique element!');
64
                end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
65 66
                return
            elseif ischar(varargin{1})
67
                [init, o.data, o.name, o.tex, o.ops, o.tags] = load_data(varargin{1});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
68
                o.dates = init:init+(nobs(o)-1);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
69
            elseif ~isoctave() && ~matlab_ver_less_than('8.2') && istable(varargin{1})
Stéphane Adjemian's avatar
Stéphane Adjemian committed
70 71 72 73 74
                % It is assumed that the dates are in the first column.
                o.name = varargin{1}.Properties.VariableNames(2:end);
                o.tex = name2tex(o.name);
                o.data = varargin{1}{:,2:end};
                o.dates = dates(varargin{1}{1,1}{1})+(0:size(varargin{1}, 1)-1);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
75
                o.ops = cell(length(o.name), 1);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
76 77 78 79 80
            elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
                o.data = varargin{1};
                o.name = default_name(vobs(o));
                o.tex = name2tex(o.name);
                o.dates = dates(1,1):dates(1,1)+(nobs(o)-1);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
81
                o.ops = cell(length(o.name), 1);
82 83
            elseif isstruct(varargin{1})
                o = struct2dseries(varargin{1});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
84 85 86 87 88 89
            end
          case  {2,3,4}
            if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
                % Instantiate dseries object with a data file and force the initial date to
                % be as given by the second input argument (initial period represented
                % with a dates object).
90
                [~, o.data, o.name, o.tex, o.ops, o.tags] = load_data(varargin{1});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
91 92 93 94 95 96 97
                o.dates = varargin{2}:varargin{2}+(nobs(o)-1);
                return
            end
            if isequal(nargin,2) && ischar(varargin{1}) && ischar(varargin{2}) && isdate(varargin{2})
                % Instantiate dseries object with a data file and force the initial date to
                % be as given by the second input argument (initial period represented with a
                % string).
98
                [~, o.data, o.name, o.tex, o.ops, o.tags] = load_data(varargin{1});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
99 100 101 102 103 104 105 106 107 108 109
                o.dates = dates(varargin{2}):dates(varargin{2})+(nobs(o)-1);
                return
            end
            a = varargin{1};
            b = varargin{2};
            if nargin<4
                d = {};
            else
                d = varargin{4};
                if ~iscell(d) && ~isempty(d)
                    d = cellstr(d);
110
                end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
111 112 113 114 115 116 117
            end
            if nargin<3
                c = {};
            else
                c = varargin{3};
                if ~iscell(c) && ~isempty(c)
                    c = cellstr(c);
118
                end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
            end
            % Get data, number of observations and number of variables.
            o.data = a;
            % Get the first date and set the frequency.
            if isempty(b)
                init = dates(1,1);
            elseif (isdates(b) && isequal(length(b),1))
                init = b;
            elseif ischar(b) && isdate(b)% Weekly, Monthly, Quaterly or Annual data (string).
                init = dates(b);
            elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data.
                init = dates([num2str(b) 'Y']);
            elseif isdates(b) % Range of dates
                init = b(1);
                if nobs(o)>1 && ~isequal(b.ndat(),nobs(o))
                    error('dseries:WrongInputArguments', ['If second input is a range, its number ' ...
                                        'of elements must match\nthe number of rows in the ' ...
                                        'first input, unless the first input\nhas only one row.']);
                elseif isequal(nobs(o), 1)
                    o.data = repmat(o.data,b.ndat(),1);
139
                end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
140 141 142 143 144 145 146 147 148 149 150 151 152
                o.dates = b;
            elseif (isnumeric(b) && isint(b)) % Range of yearly dates.
                error('dseries:WrongInputArguments', ['Not implemented! If you need to define ' ...
                                    'a range of years, you have to pass a dates object as the ' ...
                                    'second input argument']);
            else
                error('dseries:WrongInputArguments', 'Wrong calling sequence! Please check the manual.');
            end
            % Get the names of the variables.
            if ~isempty(c)
                if vobs(o)==length(c)
                    for i=1:vobs(o)
                        o.name = vertcat(o.name, c(i));
153 154
                    end
                else
Stéphane Adjemian's avatar
Stéphane Adjemian committed
155
                    error('dseries:WrongInputArguments', 'The number of declared names does not match the number of variables!')
156
                end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
157 158 159
            else
                o.name = default_name(vobs(o));
            end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
160
            o.ops = cell(length(o.name), 1);
161
            o.tags = struct();
Stéphane Adjemian's avatar
Stéphane Adjemian committed
162 163 164 165
            if ~isempty(d)
                if vobs(o)==length(d)
                    for i=1:vobs(o)
                        o.tex = vertcat(o.tex, d(i));
166 167
                    end
                else
Stéphane Adjemian's avatar
Stéphane Adjemian committed
168
                    error('dseries:WrongInputArguments', 'The number of declared tex names does not match the number of variables!')
169
                end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
170 171
            else
                o.tex = name2tex(o.name);
172
            end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
173 174 175 176 177 178
          otherwise
            error('dseries:WrongInputArguments', 'Wrong calling sequence! Please check the manual.')
        end
        if isempty(o.dates)
            o.dates = init:init+(nobs(o)-1);
        end
179
        end % dseries
Stéphane Adjemian's avatar
Stéphane Adjemian committed
180
end % methods
181
end % classdef
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215

%@test:1
%$ % Test if we can instantiate an empty dseries object.
%$ try
%$     ts = dseries();
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$
%$ T = all(t);
%@eof:1

%@test:2
%$ t = zeros(4,1);
%$
%$ try
%$     aa = dates('1938M11');
%$     ts = dseries(aa);
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,12);
%$     t(3) = dassert(ts.init.freq,12);
%$     t(4) = dassert(ts.init.time,[1938, 11]);
%$ end
%$
%$ T = all(t);
%@eof:2

%@test:3
Stéphane Adjemian's avatar
Stéphane Adjemian committed
216
%$ t = zeros(8, 1);
217 218
%$
%$ try
Sébastien Villemot's avatar
Onx  
Sébastien Villemot committed
219 220
%$     dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
%$     ts = dseries([ dseries_src_root filesep 'tests' filesep 'data' filesep 'dynseries_test_data.m');
221 222 223 224 225 226 227 228 229 230 231
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1994, 3]);
%$     t(5) = dassert(ts.vobs,2);
%$     t(6) = dassert(ts.nobs,100);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
232 233
%$     t(7) = dassert(length(ts.ops), 2);
%$     t(8) = isempty(ts.ops{1}) && isempty(ts.ops{2});
234 235 236 237 238 239
%$ end
%$
%$ T = all(t);
%@eof:3

%@test:4
Stéphane Adjemian's avatar
Stéphane Adjemian committed
240
%$ t = zeros(8, 1);
241 242
%$
%$ try
243
%$     [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data.mat','dynseries_test_data.mat');
244 245 246
%$     if ~status
%$         error()
%$     end
247
%$     ts = dseries('dynseries_test_data.mat');
248
%$     delete('dynseries_test_data.mat');
249 250 251 252 253 254 255 256 257 258 259
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1994, 3]);
%$     t(5) = dassert(ts.vobs,2);
%$     t(6) = dassert(ts.nobs,100);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
260 261
%$     t(7) = dassert(length(ts.ops), 2);
%$     t(8) = isempty(ts.ops{1}) && isempty(ts.ops{2});
262 263 264 265 266 267
%$ end
%$
%$ T = all(t);
%@eof:4

%@test:5
Stéphane Adjemian's avatar
Stéphane Adjemian committed
268
%$ t = zeros(10, 1);
269 270
%$
%$ try
271
%$     [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data.csv','dynseries_test_data.csv');
272 273 274
%$     if ~status
%$         error()
%$     end
275
%$     ts = dseries('dynseries_test_data.csv');
276
%$     delete('dynseries_test_data.csv');
277 278 279 280 281 282 283 284 285 286 287 288 289
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1990, 1]);
%$     t(5) = dassert(ts.vobs,4);
%$     t(6) = dassert(ts.nobs,4);
%$     t(7) = dassert(ts.name,{'azert';'yuiop';'qsdfg';'jklm'});
%$     t(8) = dassert(ts.tex,{'azert';'yuiop';'qsdfg';'jklm'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
290 291
%$     t(9) = dassert(length(ts.ops), 4);
%$     t(10) = isempty(ts.ops{1}) && isempty(ts.ops{2}) && isempty(ts.ops{3}) && isempty(ts.ops{4}) ;
292 293 294 295 296 297
%$ end
%$
%$ T = all(t);
%@eof:5

%@test:6
Stéphane Adjemian's avatar
Stéphane Adjemian committed
298
%$ t = zeros(10, 1);
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
%$
%$ try
%$     ts = dseries(transpose(1:5),[]);
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,1);
%$     t(3) = dassert(ts.init.freq,1);
%$     t(4) = dassert(ts.init.time,[1, 1]);
%$     t(5) = dassert(ts.vobs,1);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'Variable_1'});
%$     t(8) = dassert(ts.tex,{'Variable\\_1'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
315 316
%$     t(9) = dassert(length(ts.ops), 1);
%$     t(10) = isempty(ts.ops{1});
317 318 319 320 321 322
%$ end
%$
%$ T = all(t);
%@eof:6

%@test:7
Stéphane Adjemian's avatar
Stéphane Adjemian committed
323
%$ t = zeros(10, 1);
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
%$
%$ try
%$     ts = dseries(transpose(1:5),'1950Q1');
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1950, 1]);
%$     t(5) = dassert(ts.vobs,1);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'Variable_1'});
%$     t(8) = dassert(ts.tex,{'Variable\\_1'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
340 341
%$     t(9) = dassert(length(ts.ops), 1);
%$     t(10) = isempty(ts.ops{1});
342 343 344 345 346 347
%$ end
%$
%$ T = all(t);
%@eof:7

%@test:8
Stéphane Adjemian's avatar
Stéphane Adjemian committed
348
%$ t = zeros(10, 1);
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
%$
%$ try
%$     ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1950, 1]);
%$     t(5) = dassert(ts.vobs,2);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'Output'; 'Consumption'});
%$     t(8) = dassert(ts.tex,{'Y_t'; 'C_t'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
365 366
%$     t(9) = dassert(length(ts.ops), 2);
%$     t(10) = isempty(ts.ops{1}) && isempty(ts.ops{2});
367 368 369 370 371 372 373
%$ end
%$
%$ T = all(t);
%@eof:8

%@test:9
%$ try
374
%$     if isoctave()
375
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-1.xlsx','dynseries_test_data-1.xlsx');
376
%$     else
377
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-1.xls','dynseries_test_data-1.xls');
378
%$     end
379 380 381
%$     if ~status
%$         error()
%$     end
382 383 384 385 386 387 388
%$     if isoctave()
%$         ts = dseries('dynseries_test_data-1.xlsx');
%$         delete('dynseries_test_data-1.xlsx');
%$     else
%$         ts = dseries('dynseries_test_data-1.xls');
%$         delete('dynseries_test_data-1.xls');
%$     end
389 390 391 392 393 394 395 396 397 398 399 400 401
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1990, 1]);
%$     t(5) = dassert(ts.vobs,3);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'GDP';'Consumption';'CPI'});
%$     t(8) = dassert(ts.tex,{'GDP';'Consumption';'CPI'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
402 403
%$     t(9) = dassert(length(ts.ops), 3);
%$     t(10) = isempty(ts.ops{1}) && isempty(ts.ops{2}) && isempty(ts.ops{3});
404 405 406 407 408 409 410
%$ end
%$
%$ T = all(t);
%@eof:9

%@test:10
%$ try
411
%$     if isoctave()
412
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-2.xlsx','dynseries_test_data-2.xlsx');
413
%$     else
414
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-2.xls','dynseries_test_data-2.xls');
415
%$     end
416 417 418
%$     if ~status
%$         error()
%$     end
419 420 421 422 423 424 425
%$     if isoctave()
%$         ts = dseries('dynseries_test_data-2.xlsx');
%$         delete('dynseries_test_data-2.xlsx');
%$     else
%$         ts = dseries('dynseries_test_data-2.xls');
%$         delete('dynseries_test_data-2.xls');
%$     end
426 427 428 429 430 431 432 433 434 435 436 437 438
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1990, 1]);
%$     t(5) = dassert(ts.vobs,3);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
%$     t(8) = dassert(ts.tex,{'Variable\\_1';'Variable\\_2';'Variable\\_3'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
439 440
%$     t(9) = dassert(length(ts.ops), 3);
%$     t(10) = isempty(ts.ops{1}) && isempty(ts.ops{2}) && isempty(ts.ops{3});
441 442 443 444 445 446 447
%$ end
%$
%$ T = all(t);
%@eof:10

%@test:11
%$ try
448
%$     if isoctave()
449
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-3.xlsx','dynseries_test_data-3.xlsx');
450
%$     else
451
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-3.xls','dynseries_test_data-3.xls');
452
%$     end
453 454 455
%$     if ~status
%$         error()
%$     end
456 457 458 459 460 461 462
%$     if isoctave()
%$         ts = dseries('dynseries_test_data-3.xlsx');
%$         delete('dynseries_test_data-3.xlsx');
%$     else
%$         ts = dseries('dynseries_test_data-3.xls');
%$         delete('dynseries_test_data-3.xls');
%$     end
463 464 465 466 467 468 469 470 471 472 473 474 475
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dassert(ts.freq,1);
%$     t(3) = dassert(ts.init.freq,1);
%$     t(4) = dassert(ts.init.time,[1, 1]);
%$     t(5) = dassert(ts.vobs,3);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
%$     t(8) = dassert(ts.tex,{'Variable\\_1';'Variable\\_2';'Variable\\_3'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
476 477
%$     t(9) = dassert(length(ts.ops), 3);
%$     t(10) = isempty(ts.ops{1}) && isempty(ts.ops{2}) && isempty(ts.ops{3});
478 479 480 481 482 483 484
%$ end
%$
%$ T = all(t);
%@eof:11

%@test:12
%$ try
485
%$     if isoctave()
486
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-4.xlsx','dynseries_test_data-4.xlsx');
487
%$     else
488
%$         [strfile, status] = urlwrite('https://www.dynare.org/Datasets/dseries/dynseries_test_data-4.xls','dynseries_test_data-4.xls');
489
%$     end
490 491 492
%$     if ~status
%$         error()
%$     end
493 494 495 496 497 498 499
%$     if isoctave()
%$         ts = dseries('dynseries_test_data-4.xlsx');
%$         delete('dynseries_test_data-4.xlsx');
%$     else
%$         ts = dseries('dynseries_test_data-4.xls');
%$         delete('dynseries_test_data-4.xls');
%$     end
500 501 502 503 504 505 506 507 508 509 510 511 512
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
%$     t(2) = dassert(ts.freq,1);
%$     t(3) = dassert(ts.init.freq,1);
%$     t(4) = dassert(ts.init.time,[1, 1]);
%$     t(5) = dassert(ts.vobs,3);
%$     t(6) = dassert(ts.nobs,5);
%$     t(7) = dassert(ts.name,{'GDP';'Consumption';'CPI'});
%$     t(8) = dassert(ts.tex,{'GDP';'Consumption';'CPI'});
Stéphane Adjemian's avatar
Stéphane Adjemian committed
513 514
%$     t(9) = dassert(length(ts.ops), 3);
%$     t(10) = isempty(ts.ops{1}) && isempty(ts.ops{2}) && isempty(ts.ops{3});
515 516 517 518 519 520
%$ end
%$
%$ T = all(t);
%@eof:12

%@test:13
Stéphane Adjemian's avatar
Stéphane Adjemian committed
521
%$ t = zeros(8, 1);
522 523 524 525 526 527 528 529 530 531 532 533 534 535
%$
%$ try
%$     ts = dseries(transpose(1:4),dates('1990Q1'):dates('1990Q4'));
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1990, 1]);
%$     t(5) = dassert(ts.vobs,1);
%$     t(6) = dassert(ts.nobs,4);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
536 537
%$     t(7) = dassert(length(ts.ops), 1);
%$     t(8) = isempty(ts.ops{1});
538 539 540 541 542 543
%$ end
%$
%$ T = all(t);
%@eof:13

%@test:14
Stéphane Adjemian's avatar
Stéphane Adjemian committed
544
%$ t = zeros(9, 1);
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
%$
%$ try
%$     ts = dseries([1, 2],dates('1990Q1'):dates('1990Q4'));
%$     t(1) = 1;
%$ catch
%$     t = 0;
%$ end
%$
%$ if length(t)>1
%$     t(2) = dassert(ts.freq,4);
%$     t(3) = dassert(ts.init.freq,4);
%$     t(4) = dassert(ts.init.time,[1990, 1]);
%$     t(5) = dassert(ts.vobs,2);
%$     t(6) = dassert(ts.nobs,4);
%$     t(7) = dassert(ts.data, [ones(4,1), 2*ones(4,1)]);
Stéphane Adjemian's avatar
Stéphane Adjemian committed
560 561
%$     t(8) = dassert(length(ts.ops), 2);
%$     t(9) = isempty(ts.ops{1}) && isempty(ts.ops{2});
562 563 564 565 566 567 568
%$ end
%$
%$ T = all(t);
%@eof:14

%@test:15
%$ try
Stéphane Adjemian's avatar
Stéphane Adjemian committed
569
%$     evalc('dseries([1; 2],dates(''1990Q1''):dates(''1990Q4''));');
570 571 572 573 574 575 576
%$     t = 0;
%$ catch
%$     t = 1;
%$ end
%$
%$ T = all(t);
%@eof:15