matlab.unittest.constraints.IsReal class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying real valued array

Construction

IsReal provides a constraint specifying a real valued array. This constraint is satisfied only if the actual value contains only real values.

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.IsReal

testCase = TestCase.forInteractiveUse;

Verify that the values 5 and 5+0i are real.

testCase.verifyThat(5, IsReal)
testCase.verifyThat(5+0i, IsReal)
Interactive verification passed.
Interactive verification passed.

Test if the imaginary number is real.

testCase.verifyThat(sqrt(-1), IsReal)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsReal failed.
--> The value must be real.

Actual Value:
      0.000000000000000 + 1.000000000000000i

The actual value is imaginary.

Assert that an array contains only real values.

testCase.assertThat([0 1 1 2 3 5 8 13], IsReal)
Interactive assertion passed.

Test that the array, arr, is real.

arr = [NaN -Inf];
testCase.verifyThat(arr, IsReal)
Interactive verification passed.

Multiply the array by a complex number and test that the values are not real.

testCase.verifyThat(42i*arr, ~IsReal)
Interactive verification passed.

See Also