Main Content

matlab.unittest.constraints.HasInf 类

命名空间: matlab.unittest.constraints
超类: matlab.unittest.constraints.BooleanConstraint

测试数组是否包含无限值

描述

matlab.unittest.constraints.HasInf 类提供一个约束来测试数组是否包含无限值。

创建对象

描述

示例

c = matlab.unittest.constraints.HasInf 创建一个约束来测试数组是否包含无限值。包含至少一个无限值的数值数组满足该约束。

示例

全部折叠

使用 HasInf 约束测试数值数组。

首先,导入此示例中使用的类。

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

创建一个供交互测试的测试用例。

testCase = TestCase.forInteractiveUse;

验证 Inf 满足 HasInf 约束。

testCase.verifyThat(Inf,HasInf)
Verification passed.

测试向量 [1 1 2 3 5 8 13] 是否包含无限值。测试失败,因为所有向量元素都是有限值。

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

测试 [-Inf 5 NaN]。测试通过,因为向量包含一个无限值。

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

测试虚部是无限值的复数是否满足约束。测试通过。

testCase.verifyThat(3+1i/0,HasInf)
Verification passed.

测试矩阵 [1 NaN; -Inf 3] 是否不包含任何无限值。测试失败。

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

版本历史记录

在 R2013a 中推出