Main Content

matlab.unittest.constraints.IsLessThanOrEqualTo Class

Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint

Test if value is less than or equal to specified value

Description

The matlab.unittest.constraints.IsLessThanOrEqualTo class provides a constraint to test if a numeric value is less than or equal to another value.

Creation

Description

c = matlab.unittest.constraints.IsLessThanOrEqualTo(ceilingValue) creates a constraint to test if a value is less than or equal to ceilingValue and sets the CeilingValue property. The sizes of the values being compared must be the same or be compatible. For more information about compatible arrays, see Compatible Array Sizes for Basic Operations.

example

Properties

expand all

Value to compare against, returned as a numeric array. Specify the value of this property during creation of the constraint.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Compare numeric values using the IsLessThanOrEqualTo constraint.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsLessThanOrEqualTo

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Verify that 2 is less than or equal to 3.

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

Test if each element of the matrix [1 2 3; 4 5 6] is less than or equal to the ceiling value 4. The test fails.

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

Verify that 2 is less than or equal to each element of the ceiling vector [2 4 7].

testCase.verifyThat(2,IsLessThanOrEqualTo([2 4 7]))
Verification passed.

Test if each element of the vector [5 -3 2] is less than or equal to each corresponding element of the ceiling vector [5 -3 8]. The test passes.

testCase.verifyThat([5 -3 2],IsLessThanOrEqualTo([5 -3 8]))
Verification passed.

Compare two equal arrays. The test passes.

testCase.verifyThat(eye(2),IsLessThanOrEqualTo(eye(2)))
Verification passed.

Version History

Introduced in R2013a