pop.m 1.97 KB
Newer Older
1
function [o, id] = pop(o, a) % --*-- Unitary tests --*--
2 3

% Removes a variable from a dseries object.
4
%
5
% INPUTS
6 7 8
% - o   [dseries]  T observations and N variables.
% - a   [string]   Name of the variable to be removed.
%
9
% OUTPUTS
10
% - o   [dseries]  T observations and N-1 variables.
11

12
% Copyright (C) 2013-2017 Dynare Team
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
%
% 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/>.

29 30
o = copy(o);

31
if nargin<2
32
    [o, id] = pop_(o);
33
else
34
    [o, id] = pop_(o, a);
35 36 37 38 39 40 41 42 43 44 45 46 47 48
end

%@test:1
%$ % Define a datasets.
%$ A = rand(10,3);
%$
%$ % Define names
%$ A_name = {'A1';'A2';'A3'};
%$
%$ t = zeros(4,1);
%$
%$ % Instantiate a time series object.
%$ try
%$    ts1 = dseries(A,[],A_name,[]);
49
%$    ts2 = ts1.pop('A2');
50 51 52 53 54 55 56 57 58
%$    t(1) = 1;
%$ catch
%$    t = 0;
%$ end
%$
%$ if length(t)>1
%$    t(2) = dassert(ts2.vobs,2);
%$    t(3) = dassert(ts2.nobs,10);
%$    t(4) = dassert(ts2.data,[A(:,1), A(:,3)],1e-15);
59 60 61 62
%$    t(5) = dassert(ts1.vobs,3);
%$    if t(5)
%$      t(6) = dassert(ts1.data,A,1e-15);
%$    end
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
%$ end
%$ T = all(t);
%@eof:1

%@test:2
%$ % Define a datasets.
%$ A = rand(10,3);
%$
%$ % Define names
%$ A_name = {'A1';'A2';'A3'};
%$
%$ t = zeros(2,1);
%$
%$ % Instantiate a time series object.
%$ try
%$    ts1 = dseries(A,[],A_name,[]);
%$    [ts2,id] = pop(ts1,'A4');
%$    t(1) = 1;
%$ catch
%$    t = 0;
%$ end
%$
%$ if length(t)>1
%$    t(2) = dassert(id,0);
%$    t(2) = dassert(ts1,ts2);
%$ end
%$ T = all(t);
%@eof:2