1function o = abs_(o) % --*-- Unitary tests --*--
2
3% Apply the absolute value to all the variables in a dseries object (in place modification).
4%
5% INPUTS
6% - o [dseries]
7%
8% OUTPUTS
9% - o [dseries]
10
11% Copyright (C) 2017 Dynare Team
12%
13% This file is part of Dynare.
14%
15% Dynare is free software: you can redistribute it and/or modify
16% it under the terms of the GNU General Public License as published by
17% the Free Software Foundation, either version 3 of the License, or
18% (at your option) any later version.
19%
20% Dynare is distributed in the hope that it will be useful,
21% but WITHOUT ANY WARRANTY; without even the implied warranty of
22% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23% GNU General Public License for more details.
24%
25% You should have received a copy of the GNU General Public License
26% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
27
28for i=1:vobs(o)
29    if isempty(o.ops{i})
30        o.ops(i) = {['abs(' o.name{i} ')']};
31    else
32        o.ops(i) = {['abs(' o.ops{i} ')']};
33    end
34end
35
36o.data = abs(o.data);
37
38%@test:1
39%$ % Define a dates object
40%$ data = -ones(10,2);
41%$ o = dseries(data);
42%$ q = o;
43%$ r = copy(o);
44%$
45%$ % Call the tested routine.
46%$ try
47%$     o.abs_();
48%$     t(1) = true;
49%$ catch
50%$     t(1) = false;
51%$ end
52%$
53%$ if t(1)
54%$      t(2) = dassert(o.data, ones(10,2));
55%$      t(3) = dassert(q.data, ones(10,2));
56%$      t(4) = dassert(r.data, -ones(10, 2));
57%$      t(5) = dassert(o.name{1}, 'Variable_1');
58%$      t(6) = dassert(q.name{1}, 'Variable_1');
59%$      t(7) = dassert(r.name{1}, 'Variable_1');
60%$      t(8) = dassert(o.ops{1}, 'abs(Variable_1)');
61%$      t(9) = dassert(q.ops{1}, 'abs(Variable_1)');
62%$      t(10) = dassert(r.name{1}, 'Variable_1');
63%$ end
64%$
65%$ T = all(t);
66%@eof:1
67
68%@test:2
69%$ % Define a dates object
70%$ data = [ones(10,1), -ones(10,1)];
71%$ o = dseries(data);
72%$ q = o;
73%$ r = copy(o);
74%$
75%$ % Call the tested routine.
76%$ try
77%$     o.abs_();
78%$     t(1) = true;
79%$ catch
80%$     t(1) = false;
81%$ end
82%$
83%$ if t(1)
84%$      t(2) = dassert(length(o.name), 2);
85%$      t(3) = dassert(o.name{1},'Variable_1');
86%$      t(4) = dassert(o.name{2},'Variable_2');
87%$      t(5) = dassert(q.name{1},'Variable_1');
88%$      t(6) = dassert(q.name{2},'Variable_2');
89%$      t(7) = dassert(r.name{1},'Variable_1');
90%$      t(8) = dassert(r.name{2},'Variable_2');
91%$      t(9) = dassert(o.ops{1},'abs(Variable_1)');
92%$      t(10) = dassert(o.ops{2},'abs(Variable_2)');
93%$      t(11) = dassert(q.ops{1},'abs(Variable_1)');
94%$      t(12) = dassert(q.ops{2},'abs(Variable_2)');
95%$      t(13) = isempty(r.ops{1});
96%$      t(14) = isempty(r.ops{2});
97%$ end
98%$
99%$ T = all(t);
100%@eof:2