1function o = rename(o, old, new) % --*-- Unitary tests --*--
2
3% Renames variables in a dseries object.
4%
5% INPUTS
6% - o     [dseries]
7% - old   [string, cell]
8% - new   [string, cell]
9%
10% OUTPUTS
11% - o     [dseries]
12
13% Copyright (C) 2013-2017 Dynare Team
14%
15% This file is part of Dynare.
16%
17% Dynare is free software: you can redistribute it and/or modify
18% it under the terms of the GNU General Public License as published by
19% the Free Software Foundation, either version 3 of the License, or
20% (at your option) any later version.
21%
22% Dynare is distributed in the hope that it will be useful,
23% but WITHOUT ANY WARRANTY; without even the implied warranty of
24% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25% GNU General Public License for more details.
26%
27% You should have received a copy of the GNU General Public License
28% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
29
30o = copy(o);
31if nargin<3
32    o.rename_(old);
33else
34    o.rename_(old, new);
35end
36
37%@test:1
38%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
39%$ try
40%$     ds = ts.rename('Output','Production');
41%$     t(1) = 1;
42%$ catch
43%$     t(1) = 0;
44%$ end
45%$
46%$ if t(1)
47%$     t(2) = dassert(ds.freq,4);
48%$     t(3) = dassert(ds.init.freq,4);
49%$     t(4) = dassert(ds.init.time,[1950, 1]);
50%$     t(5) = dassert(ds.vobs,2);
51%$     t(6) = dassert(ds.nobs,5);
52%$     t(7) = dassert(ds.name,{'Production'; 'Consumption'});
53%$     t(8) = dassert(ds.tex,{'Y_t'; 'C_t'});
54%$ end
55%$
56%$ T = all(t);
57%@eof:1
58
59%@test:2
60%$ ts = dseries(randn(10,1));
61%$ try
62%$     ds = ts.rename('Dora');
63%$     t(1) = 1;
64%$ catch
65%$     t(1) = 0;
66%$ end
67%$
68%$ if t(1)
69%$     t(2) = dassert(ds.name,{'Dora'});
70%$ end
71%$
72%$ T = all(t);
73%@eof:2