0001 function ok = t_is(got, expected, prec, msg)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 global t_quiet;
0036
0037 if nargin < 4
0038 msg = '';
0039 end
0040 if nargin < 3 || isempty(prec)
0041 prec = 5;
0042 end
0043 [m, n] = size(expected);
0044 if all(size(got) == [m, n]) || all([m, n] == [1 1])
0045 if m == 0 || n == 0
0046 condition = true;
0047 else
0048
0049 gNaN = find(isnan(got(:)));
0050 eNaN = find(isnan(expected(:)));
0051 if (~isscalar(expected) && ...
0052 (length(gNaN) ~= length(eNaN) || sum(gNaN-eNaN) ~= 0)) || ...
0053 (isscalar(expected) && ...
0054 (( isnan(expected) && ~all(isnan(got))) || ...
0055 (~isnan(expected) && any(isnan(got)))) )
0056 condition = false;
0057 max_diff = -1;
0058 elseif all(all(isnan(got))) && all(all(isnan(got)))
0059 condition = true;
0060 else
0061 got_minus_expected = got - expected;
0062 max_diff = max(max(abs(got_minus_expected)));
0063 condition = ( max_diff < 10^(-prec) );
0064 end
0065 end
0066 else
0067 condition = false;
0068 max_diff = 0;
0069 end
0070
0071 t_ok(condition, msg);
0072 if ~condition && ~t_quiet
0073 if max_diff > 0
0074 [i, j, v] = find(~(abs(got_minus_expected) < 10^(-prec)));
0075 k = i+(j-1)*m;
0076 [vv, kk] = max(abs(got_minus_expected(k)));
0077 fprintf(' row col got expected got - exp\n');
0078 fprintf('------- ------ ---------------- ---------------- ----------------');
0079 for u = 1:length(i)
0080 if isscalar(expected)
0081 ex = expected;
0082 else
0083 ex = expected(k(u));
0084 end
0085 fprintf('\n%6d %6d %16g %16g %16g', ...
0086 [i(u) j(u) got(k(u)) ex got_minus_expected(k(u))]');
0087 if u == kk
0088 fprintf(' *');
0089 end
0090 end
0091 fprintf('\nmax diff @ (%d,%d) = %g > allowed tol of %g\n\n', ...
0092 i(kk), j(kk), max_diff, 10^(-prec));
0093 elseif max_diff == -1
0094 fprintf(' mismatch in locations of NaNs\n');
0095 else
0096 fprintf(' dimension mismatch:\n');
0097 fprintf(' got: %d x %d\n', size(got));
0098 fprintf(' expected: %d x %d\n\n', size(expected));
0099 end
0100 end
0101 if nargout
0102 ok = condition;
0103 end