1function o = log_(o) % --*-- Unitary tests --*-- 2 3% Apply the logarithm 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) 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 28% Ensure that we never return a complex number (rather return a NaN) 29o.data(find(o.data < 0)) = NaN; 30 31o.data = log(o.data); 32 33for i=1:vobs(o) 34 if isempty(o.ops{i}) 35 o.ops(i) = {sprintf('log(%s)', o.name{i})}; 36 else 37 o.ops(i) = {sprintf('log(%s)', o.ops{i})}; 38 end 39end 40 41%@test:1 42%$ % Define a dates object 43%$ data = ones(10,2); 44%$ o = dseries(data); 45%$ q = o; 46%$ r = copy(o); 47%$ 48%$ % Call the tested routine. 49%$ try 50%$ o.log_(); 51%$ t(1) = true; 52%$ catch 53%$ t(1) = false; 54%$ end 55%$ 56%$ if t(1) 57%$ t(2) = dassert(o.data, zeros(10,2)); 58%$ t(3) = dassert(q.data, zeros(10,2)); 59%$ t(4) = dassert(r.data, ones(10, 2)); 60%$ end 61%$ 62%$ T = all(t); 63%@eof:1 64 65%@test:2 66%$ % Define a dates object 67%$ data = ones(10,2); 68%$ o = dseries(data); 69%$ q = o; 70%$ r = copy(o); 71%$ 72%$ % Call the tested routine. 73%$ try 74%$ o.log_(); 75%$ t(1) = true; 76%$ catch 77%$ t(1) = false; 78%$ end 79%$ 80%$ if t(1) 81%$ t(2) = dassert(length(o.name), 2); 82%$ t(3) = dassert(o.name{1},'Variable_1'); 83%$ t(4) = dassert(o.name{2},'Variable_2'); 84%$ t(5) = dassert(q.name{1},'Variable_1'); 85%$ t(6) = dassert(q.name{2},'Variable_2'); 86%$ t(7) = dassert(r.name{1},'Variable_1'); 87%$ t(8) = dassert(r.name{2},'Variable_2'); 88%$ t(9) = dassert(o.ops{1},'log(Variable_1)'); 89%$ t(10) = dassert(o.ops{2},'log(Variable_2)'); 90%$ t(11) = dassert(q.ops{1},'log(Variable_1)'); 91%$ t(12) = dassert(q.ops{2},'log(Variable_2)'); 92%$ t(13) = isempty(r.ops{1}); 93%$ t(14) = isempty(r.ops{2}); 94%$ end 95%$ 96%$ T = all(t); 97%@eof:2