matlab.unittest.constraints.StructComparator class
Package: matlab.unittest.constraints
Comparator for MATLAB structure arrays
Construction
StructComparator
creates
a comparator for MATLAB® structure arrays.
StructComparator(
indicates
a comparator, compObj
)compObj
, that defines the comparator
used to compare values contained in the structure. By default, a StructComparator
supports
only empty structure arrays.
StructComparator(
provides
a comparator with additional options specified by one or more compObj
,Name,Value
)Name,Value
pair
arguments.
StructComparator(
provides
a comparator for empty structure arrays with additional options specified
by one or more Name,Value
)Name,Value
pair arguments.
Input Arguments
Properties
|
Fields to ignore during struct comparison, specified in the
name-value pair argument, |
|
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
StructComparator
object. TheIsEqualTo
class creates a constraint to test for equality between data of various types, including structures.Use a
StructComparator
object when you need to override the comparison performed by theIsEqualTo
class. For example, if you want the comparison to fail when structures include nonnumeric values, include aStructComparator
object in your test. In this example, MATLAB throws an exception becauses1
ands2
contain nonnumeric values.import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.StructComparator import matlab.unittest.constraints.NumericComparator s1 = struct('f1',zeros(1,10),'f2','a','f3',{'b','c'}); s2 = s1; testCase = matlab.unittest.TestCase.forInteractiveUse; testCase.verifyThat(s2,IsEqualTo(s1,'Using',StructComparator(NumericComparator)))