matlab.unittest.constraints.HasNaN class

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

Constraint specifying array containing NaN value

Construction

HasNaN creates a constraint that is able to determine if any value of an actual value array is NaN. This constraint is satisfied only if the actual value array contains at least one NaN value.

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

testCase = TestCase.forInteractiveUse;

Test that the value NaN satisfies the constraint.

testCase.verifyThat(NaN, HasNaN)
Interactive verification passed.

Assert that an array contains a NaN value.

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

---------------------
Framework Diagnostic:
---------------------
HasNaN failed.
--> At least one element must be NaN.

Actual double:
         0     1     1     2     3     5     8    13
Assertion failed.

The array does not contain a NaN value.

Verify that an array contains a NaN value.

testCase.verifyThat([-Inf 5 NaN], HasNaN)
Interactive verification passed.

Assert that a complex number satisfies the constraint.

testCase.assertThat(42+NaN*1i, HasNaN)
Interactive assertion passed.

Verify that an array does not contain any NaN values.

testCase.verifyThat([Inf -7+Inf*1i], ~HasNaN)
Interactive verification passed.

Negating the HasNaN constraint does not ensure the value is finite, only that it does not contain any NaN values.

See Also

| |