Test if all elements of array meets constraint
The EveryElementOf 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 every 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.
EveryElementOf(actVal) creates a proxy instance which tests if every element of a provided array, actVal, meets a constraint. The test passes if all elements satisfy the constraint.
EveryElementOf checks whether every element in the provided array satisfies an associated constraint. However, there are some constraints, such as IsEqualTo and IsGreaterThan, IsLessThan, which validate all elements in the array satisfies the constraint without requiring the dereferencing operation outside of the constraint itself. In these situations, use of EveryElementOf 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.EveryElementOf; import matlab.unittest.constraints.HasNaN; import matlab.unittest.constraints.IsGreaterThan; % Create a TestCase for interactive use testCase = matlab.unittest.TestCase; % Passing verification testCase.verifyThat(EveryElementOf([1 5]), IsGreaterThan(0)); % Failing assertion testCase.verifyThat(EveryElementOf([NaN Inf 5]), HasNaN);