matlab.unittest.constraints.NumericComparator Class
Namespace: matlab.unittest.constraints
Comparator for numeric arrays
Description
The matlab.unittest.constraints.NumericComparator class provides a
comparator for numeric arrays. To use this comparator in your tests, create a
NumericComparator instance, and specify it as the value of the
Using name-value argument of the IsEqualTo constraint constructor.
Creation
Description
c = matlab.unittest.constraints.NumericComparator
creates a comparator for numeric arrays. The comparator is satisfied if the actual and
expected values have the same numeric class, size, complexity, and sparsity, and the
isequaln function finds them equal.
c = matlab.unittest.constraints.NumericComparator("Within",
uses the specified tolerance in comparison. When you use this syntax, the comparator first
checks for equal class, size, and sparsity of the actual and expected values. If any of
these checks fail, the comparator is not satisfied. If the checks pass, but the complexity
check or tol)isequaln check fails, the comparator delegates comparison to
tol.
Input Arguments
Properties
Examples
Tips
In most cases, you are not required to use a
NumericComparatorinstance. TheIsEqualToclass creates a constraint to test for the equality of various data types, including numeric arrays.Use a
NumericComparatorinstance when you need to override the comparison performed by theIsEqualToclass. For example, if you want the comparison to fail when actual and expected values are nonnumeric, include aNumericComparatorinstance in your test. You also can useNumericComparatorto restrict the values contained in cell arrays, structures, dictionaries, tables, and public properties of MATLAB® object arrays. In this example, MATLAB throws an error because the actual and expected values are cell arrays.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = {1,2,3}; act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",NumericComparator))
Version History
Introduced in R2013a
See Also
matlab.unittest.constraints.IsEqualTo | verifyThat | isequaln