1function o = abs(o) % --*-- Unitary tests --*-- 2 3% Apply the absolute value to all the variables in a dseries object (without in place modification). 4% 5% INPUTS 6% - o [dseries] 7% 8% OUTPUTS 9% - o [dseries] 10 11% Copyright (C) 2011-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 28o = copy(o); 29o.abs_; 30 31%@test:1 32%$ % Define a dates object 33%$ data = -ones(10,2); 34%$ o = dseries(data); 35%$ q = dseries(data); 36%$ 37%$ % Call the tested routine. 38%$ try 39%$ p = o.abs(); 40%$ t(1) = true; 41%$ catch 42%$ t(1) = false; 43%$ end 44%$ 45%$ if t(1) 46%$ t(2) = dassert(o, q); 47%$ t(3) = dassert(p.data, ones(10, 2)); 48%$ end 49%$ 50%$ T = all(t); 51%@eof:1 52 53%@test:2 54%$ % Define a dates object 55%$ data = -ones(10,2); 56%$ o = dseries(data); 57%$ q = dseries(data); 58%$ 59%$ % Call the tested routine. 60%$ try 61%$ p = o.abs(); 62%$ t(1) = true; 63%$ catch 64%$ t(1) = false; 65%$ end 66%$ 67%$ if t(1) 68%$ t(2) = dassert(length(p.name), 2); 69%$ t(3) = dassert(p.ops{1},'abs(Variable_1)'); 70%$ t(4) = dassert(p.ops{2},'abs(Variable_2)'); 71%$ t(5) = dassert(p.name{1},'Variable_1'); 72%$ t(6) = dassert(p.name{2},'Variable_2'); 73%$ t(7) = dassert(o.name{1},'Variable_1'); 74%$ t(8) = dassert(o.name{2},'Variable_2'); 75%$ t(9) = isempty(o.ops{1}); 76%$ t(10) = isempty(o.ops{2}); 77%$ end 78%$ 79%$ T = all(t); 80%@eof:2 81 82%@test:3 83%$ % Define a datasets. 84%$ A = randn(10,2); 85%$ 86%$ % Define names 87%$ A_name = {'A1';'A2'}; 88%$ A_tex = {'A_1';'A_2'}; 89%$ 90%$ % Instantiate a time series object and compute the absolute value. 91%$ try 92%$ ts1 = dseries(A,[],A_name,A_tex); 93%$ ts2 = abs(ts1); 94%$ t(1) = 1; 95%$ catch 96%$ t = 0; 97%$ end 98%$ 99%$ if t(1) 100%$ t(2) = dassert(ts2.vobs,2); 101%$ t(3) = dassert(ts2.nobs,10); 102%$ t(4) = dassert(ts2.data,abs(A),1e-15); 103%$ t(5) = dassert(ts2.name,{'A1';'A2'}); 104%$ t(6) = dassert(ts2.ops,{'abs(A1)';'abs(A2)'}); 105%$ t(7) = dassert(ts2.tex,{'A_1';'A_2'}); 106%$ t(8) = dassert(ts1.vobs, 2); 107%$ t(9) = dassert(ts1.nobs, 10); 108%$ t(10) = dassert(ts1.data, A, 1e-15); 109%$ t(11) = dassert(ts1.name, {'A1';'A2'}); 110%$ t(12) = dassert(ts1.tex, {'A_1';'A_2'}); 111%$ t(13) = isempty(ts1.ops{1}); 112%$ t(14) = isempty(ts1.ops{2}); 113%$ end 114%$ T = all(t); 115%@eof:3 116 117%@test:4 118%$ % Define a datasets. 119%$ A = randn(10,2); 120%$ 121%$ % Define names 122%$ A_name = {'A1';'A2'}; 123%$ A_tex = {'A_1';'A_2'}; 124%$ 125%$ % Instantiate a time series object and compute the absolute value. 126%$ try 127%$ ts1 = dseries(A,[],A_name,A_tex); 128%$ ts2 = ts1.abs(); 129%$ t(1) = 1; 130%$ catch 131%$ t = 0; 132%$ end 133%$ 134%$ if t(1) 135%$ t(2) = dassert(ts2.vobs,2); 136%$ t(3) = dassert(ts2.nobs,10); 137%$ t(4) = dassert(ts2.data,abs(A),1e-15); 138%$ t(5) = dassert(ts2.name,{'A1';'A2'}); 139%$ t(6) = dassert(ts2.tex,{'A_1';'A_2'}); 140%$ t(7) = dassert(ts2.ops,{'abs(A1)';'abs(A2)'}); 141%$ t(8) = dassert(ts1.vobs, 2); 142%$ t(9) = dassert(ts1.nobs, 10); 143%$ t(10) = dassert(ts1.data, A, 1e-15); 144%$ t(11) = dassert(ts1.name, {'A1';'A2'}); 145%$ t(12) = dassert(ts1.tex, {'A_1';'A_2'}); 146%$ t(13) = isempty(ts1.ops{1}); 147%$ t(14) = isempty(ts1.ops{2}); 148%$ end 149%$ T = all(t); 150%@eof:4 151