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

Rewrote min function and fixed unit tests.

parent 2b2b6f19
No related branches found
No related tags found
No related merge requests found
function C = min(varargin) function q = min(varargin) % --*-- Unitary tests --*--
% Overloads the min function for dates objects. % Overloads the min function for dates objects.
% Copyright (C) 2013 Dynare Team
% %
% This file is part of Dynare. % INPUTS
% - varargin [dates]
%
% OUTPUTS
% - q [dates]
% Copyright (C) 2013-2014 Dynare Team
% %
% Dynare is free software: you can redistribute it and/or modify % 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 % it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or % the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version. % (at your option) any later version.
% %
% Dynare is distributed in the hope that it will be useful, % Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of % but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details. % GNU General Public License for more details.
...@@ -19,22 +23,19 @@ function C = min(varargin) ...@@ -19,22 +23,19 @@ function C = min(varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~all(cellfun(@isdates,varargin))
error('dates:min:ArgCheck','All input arguments must be dates objects.')
end
switch nargin switch nargin
case 1 case 1
switch length(varargin{1}) sorted_time_member = sortrows(varargin{1}.time);
case 0 q = dates();
C= dates(); q.freq = varargin{1}.freq;
case 1 q.ndat = 1;
C = varargin{1}; q.time = sorted_time_member(1,:);
otherwise
tmp = sortrows(varargin{1}.time);
C = dates();
C.freq = varargin{1}.freq;
C.ndat = 1;
C.time = tmp(1,:);
end
otherwise otherwise
C = min(horzcat(varargin{:})); q = min(horzcat(varargin{:}));
end end
%@test:1 %@test:1
...@@ -49,8 +50,8 @@ end ...@@ -49,8 +50,8 @@ end
%$ i3 = (m3==d6); %$ i3 = (m3==d6);
%$ %$
%$ % Check the results. %$ % Check the results.
%$ t(1) = dassert(i2,1); %$ t(1) = dassert(i2,true);
%$ t(2) = dassert(i3,1); %$ t(2) = dassert(i3,true);
%$ T = all(t); %$ T = all(t);
%@eof:1 %@eof:1
...@@ -61,7 +62,7 @@ end ...@@ -61,7 +62,7 @@ end
%$ i = (m==dates('1949Q1')); %$ i = (m==dates('1949Q1'));
%$ %$
%$ % Check the results. %$ % Check the results.
%$ t(1) = dassert(i,1); %$ t(1) = dassert(i,true);
%$ T = all(t); %$ T = all(t);
%@eof:2 %@eof:2
...@@ -71,7 +72,7 @@ end ...@@ -71,7 +72,7 @@ end
%$ i = (m==dates('1949Q1')); %$ i = (m==dates('1949Q1'));
%$ %$
%$ % Check the results. %$ % Check the results.
%$ t(1) = dassert(i,1); %$ t(1) = dassert(i,true);
%$ T = all(t); %$ T = all(t);
%@eof:3 %@eof:3
...@@ -81,6 +82,6 @@ end ...@@ -81,6 +82,6 @@ end
%$ i = (m==dates('1949Q1')); %$ i = (m==dates('1949Q1'));
%$ %$
%$ % Check the results. %$ % Check the results.
%$ t(1) = dassert(i,1); %$ t(1) = dassert(i,true);
%$ T = all(t); %$ T = all(t);
%@eof:4 %@eof:4
\ 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