Skip to content
Snippets Groups Projects
Commit 10f5d515 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Changed the behaviour of the unique method...

As in commit 6beaf7b0 (for the sort method).
parent e444a33e
Branches
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ switch S(1).type
error(['dates::subsref: ' S(1).subs ' is not a method but a member!'])
end
B = builtin('subsref', A, S(1));
case {'sort','sort_','unique','double','isempty','length','char','ndat'}% Public methods (without input arguments)
case {'sort','sort_','unique','unique_','double','isempty','length','char','ndat'}% Public methods (without input arguments)
B = feval(S(1).subs,A);
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
S = shiftS(S,1);
......
......@@ -30,13 +30,8 @@ if o.ndat()<=1
return
end
if isoctave || matlab_ver_less_than('8.1.0')
[tmp, id, jd] = unique(o.time,'rows');
else
[tmp, id, jd] = unique(o.time,'rows','legacy');
end
o.time = o.time(sort(id),:);
o = copy(o);
o.unique_();
%@test:1
%$ % Define some dates
......@@ -49,14 +44,80 @@ o.time = o.time(sort(id),:);
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$ f.time = [1953 4; 1950 2; 1950 1; 1945 3; 1950 2];
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ d = d.unique();
%$ try
%$ c = d.unique();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ t(1) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = size(e.time,1) == d.ndat();
%$ if t(1)
%$ t(2) = dassert(d.time,f.time);
%$ t(3) = dassert(c.time,e.time);
%$ t(4) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950q1';
%$ B4 = '1945Q3';
%$ B5 = '1950Q2';
%$
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$ f.time = [1953 4; 1950 2; 1950 1; 1945 3; 1950 2];
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ try
%$ c = unique(d);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,f.time);
%$ t(3) = dassert(c.time,e.time);
%$ t(4) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:2
%@test:3
%$ % Define some dates
%$ B1 = '1953Q4';
%$
%$ % Define expected results.
%$ e.time = [1953 4];
%$ e.freq = 4;
%$ f.time = e.time;
%$
%$ % Call the tested routine.
%$ d = dates(B1);
%$ try
%$ c = d.unique();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,f.time);
%$ t(3) = dassert(c.time,e.time);
%$ t(4) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:3
function o = unique_(o) % --*-- Unitary tests --*--
% Overloads the unique function for dates objects (in place modification).
%
% INPUTS
% - o [dates]
%
% OUPUTS
% - o [dates]
%
% REMARKS
% 1. Only the last occurence of a date is kept.
% Copyright (C) 2013-2015 Dynare Team
%
% This code 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 dates submodule 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/>.
if o.ndat()<=1
return
end
if isoctave || matlab_ver_less_than('8.1.0')
[tmp, id, jd] = unique(o.time,'rows');
else
[tmp, id, jd] = unique(o.time,'rows','legacy');
end
o.time = o.time(sort(id),:);
%@test:1
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950q1';
%$ B4 = '1945Q3';
%$ B5 = '1950Q2';
%$
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ try
%$ d.unique_();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,e.time);
%$ t(3) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:1
%@test:1
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950q1';
%$ B4 = '1945Q3';
%$ B5 = '1950Q2';
%$
%$ % Define expected results.
%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4,B5);
%$ try
%$ unique_(d);
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(d.time,e.time);
%$ t(3) = dassert(d.freq,e.freq);
%$ end
%$ T = all(t);
%@eof:1
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment