matlab.unittest.constraints.AnyElementOf class

Package: matlab.unittest.constraints

Test if any element of array meets constraint

Description

The AnyElementOf class creates a proxy of the actual value to the framework. The proxy enables a test writer to apply a constraint against each element of an array, which ensures that a passing result occurs when at least one element of the array satisfies the constraint.

It is intended that you use this class through matlab.unittest qualifications as shown in the examples. The class does not modify the provided actual value, but serves as a wrapper to perform the constraint analysis. The testing framework analyzes the constraint on an element-by-element basis.

Construction

AnyElementOf(actVal) creates a proxy instance that tests if any element of a provided array, actVal, meets a constraint. The test passes if at least one element individually satisfies the constraint.

Tips

  • AnyElementOf checks if any element in the provided array satisfies an associated constraint. However, there are some constraints, such as HasNaN and HasInf, that natively validate if any of the elements satisfy a condition. In these situations, use of AnyElementOf is unnecessary and impedes qualification performance.

Input Arguments

actVal

Actual value to test against constraint

Properties

ActualValue

Actual value to test against constraint. Set this property through the constructor via the actVal input argument.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.

Examples

collapse all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.AnyElementOf

testCase = TestCase.forInteractiveUse;

Test that at least one element of actVal is finite.

import matlab.unittest.constraints.IsFinite
actVal = [NaN, Inf, 5];
testCase.verifyThat(AnyElementOf(actVal), IsFinite)
Interactive verification passed.

Test that at least one element of the actual value is complex.

import matlab.unittest.constraints.IsReal
testCase.verifyThat(AnyElementOf([1+0i 4i]), ~IsReal)
Interactive verification passed.

Test that at least one element of the actual value array is less than zero.

import matlab.unittest.constraints.IsLessThan
testCase.verifyThat(AnyElementOf([1 5]), IsLessThan(0))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
All elements failed. The first element failed because:
--> IsLessThan failed.
    --> The value must be less than the maximum value.
    
    Actual Value:
             1
    Maximum Value (Exclusive):
             0

Actual Value Array:
         1     5

Neither actual value element is less than zero.