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 argument

  • 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 argument

  • 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 optionalerr_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):

Test that demonstrates assertion failure (3 equals 4 is false):

Test with explicit false value to show failure:

Using return values to handle assertion results:

Test with custom error message:

Example showing successful assertion with true value:

🔗 See also

assert_isfalse, assert_checkerror, assert_isequal.

🕔 History

Version
📄 Description

1.0.0

initial version

Last updated

Was this helpful?