[b4b313]: / matlab_xunit_3.1 / matlab_xunit / xunit / assertEqual.m

Download this file

44 lines (37 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function assertEqual(A, B, custom_message)
%assertEqual Assert that inputs are equal
% assertEqual(A, B) throws an exception if A and B are not equal. A and B
% must have the same class and sparsity to be considered equal.
%
% assertEqual(A, B, MESSAGE) prepends the string MESSAGE to the assertion
% message if A and B are not equal.
%
% Examples
% --------
% % This call returns silently.
% assertEqual([1 NaN 2], [1 NaN 2]);
%
% % This call throws an error.
% assertEqual({'A', 'B', 'C'}, {'A', 'foo', 'C'});
%
% See also assertElementsAlmostEqual, assertVectorsAlmostEqual
% Steven L. Eddins
% Copyright 2008-2010 The MathWorks, Inc.
if nargin < 3
custom_message = '';
end
if ~ (issparse(A) == issparse(B))
message = xunit.utils.comparisonMessage(custom_message, ...
'One input is sparse and the other is not.', A, B);
throwAsCaller(MException('assertEqual:sparsityNotEqual', '%s', message));
end
if ~strcmp(class(A), class(B))
message = xunit.utils.comparisonMessage(custom_message, ...
'The inputs differ in class.', A, B);
throwAsCaller(MException('assertEqual:classNotEqual', '%s', message));
end
if ~isequalwithequalnans(A, B)
message = xunit.utils.comparisonMessage(custom_message, ...
'Inputs are not equal.', A, B);
throwAsCaller(MException('assertEqual:nonEqual', '%s', message));
end