Home > matpower4.1 > t > t_is.m

t_is

PURPOSE ^

T_IS Tests if two matrices are identical to some tolerance.

SYNOPSIS ^

function t_is(got, expected, prec, msg)

DESCRIPTION ^

T_IS  Tests if two matrices are identical to some tolerance.
   T_IS(GOT, EXPECTED, PREC, MSG) increments the global test count
   and if the maximum difference between corresponding elements of
   GOT and EXPECTED is less than 10^(-PREC) then it increments the
   passed tests count, otherwise increments the failed tests count.
   Prints 'ok' or 'not ok' followed by the MSG, unless the global
   variable t_quiet is true. Intended to be called between calls to
   T_BEGIN and T_END.

   Example:
       quiet = 0;
       t_begin(5, quiet);
       t_ok(pi > 3, 'size of pi');
       t_skip(3, 'not yet written');
       t_is(2+2, 4, 12, '2+2 still equals 4');
       t_end;

   See also T_OK, T_SKIP, T_BEGIN, T_END, T_RUN_TESTS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_is(got, expected, prec, msg)
0002 %T_IS  Tests if two matrices are identical to some tolerance.
0003 %   T_IS(GOT, EXPECTED, PREC, MSG) increments the global test count
0004 %   and if the maximum difference between corresponding elements of
0005 %   GOT and EXPECTED is less than 10^(-PREC) then it increments the
0006 %   passed tests count, otherwise increments the failed tests count.
0007 %   Prints 'ok' or 'not ok' followed by the MSG, unless the global
0008 %   variable t_quiet is true. Intended to be called between calls to
0009 %   T_BEGIN and T_END.
0010 %
0011 %   Example:
0012 %       quiet = 0;
0013 %       t_begin(5, quiet);
0014 %       t_ok(pi > 3, 'size of pi');
0015 %       t_skip(3, 'not yet written');
0016 %       t_is(2+2, 4, 12, '2+2 still equals 4');
0017 %       t_end;
0018 %
0019 %   See also T_OK, T_SKIP, T_BEGIN, T_END, T_RUN_TESTS.
0020 
0021 %   MATPOWER
0022 %   $Id: t_is.m,v 1.14 2011/06/29 20:36:33 cvs Exp $
0023 %   by Ray Zimmerman, PSERC Cornell
0024 %   Copyright (c) 2004-2010 by Power System Engineering Research Center (PSERC)
0025 %
0026 %   This file is part of MATPOWER.
0027 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0028 %
0029 %   MATPOWER is free software: you can redistribute it and/or modify
0030 %   it under the terms of the GNU General Public License as published
0031 %   by the Free Software Foundation, either version 3 of the License,
0032 %   or (at your option) any later version.
0033 %
0034 %   MATPOWER is distributed in the hope that it will be useful,
0035 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0036 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0037 %   GNU General Public License for more details.
0038 %
0039 %   You should have received a copy of the GNU General Public License
0040 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0041 %
0042 %   Additional permission under GNU GPL version 3 section 7
0043 %
0044 %   If you modify MATPOWER, or any covered work, to interface with
0045 %   other modules (such as MATLAB code and MEX-files) available in a
0046 %   MATLAB(R) or comparable environment containing parts covered
0047 %   under other licensing terms, the licensors of MATPOWER grant
0048 %   you additional permission to convey the resulting work.
0049 
0050 global t_quiet;
0051 
0052 if nargin < 4
0053     msg = '';
0054 end
0055 if nargin < 3 || isempty(prec)
0056     prec = 5;
0057 end
0058 [m, n] = size(expected);
0059 if all(size(got) == [m, n]) || all([m, n] == [1 1])
0060     got_minus_expected = got - expected;
0061     max_diff = max(max(abs(got_minus_expected)));
0062     condition = ( max_diff < 10^(-prec) );
0063 else
0064     condition = false;
0065     max_diff = 0;
0066 end
0067 
0068 t_ok(condition, msg);
0069 if ~condition && ~t_quiet
0070     if max_diff ~= 0
0071         [i, j, v] = find(~(abs(got_minus_expected) < 10^(-prec)));
0072         k = i+(j-1)*m;
0073         [vv, kk] = max(abs(got_minus_expected(k)));
0074         fprintf('  row     col          got             expected          got - exp\n');
0075         fprintf('-------  ------  ----------------  ----------------  ----------------');
0076         for u = 1:length(i)
0077             fprintf('\n%6d  %6d  %16g  %16g  %16g', ...
0078                 [i(u) j(u) got(k(u)) expected(k(u)) got_minus_expected(k(u))]');
0079             if u == kk
0080                 fprintf('  *');
0081             end
0082         end
0083         fprintf('\nmax diff @ (%d,%d) = %g > allowed tol of %g\n\n', ...
0084             i(kk), j(kk), max_diff, 10^(-prec));
0085     else
0086         fprintf('    dimension mismatch:\n');
0087         fprintf('             got: %d x %d\n', size(got));
0088         fprintf('        expected: %d x %d\n\n', size(expected));
0089     end
0090 end

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005