1function o = cumprod(varargin) % --*-- Unitary tests --*--
2
3% Overloads matlab's cumprod function for dseries objects.
4%
5% INPUTS
6% - A     dseries object [mandatory].
7% - d     dates object [optional]
8% - v     dseries object with one observation [optional]
9%
10% OUTPUTS
11% - B     dseries object.
12
13% Copyright (C) 2014-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.cumprod_();
34else
35    if isoctave
36        o = cumprod_(o, varargin{2:end});
37    else
38        o.cumprod_(varargin{2:end});
39    end
40end
41
42%@test:1
43%$ % Define a data set.
44%$ A = 2*ones(4,1);
45%$
46%$ % Define names
47%$ A_name = {'A1'};
48%$
49%$ % Instantiate a time series object.
50%$ ts = dseries(A,[],A_name,[]);
51%$
52%$ % Call the tested method.
53%$ try
54%$     ds = cumprod(ts);
55%$     t(1) = 1;
56%$ catch
57%$     t(1) = 0;
58%$ end
59%$
60%$ if t(1)
61%$     t(2) = isequal(ds.data, cumprod(A));
62%$     t(3) = isequal(ds.name{1}, 'A1');
63%$     t(4) = isequal(ds.ops{1}, 'cumprod(A1)');
64%$     t(5) = isequal(ts.data, A);
65%$     t(6) = isequal(ts.name{1}, 'A1');
66%$     t(7) = isempty(ts.ops{1});
67%$ end
68%$
69%$ T = all(t);
70%@eof:1
71
72%@test:2
73%$ % Define a data set.
74%$ A = 2*ones(7,1);
75%$
76%$ % Define names
77%$ A_name = {'A1'};
78%$
79%$ % Instantiate a time series object.
80%$ ts1 = dseries(A, [], A_name, []);
81%$ ts2 = dseries(pi, [], A_name, []);
82%$
83%$ % Call the tested method.
84%$ try
85%$   ts3 = ts1.cumprod(dates('3Y'),ts2);
86%$   t(1) = 1;
87%$ catch
88%$   t(1) = 0;
89%$ end
90%$
91%$ % Expected results.
92%$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []);
93%$
94%$ % Check the results.
95%$ if t(1)
96%$   t(2) = dassert(ts3.data, ts4.data);
97%$   t(3) = dassert(ts1.data, A);
98%$ end
99%$ T = all(t);
100%@eof:2
101