Main Content

matlab.unittest.constraints.HasInf Class

Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Test if array has infinite values


The matlab.unittest.constraints.HasInf class provides a constraint to test if an array has infinite values.




c = matlab.unittest.constraints.HasInf creates a constraint to test if an array has infinite values. The constraint is satisfied by a numeric array that has at least one infinite value.


collapse all

Test numeric arrays using the HasInf constraint.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasInf

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Verify that Inf satisfies the HasInf constraint.

Verification passed.

Test if the vector [1 1 2 3 5 8 13] has infinite values. The test fails because all vector elements are finite.

testCase.verifyThat([1 1 2 3 5 8 13],HasInf)
Verification failed.
    Framework Diagnostic:
    HasInf failed.
    --> At least one element must be Inf or -Inf.
    Actual Value:
         1     1     2     3     5     8    13

Test [-Inf 5 NaN]. The test passes because the vector contains an infinite value.

testCase.verifyThat([-Inf 5 NaN],HasInf)
Verification passed.

Test if a complex number with an infinite imaginary part satisfies the constraint. The test passes.

Verification passed.

Test if the matrix [1 NaN; -Inf 3] does not have any infinite values. The test fails.

testCase.verifyThat([1 NaN; -Inf 3],~HasInf)
Verification failed.
    Framework Diagnostic:
    Negated HasInf failed.
    --> All elements must be finite or NaN.
        Failing indices:
    Actual Value:
         1   NaN
      -Inf     3

Version History

Introduced in R2013a