Main Content

matlab.unittest.constraints.HasInf Class

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

Test if array has infinite values

Description

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

Creation

Description

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.

example

Examples

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.

testCase.verifyThat(Inf,HasInf)
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.

testCase.verifyThat(3+1i/0,HasInf)
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:
            2
    
    Actual Value:
         1   NaN
      -Inf     3

Version History

Introduced in R2013a