rename.m 1.72 KB
Newer Older
Stéphane Adjemian's avatar
Stéphane Adjemian committed
1
function o = rename(o, old, new) % --*-- Unitary tests --*--
2

3 4
% Renames variables in a dseries object.
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
5
% INPUTS
6 7 8 9
% - o     [dseries]
% - old   [string, cell]
% - new   [string, cell]
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
10
% OUTPUTS
11 12 13
% - o     [dseries]

% Copyright (C) 2013-2017 Dynare Team
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

30
o = copy(o);
31
if nargin<3
32
    o.rename_(old);
Houtan Bastani's avatar
Houtan Bastani committed
33
else
Stéphane Adjemian's avatar
Stéphane Adjemian committed
34
    o.rename_(old, new);
Houtan Bastani's avatar
Houtan Bastani committed
35
end
36 37 38 39

%@test:1
%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
%$ try
40
%$     ds = ts.rename('Output','Production');
41 42
%$     t(1) = 1;
%$ catch
43
%$     t(1) = 0;
44 45
%$ end
%$
46 47 48 49 50 51 52 53
%$ if t(1)
%$     t(2) = dassert(ds.freq,4);
%$     t(3) = dassert(ds.init.freq,4);
%$     t(4) = dassert(ds.init.time,[1950, 1]);
%$     t(5) = dassert(ds.vobs,2);
%$     t(6) = dassert(ds.nobs,5);
%$     t(7) = dassert(ds.name,{'Production'; 'Consumption'});
%$     t(8) = dassert(ds.tex,{'Y_t'; 'C_t'});
54 55 56 57 58 59
%$ end
%$
%$ T = all(t);
%@eof:1

%@test:2
Stéphane Adjemian's avatar
Stéphane Adjemian committed
60 61
%$ ts = dseries(randn(10,1));
%$ try
62
%$     ds = ts.rename('Dora');
Houtan Bastani's avatar
Houtan Bastani committed
63 64
%$     t(1) = 1;
%$ catch
65
%$     t(1) = 0;
Houtan Bastani's avatar
Houtan Bastani committed
66 67
%$ end
%$
68 69
%$ if t(1)
%$     t(2) = dassert(ds.name,{'Dora'});
Houtan Bastani's avatar
Houtan Bastani committed
70 71 72
%$ end
%$
%$ T = all(t);
73
%@eof:2