Accelerating the pace of engineering and science

# matlab.unittest.constraints.HasInf class

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

Constraint specifying array containing any infinite value

## Construction

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

## Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

## Examples

expand all

### Test That Actual Value Array Contains Infinite Value

Create a test case for interactive testing.

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

testCase = TestCase.forInteractiveUse;```

Test that the value Inf satisfies the constraint.

`testCase.verifyThat(Inf, HasInf)`
`Interactive verification passed.`

Assert that an array contains an infinite value.

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

---------------------
Framework Diagnostic:
---------------------
HasInf failed.
--> At least one element must be Inf or -Inf.

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

The array does not contain any infinite values.

Verify that an array contains an infinite value.

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

Assert that a complex number that is infinite in the imaginary part satisfies the constraint.

`testCase.assertThat(42+Inf*1i, HasInf)`
`Interactive verification passed.`

Verify that an array does not contain any infinite values.

`testCase.verifyThat([NaN -7+NaN*1i], ~HasInf)`
`Interactive verification passed.`

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