matlab.unittest.constraints.IsLessThanOrEqualTo class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint

Constraint specifying value less than or equal to another value

Construction

IsLessThanOrEqualTo(ceilVal) creates a constraint specifying that an actual value is less than or equal to another value. The constraint is satisfied if the actual value array is less than or equal to the specified ceiling value, ceilVal. The actual value is less than or equal to ceilVal only if the result of the expression actual <= ceilVal is nonempty and all values are true.

Input Arguments

ceilVal

Maximum value to satisfy the constraint.

Properties

CeilingValue

Maximum value to satisfy the constraint. Set this property through the constructor via the ceilVal input argument.

Methods

andForm logical conjunction of constraints
orForm logical disjunction of constraints

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Examples

expand all

Test That Actual Value Is Less Than or Equal to Provided Ceiling Value

Create a test case for interactive testing.

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

testCase = TestCase.forInteractiveUse;

Test that the actual value is less than or equal to four.

actVal = 3;
testCase.verifyThat(actVal, IsLessThanOrEqualTo(4))
Interactive verification passed.

Test that the actual value is less than or equal to three.

testCase.verifyThat(actVal, IsLessThanOrEqualTo(3))
Interactive verification passed.

Test that each element in the actual value array is less than or equal to four.

actVal = [1 2 3 4];
testCase.verifyThat(actVal, IsLessThanOrEqualTo(4))
Interactive verification passed.

Test that each element in the actual value matrix is less than or equal to four.

actVal = [1 2 3; 4 5 6];
testCase.verifyThat(actVal, IsLessThanOrEqualTo(4))
Interactive 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

The matrix contains two elements that are greater than four.

Test that the actual value, 1, is less than or equal to every element in an array.

testCase.verifyThat(1, IsLessThanOrEqualTo([1 2 3]))
Interactive verification passed.

Test that elements in the actual value array are less than the corresponding ceiling values.

testCase.verifyThat([4 -9 2], IsLessThanOrEqualTo([5 -3 2]))
Interactive verification passed.

Repeat the test, this time negating the second actual value element.

testCase.verifyThat([4 9 2], IsLessThanOrEqualTo([5 -3 2]))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsLessThanOrEqualTo failed.
--> Each element must be less than or equal to each corresponding element of the maximum array.
    
    Failing Indices:
             2

Actual Value:
         4     9     2
Maximum Value (Inclusive):
         5    -3     2

The negated element is greater than -3.

Was this topic helpful?