assert_isequal(computed, expected)
res = assert_isequal(computed, expected)
[res, msg] = assert_isequal(computed, expected)
| Parameter | Description |
|---|---|
| computed | a value of any type to be tested for equality. |
| expected | a value of any type representing the expected result. |
| Parameter | Description |
|---|---|
| res | a logical value: true if values are equal, false otherwise. |
| msg | a string containing the error message. If res == true, then msg == ''. If res == false, then msg contains the assertion failure message. |
assert_isequal raises an error if the computed value is not equal to the expected value.
This function performs strict equality testing that checks for same type, same dimensions, and same values comparisons. It uses the same logic as the isequaln function.
Unlike standard equality operators, this function properly handles NaN values, considering them equal when both values contain NaN in the same positions.
This function is essential for unit testing to verify that computed results match expected outcomes exactly.
A = eye(3, 3);
assert_isequal(A, A)
A = eye(3, 3);
B = single(A);
try
assert_isequal(A, B)
catch ME
disp(['Error: ' ME.message])
end
A = NaN;
B = A;
assert_isequal(A, B)
[res, msg] = assert_isequal([1, 2, 3], [1, 2, 4]);
if res
disp('Values are equal')
else
disp(['Values are not equal: ' msg])
end
| Version | Description |
|---|---|
| 1.0.0 | initial version |