matlab.unittest.constraints.CellComparator 类
命名空间: matlab.unittest.constraints
元胞数组的比较器
描述
matlab.unittest.constraints.CellComparator
类为元胞数组提供比较器。要在测试中使用此比较器,请创建一个 CellComparator
实例,并将其指定为 IsEqualTo
约束构造函数的 Using
名称-值参量的值。
创建对象
描述
c = matlab.unittest.constraints.CellComparator
为空元胞数组创建一个比较器。如果实际值和预期值是大小相同的空元胞数组,则满足比较器。
c = matlab.unittest.constraints.CellComparator(
使用指定的比较器 comp
)comp
来比较元胞数组中包含的值。使用此语法时,如果实际值和预期值是大小相同的元胞数组,并且对应的元胞数组元素满足 comp
中的任一比较器,则满足该比较器。
输入参量
属性
示例
提示
在大多数情况下,您不需要使用
CellComparator
实例。IsEqualTo
类创建一个约束来测试各种数据类型的相等性,包括元胞数组。当需要覆盖由
IsEqualTo
类执行的比较时,请使用CellComparator
实例。例如,如果希望在元胞数组包含非数值时比较失败,请在测试中包含CellComparator
实例。在此示例中,MATLAB® 引发错误,因为实际和预期元胞数组包含非数值。import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.CellComparator import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = {1,2,{3},'abc'}; act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",CellComparator(NumericComparator)))
版本历史记录
在 R2013a 中推出