matlab.unittest.constraints.StructComparator Class
Namespace: matlab.unittest.constraints
Comparator for structure arrays
Description
The matlab.unittest.constraints.StructComparator class provides a
comparator for structure arrays. To use this comparator in your tests, create a
StructComparator instance, and specify it as the value of the
Using name-value argument of the IsEqualTo constraint constructor.
Creation
Description
c = matlab.unittest.constraints.StructComparator
creates a comparator for empty structure arrays and structure arrays with no fields. The
comparator is satisfied if the actual and expected values are structure arrays with the
same size and fields.
c = matlab.unittest.constraints.StructComparator(
uses the specified comparators comp)comp to compare the values contained
in the structure arrays. When you use this syntax, the comparator is satisfied if the
actual and expected values are structure arrays with the same size and fields, and the
values in corresponding fields satisfy any of the comparators in
comp.
c = matlab.unittest.constraints.StructComparator(___,
sets additional options using one or more name-value arguments in addition to any of the
input argument combinations in the previous syntaxes. For example, Name,Value)c =
matlab.unittest.constraints.StructComparator("Recursively",true) creates a
comparator that operates recursively when comparing the values contained in the structure
arrays.
Input Arguments
Name-Value Arguments
Properties
Examples
Tips
In most cases, you are not required to use a
StructComparatorinstance. TheIsEqualToclass creates a constraint to test for the equality of various data types, including structure arrays.Use a
StructComparatorinstance when you need to override the comparison performed by theIsEqualToclass. For example, if you want the comparison to fail when structure arrays contain nonnumeric values, include aStructComparatorinstance in your test. In this example, MATLAB® throws an error because the actual and expected structures contain nonnumeric values.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.StructComparator import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = struct("f1",zeros(1,10),"f2",'a',"f3",{'b','c'}); act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",StructComparator(NumericComparator)))
Version History
Introduced in R2013a