Main Content

matlab.unittest.constraints.IsLessThan 类

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

测试值是否小于指定值

描述

matlab.unittest.constraints.IsLessThan 类提供一个约束来测试数值是否小于另一个值。

创建对象

描述

示例

c = matlab.unittest.constraints.IsLessThan(ceilingValue) 创建一个约束来测试值是否小于 ceilingValue 并设置 CeilingValue 属性。进行比较的值的大小必须相同或兼容。有关兼容数组的详细信息,请参阅基本运算的兼容数组大小

属性

全部展开

要比较的值,以数值数组形式返回。在创建约束的过程中指定此属性的值。

属性:

GetAccess
public
SetAccess
private

示例

全部折叠

使用 IsLessThan 约束比较数值。

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsLessThan

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

testCase = TestCase.forInteractiveUse;

验证 2 是否小于 3

testCase.verifyThat(2,IsLessThan(3))
Verification passed.

测试矩阵 [1 2 3; 4 5 6] 的每个元素是否小于上限值 4。测试失败。

testCase.verifyThat([1 2 3; 4 5 6],IsLessThan(4))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsLessThan failed.
    --> Each element must be less than the maximum value.
        
        Failing Indices:
             2     4     6
    
    Actual Value:
         1     2     3
         4     5     6
    Maximum Value (Exclusive):
         4

验证 2 小于上限值向量 [5 6 7] 的每个元素。

testCase.verifyThat(2,IsLessThan([5 6 7]))
Verification passed.

测试向量 [5 -3 2] 的每个元素是否小于上限值向量 [7 -1 8] 的每个对应元素。测试通过。

testCase.verifyThat([5 -3 2],IsLessThan([7 -1 8]))
Verification passed.

比较两个相等的数组。测试失败。

testCase.verifyThat(eye(2),IsLessThan(eye(2)))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsLessThan failed.
    --> Each element must be less than each corresponding element of the maximum value array.
        
        Failing Indices:
             1     2     3     4
    
    Actual Value:
         1     0
         0     1
    Maximum Value (Exclusive):
         1     0
         0     1

版本历史记录

在 R2013a 中推出