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 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)