assert_istrue
Check that condition is true.
📝Syntax
assert_istrue(x)
r = assert_istrue(x)
[r, msg] = assert_istrue(x)
assert_istrue(x, err_msg)
r = assert_istrue(x, err_msg)
[r, msg] = assert_istrue(x, err_msg)
📥Input Arguments
Parameter Description
x a logical value to be tested for truthfulness.
err_msg a string containing the custom error message to display in case of assertion failure (optional).
📤Output Arguments
Parameter Description
r a logical value: true if the assertion passes, false otherwise.
msg a string containing the error message. If x == true, then msg == ''. If x == false, then msg contains the assertion failure message.
📄Description

assert_istrue raises an error if the input value is false.

This function also raises an error if the input is not a logical value, ensuring type safety.

When the optional err_msg parameter is provided, it will be used as the error message instead of the default message when the assertion fails.

This function is essential in unit testing to verify that conditions are true or that logical operations return the expected true result.

💡Examples
Test that passes (3 equals 3 is true):
assert_istrue(3 == 3)
Test that demonstrates assertion failure (3 equals 4 is false):
try
    assert_istrue(3 == 4)
catch ME
    disp(['Error: ' ME.message])
end
Test with explicit false value to show failure:
r = assert_istrue(false)
Using return values to handle assertion results:
[r, msg] = assert_istrue(false)
Test with custom error message:
[r, msg] = assert_istrue(3 == 4, 'your error message.');
if ~r
    disp(['Custom error: ' msg])
end
Example showing successful assertion with true value:
assert_istrue(true);
disp('Assertion passed!')
🔗See Also
assert_isfalseassert_checkerrorassert_isequal
🕔Version History
Version Description
1.0.0 initial version
Edit this page on GitHub