matlab.unittest.constraints.StringComparator class
Package: matlab.unittest.constraints
Comparator for two strings, character arrays, or cell arrays of character arrays
Construction
StringComparator
creates a comparator for two strings, character arrays, or cell arrays of character arrays. The comparator is satisfied if the two values are equal. By default, StringComparator
checks that the values have equal size and class, and then performs a case-sensitive comparison of each value.
StringComparator(
creates
a comparator with additional options specified by one or more Name,Value
)Name,Value
pair
arguments.
Input Arguments
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 if the comparator is insensitive to case, specified
as Default: |
|
Indicator if the comparator is insensitive to whitespace characters,
specified as Default: |
Properties
|
Indicator if the comparator is insensitive to case, specified
in the name-value pair argument, |
|
Indicator if the comparator is insensitive to whitespace characters,
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
StringComparator
object. TheIsEqualTo
class creates a constraint to test for equality between data of various types, including strings.Use a
StringComparator
object when you need to override the comparison performed by theIsEqualTo
class. For example, if you want the comparison to fail when actual and expected values are nontextual, include aStringComparator
object in your test. You also can useStringComparator
to restrict the values contained in structures, cell arrays, and tables. In this example, MATLAB® throws an exception because the actual and expected values are numeric arrays.import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.StringComparator exp = magic(5); act = exp; testCase = matlab.unittest.TestCase.forInteractiveUse; testCase.verifyThat(act,IsEqualTo(exp,'Using',StringComparator))