cumsum.m 2.18 KB
Newer Older
1
function o = cumsum(varargin) % --*-- Unitary tests --*--
2 3 4

% Overloads matlab's cumsum function for dseries objects.
%
5
% INPUTS
6 7 8
% - o     dseries object [mandatory].
% - d     dates object [optional]
% - v     dseries object with one observation [optional]
9
%
10
% OUTPUTS
11
% - o     dseries object.
12

13
% Copyright (C) 2013-2017 Dynare Team
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% 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.
%
% Dynare is distributed in the hope that it will be useful,
% 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/>.

30
o = copy(varargin{1});
31

32 33
if nargin<2
    o.cumsum_();
34
else
35 36 37 38 39
    if isoctave()
        o = cumsum_(o, varargin{2:end});
    else
        o.cumsum_(varargin{2:end});
    end
40 41 42 43 44 45 46 47 48 49 50 51 52
end

%@test:1
%$ % Define a data set.
%$ A = ones(10,1);
%$
%$ % Define names
%$ A_name = {'A1'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
53 54 55 56 57 58
%$ try
%$   ts3 = cumsum(ts1);
%$   t(1) = 1;
%$ catch
%$   t(1) = 0;
%$ end
59 60 61 62 63
%$
%$ % Expected results.
%$ ts2 = dseries(transpose(1:10), [], A_name, []);
%$
%$ % Check the results.
64 65 66 67
%$ if t(1)
%$   t(2) = dassert(ts3.data, ts2.data);
%$   t(3) = dassert(ts1.data, A);
%$ end
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
%$ T = all(t);
%@eof:1

%@test:2
%$ % Define a data set.
%$ A = ones(10,1);
%$
%$ % Define names
%$ A_name = {'A1'};
%$
%$ % Instantiate a time series object.
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = dseries(pi, [], A_name, []);
%$
%$ % Call the tested method.
83 84 85 86 87 88
%$ try
%$   ts3 = ts1.cumsum(dates('3Y'),ts2);
%$   t(1) = 1;
%$ catch
%$   t(1) = 0;
%$ end
89 90 91 92 93
%$
%$ % Expected results.
%$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []);
%$
%$ % Check the results.
94 95 96 97
%$ if t(1)
%$   t(2) = dassert(ts3.data, ts4.data);
%$   t(3) = dassert(ts1.data, A);
%$ end
98
%$ T = all(t);
99
%@eof:2