matlab.unittest.constraints.ReturnsTrue Class
Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint
Test if function returns true
Description
The matlab.unittest.constraints.ReturnsTrue class provides a constraint to
test if a function returns true.
The matlab.unittest.constraints.ReturnsTrue class is a handle class.
Creation
Description
c = matlab.unittest.constraints.ReturnsTrue
creates a constraint to test if a function returns true. The constraint is satisfied by a
function handle that returns a logical scalar value of 1
(true).
Examples
Tips
An alternative to
ReturnsTrueis theIsTrueconstraint.IsTrueruns faster and is easier to use, butReturnsTrueprovides slightly better diagnostic information. In this example, both tests fail, but the second test displays the function handle as part of the diagnostics.import matlab.unittest.TestCase import matlab.unittest.constraints.IsTrue import matlab.unittest.constraints.ReturnsTrue testCase = TestCase.forInteractiveUse; actual = 1; expected = 2; testCase.verifyThat(isequal(actual,expected),IsTrue) testCase.verifyThat(@() isequal(actual,expected),ReturnsTrue)