Home > matlab > utilities > tests > dyn_assert.m

dyn_assert

PURPOSE ^

This function tests the equality of two objects.

SYNOPSIS ^

function t = dyn_assert(A,B,tol)

DESCRIPTION ^

 This function tests the equality of two objects.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t = dyn_assert(A,B,tol)
0002 % This function tests the equality of two objects.
0003 
0004 % Copyright (C) 2011 Dynare Team
0005 % stephane DOT adjemian AT univ DASH lemans DOT fr
0006 %
0007 % This file is part of Dynare.
0008 %
0009 % Dynare is free software: you can redistribute it and/or modify
0010 % it under the terms of the GNU General Public License as published by
0011 % the Free Software Foundation, either version 3 of the License, or
0012 % (at your option) any later version.
0013 %
0014 % Dynare is distributed in the hope that it will be useful,
0015 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 % GNU General Public License for more details.
0018 %
0019 % You should have received a copy of the GNU General Public License
0020 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 if ( (nargin<3) || isempty(tol) )
0023     use_isequal_matlab_builtin = 1;
0024 else
0025     use_isequal_matlab_builtin = 0;
0026 end
0027 
0028 [nA,mA] = size(A);
0029 [nB,mB] = size(B);
0030 
0031 if nA-nB
0032     error('assert:: Dimensions of compared objects A and B don''t match!')
0033 end
0034 
0035 if mA-mB
0036     error('assert:: Dimensions of compared objects A and B don''t match!')
0037 end
0038 
0039 if isstruct(B) && ~isstruct(A)
0040     error('assert:: Compared objects are not of the same type!')
0041 end
0042 
0043 if iscell(B) && ~iscell(A)
0044     error('assert:: Compared objects are not of the same type!')
0045 end
0046 
0047 if use_isequal_matlab_builtin
0048     t = isequal(A,B);
0049     if ~t
0050         t = isequalwithequalnans(A,B);
0051     end
0052 else
0053     t = 1;
0054     if ~(isstruct(B) || iscell(B))
0055         if max(abs(A(:)-B(:)))>tol
0056             t = 0;
0057         end
0058     else
0059         % not yet implemented
0060         t = NaN;
0061     end
0062 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005