matlab.unittest.constraints.CellComparator class
Package: matlab.unittest.constraints
Comparator for cell arrays
Description
The CellComparator
compares cell arrays.
Construction
CellComparator
creates
a comparator for cell arrays.
CellComparator(
indicates
a comparator, compObj
)compObj
, that defines the comparator
used to compare values contained in the cell array. By default, a
cell comparator supports only empty cell arrays.
CellComparator(
provides
a comparator with additional options specified by one or more compObj
,Name,Value
)Name,Value
pair
arguments.
CellComparator(
provides
a comparator for empty cell arrays with additional options specified
by one or more Name,Value
)Name,Value
pair arguments.
Input Arguments
|
Comparator object |
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
|
Indicator of whether comparator operates recursively, specified
as When the value is comp1 = CellComparator(StringComparator) comp2 = CellComparator(StringComparator,'Recursively', true) comp1 and comp2 support
cell arrays of strings and character arrays. However, only comp2 supports
cell arrays that recursively contain either cell arrays or strings
as their elements.
Default: |
Properties
|
Indicator of whether comparator operates recursively, specified
in the name-value pair argument, |
Copy Semantics
Value. To learn how value classes affect copy operations, see Copying Objects.
Examples
Tips
In most cases, you are not required to use a
CellComparator
object. TheIsEqualTo
class creates a constraint to test for equality between data of various types, including cell arrays.Use a
CellComparator
object when you need to override the comparison performed by theIsEqualTo
class. For example, if you want the comparison to fail when cell arrays include nonnumeric values, include aCellComparator
object in your test. In this example, MATLAB® throws an exception becauseC1
andC2
contain nonnumeric values.import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.CellComparator import matlab.unittest.constraints.NumericComparator C1 = {1,2,{3},'abc'}; C2 = C1; testCase = matlab.unittest.TestCase.forInteractiveUse; testCase.verifyThat(C2,IsEqualTo(C1,'Using',CellComparator(NumericComparator)))