matlab.unittest.constraints.CellComparator Class
Namespace: matlab.unittest.constraints
Comparator for cell arrays
Description
The matlab.unittest.constraints.CellComparator
class provides a comparator
for cell arrays. To use this comparator in your tests, create a CellComparator
instance, and specify it as the value of the Using
name-value argument of
the IsEqualTo
constraint constructor.
Creation
Description
c = matlab.unittest.constraints.CellComparator
creates a comparator for empty cell arrays. The comparator is satisfied if the actual and
expected values are empty cell arrays with the same size.
c = matlab.unittest.constraints.CellComparator(
uses the specified comparators comp
)comp
to compare the values contained
in the cell arrays. When you use this syntax, the comparator is satisfied if the actual
and expected values are cell arrays with the same size, and the corresponding cell array
elements satisfy any of the comparators in comp
.
c = matlab.unittest.constraints.CellComparator(___,"Recursively",
also specifies whether to operate recursively when comparing the values contained in the
cell arrays. If tf
)tf
is true
, the recursion
continues until all nested values are examined for equality. You can use this syntax with
any of the input argument combinations in the previous syntaxes.
Input Arguments
Properties
Examples
Tips
In most cases, you are not required to use a
CellComparator
instance. TheIsEqualTo
class creates a constraint to test for the equality of various data types, including cell arrays.Use a
CellComparator
instance when you need to override the comparison performed by theIsEqualTo
class. For example, if you want the comparison to fail when cell arrays contain nonnumeric values, include aCellComparator
instance in your test. In this example, MATLAB® throws an error because the actual and expected cell arrays contain nonnumeric values.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.CellComparator import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = {1,2,{3},'abc'}; act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",CellComparator(NumericComparator)))
Version History
Introduced in R2013a