1function o = cumsum(varargin) % --*-- Unitary tests --*--
2
3% Overloads matlab's cumsum function for dseries objects.
4%
5% INPUTS
6% - o     dseries object [mandatory].
7% - d     dates object [optional]
8% - v     dseries object with one observation [optional]
9%
10% OUTPUTS
11% - o     dseries object.
12
13% Copyright (C) 2013-2017 Dynare Team
14%
15% This file is part of Dynare.
16%
17% Dynare is free software: you can redistribute it and/or modify
18% it under the terms of the GNU General Public License as published by
19% the Free Software Foundation, either version 3 of the License, or
20% (at your option) any later version.
21%
22% Dynare is distributed in the hope that it will be useful,
23% but WITHOUT ANY WARRANTY; without even the implied warranty of
24% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25% GNU General Public License for more details.
26%
27% You should have received a copy of the GNU General Public License
28% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
29
30o = copy(varargin{1});
31
32if nargin<2
33    o.cumsum_();
34else
35    if isoctave()
36        o = cumsum_(o, varargin{2:end});
37    else
38        o.cumsum_(varargin{2:end});
39    end
40end
41
42%@test:1
43%$ % Define a data set.
44%$ A = ones(10,1);
45%$
46%$ % Define names
47%$ A_name = {'A1'};
48%$
49%$ % Instantiate a time series object.
50%$ ts1 = dseries(A,[],A_name,[]);
51%$
52%$ % Call the tested method.
53%$ try
54%$   ts3 = cumsum(ts1);
55%$   t(1) = 1;
56%$ catch
57%$   t(1) = 0;
58%$ end
59%$
60%$ % Expected results.
61%$ ts2 = dseries(transpose(1:10), [], A_name, []);
62%$
63%$ % Check the results.
64%$ if t(1)
65%$   t(2) = dassert(ts3.data, ts2.data);
66%$   t(3) = dassert(ts1.data, A);
67%$ end
68%$ T = all(t);
69%@eof:1
70
71%@test:2
72%$ % Define a data set.
73%$ A = ones(10,1);
74%$
75%$ % Define names
76%$ A_name = {'A1'};
77%$
78%$ % Instantiate a time series object.
79%$ ts1 = dseries(A,[],A_name,[]);
80%$ ts2 = dseries(pi, [], A_name, []);
81%$
82%$ % Call the tested method.
83%$ try
84%$   ts3 = ts1.cumsum(dates('3Y'),ts2);
85%$   t(1) = 1;
86%$ catch
87%$   t(1) = 0;
88%$ end
89%$
90%$ % Expected results.
91%$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []);
92%$
93%$ % Check the results.
94%$ if t(1)
95%$   t(2) = dassert(ts3.data, ts4.data);
96%$   t(3) = dassert(ts1.data, A);
97%$ end
98%$ T = all(t);
99%@eof:2