Skip to content
Snippets Groups Projects
Verified Commit 5d3de2be authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Fixed sort method.

parent c69086d7
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ function o = sort_(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dates] with dates sorted by increasing order.
% Copyright (C) 2015-2017 Dynare Team
% Copyright © 2015-2020 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
......@@ -27,60 +27,85 @@ if isequal(o.ndat(),1)
return
end
o.time = sortrows(o.time,[1,2]);
if o.freq==365
[~, io] = sort(o.time(:,1));
o.time(:,1) = o.time(io,1);
else
o.time = sortrows(o.time,[1,2]);
end
return
%@test:1
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950Q1';
%$ B4 = '1945Q3';
%$
%$ % Define expected results.
%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4];
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4);
%$ try
%$ d.sort_();
%$ 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);
% Define some dates
B1 = '1953Q4';
B2 = '1950Q2';
B3 = '1950Q1';
B4 = '1945Q3';
% Define expected results.
e.time = [1945 3; 1950 1; 1950 2; 1953 4];
e.freq = 4;
% Call the tested routine.
d = dates(B1,B2,B3,B4);
try
d.sort_();
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:2
%$ % Define some dates
%$ B1 = '1953Q4';
%$ B2 = '1950Q2';
%$ B3 = '1950Q1';
%$ B4 = '1945Q3';
%$
%$ % Define expected results.
%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4];
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4);
%$ try
%$ c = sort_(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:2
\ No newline at end of file
% Define some dates
B1 = '1953Q4';
B2 = '1950Q2';
B3 = '1950Q1';
B4 = '1945Q3';
% Define expected results.
e.time = [1945 3; 1950 1; 1950 2; 1953 4];
e.freq = 4;
% Call the tested routine.
d = dates(B1,B2,B3,B4);
try
c = sort_(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:2
%@test:3
d = dates('2000-01-01', '2001-01-01', '1999-01-02');
try
d.sort_();
t(1) = true;
catch
t(1) = false;
end
% Check the results.
if t(1)
t(2) = isequal(d,dates('1999-01-02', '2000-01-01', '2001-01-01'));
end
T = all(t);
%@eof:3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment