1function o = center(o, geometric) % --*-- Unitary tests --*--
2
3% Centers dseries object o around its mean (arithmetic or geometric).
4%
5% INPUTS
6%  - o             dseries object [mandatory].
7%  - geometric     logical [default is false], if true returns the geometric mean.
8%
9% OUTPUTS
10%  - o             dseries object.
11
12% Copyright (C) 2016-2017 Dynare Team
13%
14% This file is part of Dynare.
15%
16% Dynare is free software: you can redistribute it and/or modify
17% it under the terms of the GNU General Public License as published by
18% the Free Software Foundation, either version 3 of the License, or
19% (at your option) any later version.
20%
21% Dynare is distributed in the hope that it will be useful,
22% but WITHOUT ANY WARRANTY; without even the implied warranty of
23% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24% GNU General Public License for more details.
25%
26% You should have received a copy of the GNU General Public License
27% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
28
29if nargin<2
30    geometric = false;
31end
32
33o = copy(o);
34o.center_(geometric);
35
36%@test:1
37%$ % Define a dataset.
38%$ A = repmat([1.005, 1.05], 10, 1);
39%$
40%$ % Instantiate a time series object and compute the mean.
41%$ try
42%$    ts = dseries(A);
43%$    ds = ts.center(true);
44%$    t(1) = 1;
45%$ catch
46%$    t = 0;
47%$ end
48%$
49%$ if t(1)
50%$    t(2) = all(all(abs(ds.data-ones(10,2))<1e-12));
51%$    t(3) = all(all(abs(ts.data-A)<1e-12));
52%$    t(4) = dassert(ds.ops{1}, 'center(Variable_1, 1)');
53%$    t(5) = dassert(ds.name{1}, 'Variable_1');
54%$    t(6) = isempty(ts.ops{1});
55%$    t(7) = dassert(ds.name{1}, 'Variable_1');
56%$ end
57%$ T = all(t);
58%@eof:1
59