Main Content

matlab.unittest.constraints.IsEmpty 类

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

测试值是否为空

描述

matlab.unittest.constraints.IsEmpty 类提供一个约束来测试值是否为空。

创建对象

描述

示例

c = matlab.unittest.constraints.IsEmpty 创建一个约束来测试值是否为空。至少一个维度的长度等于零的数组满足该约束。

示例

全部折叠

使用 IsEmpty 约束测试值。

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

import matlab.unittest.TestCase
import matlab.unittest.TestSuite
import matlab.unittest.constraints.IsEmpty

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

testCase = TestCase.forInteractiveUse;

验证空字符向量是否满足 IsEmpty 约束。

testCase.verifyThat('',IsEmpty)
Verification passed.

验证维度长度为 0 的数组是空数组。测试通过。

testCase.verifyThat(rand(2,5,0,3),IsEmpty)
Verification passed.

验证向量 [1 1 2 3 5 8 13] 为非空向量。测试通过。

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

测试由空数值数组组成的元胞数组。测试失败,因为元胞数组不为空。

testCase.verifyThat({[],[],[]},IsEmpty)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsEmpty failed.
    --> The value must be empty.
    --> The value has a size of [1  3].
    
    Actual Value:
      1×3 cell array
    
        {0×0 double}    {0×0 double}    {0×0 double}

测试一个空测试套件。测试通过。

testCase.verifyThat(TestSuite.empty,IsEmpty)
Verification passed.

版本历史记录

在 R2013a 中推出