# matlab.unittest.constraints.IsFinite Class

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

Test if array elements are finite values

## Description

The `matlab.unittest.constraints.IsFinite` class provides a constraint to test if elements of an array are finite values.

## Creation

### Description

example

````c = matlab.unittest.constraints.IsFinite` creates a constraint to test if all elements of an array are finite values. The constraint is satisfied by a numeric array that does not contain any infinite or `NaN` values.```

## Examples

collapse all

Test numeric arrays using the `IsFinite` constraint.

First, import the classes used in this example.

```import matlab.unittest.TestCase import matlab.unittest.constraints.IsFinite ```

Create a test case for interactive testing.

`testCase = TestCase.forInteractiveUse;`

Verify that the value `5` is finite.

`testCase.verifyThat(5,IsFinite)`
`Verification passed.`

Test if the vector `[1 1 2 3 5 8 13]` satisfies the `IsFinite` constraint. The test passes because all vector elements are finite.

`testCase.verifyThat([1 1 2 3 5 8 13],IsFinite)`
`Verification passed.`

Test `[-Inf 5 NaN]`. The test fails because the vector contains an infinite value as well as a `NaN` value.

`testCase.verifyThat([-Inf 5 NaN],IsFinite)`
```Verification failed. --------------------- Framework Diagnostic: --------------------- IsFinite failed. --> All elements must be finite-valued. Failing indices: [1 3] Actual Value: -Inf 5 NaN```

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

`testCase.verifyThat(3+1i/0,IsFinite)`
```Verification failed. --------------------- Framework Diagnostic: --------------------- IsFinite failed. --> The value must be finite. Actual Value: 3.000000000000000 + Infi```

Verify that the matrix `[1 NaN; -Inf 3]` is not finite.

`testCase.verifyThat([1 NaN; -Inf 3],~IsFinite)`
`Verification passed.`

## Version History

Introduced in R2013a