Test if any element of array meets constraint
The AnyElementOf class creates a proxy of the actual value to the framework. It allows a test writer to apply a constraint against each element of an array, and ensure that a passing result occurs if there is at least one element of the array that satisfies the constraint.
This class is intended to be used through matlab.unittest qualifications as is shown in the examples. The class does not modify the provided actual value, but serves as a wrapper to perform the constraint analysis. The constraint is analyzed on an element by element basis.
AnyElementOf(actVal) creates a proxy instance which tests if any element of a provided array, actVal, meets a constraint. The test passes if at least one element individually satisfies the constraint.
AnyElementOf checks whether any element in the provided array satisfies an associated constraint. However, there are some constraints, such as HasNaN and HasInf, which validate whether any element in that array satisfies the constraint without requiring the dereferencing operation outside of the constraint itself. In these situations, use of AnyElementOf is unnecessary and impedes qualification performance.
Actual value to test against constraint
Actual value to test against constraint. This property is set through the constructor via the actVal input argument.
Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.
import matlab.unittest.constraints.AnyElementOf; import matlab.unittest.constraints.IsFinite; import matlab.unittest.constraints.IsLessThan; % Create a TestCase for interactive use testCase = matlab.unittest.TestCase; % Passing verification testCase.verifyThat(AnyElementOf([NaN Inf 5]), IsFinite); % Failing assertion testCase.verifyThat(AnyElementOf([1 5]), IsLessThan(0));