matlab.unittest.constraints.IsTrue class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint

Constraint specifying true value

Construction

IsTrue provides a constraint specifying a true value. This constraint is satisfied only by a scalar logical with a value of true.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.

Examples

collapse all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsTrue

testCase = TestCase.forInteractiveUse;

Test that true satisfies the IsTrue constraint.

testCase.verifyThat(true, IsTrue)
Interactive verification passed.

Test that the IsTrue constraint is not satisfied by false.

testCase.verifyThat(false, IsTrue)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsTrue failed.
--> The value must evaluate to "true".

Actual Value:
         0

The test fails because false returns logical(0).

Test that the IsTrue constraint is not satisfied by the double 1.

testCase.verifyThat(1, IsTrue)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsTrue failed.
--> The value must be logical. It is of type "double".

Actual Value:
         1

The IsTrue constraint is satisfied only by logical(1).

Test that the IsTrue constraint is not satisfied by a logical array of ones.

testCase.verifyThat([true true true], IsTrue)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsTrue failed.
--> The value must be scalar. It has a size of [1  3].

Actual Value:
         1     1     1

The IsTrue constraint is satisfied only if the value is scalar and logical(1).

Tips

  • For faster test execution, use verifyTrue, assertTrue, assumeTrue, or fatalAssertTrue instead of IsTrue.

  • To display custom comparisons in the form of a function handle, use ReturnsTrue instead of IsTrue.