matlab.unittest.constraints.StringComparator Class
Namespace: matlab.unittest.constraints
Comparator for string arrays, character arrays, or cell arrays of character arrays
Description
The matlab.unittest.constraints.StringComparator
class provides a
comparator for string arrays, character arrays, or cell arrays of character arrays. To use
this comparator in your tests, create a StringComparator
instance, and specify
it as the value of the Using
name-value argument of the IsEqualTo
constraint constructor.
Creation
Description
c = matlab.unittest.constraints.StringComparator
creates a comparator for string arrays, character arrays, or cell arrays of character
arrays. The comparator is satisfied if the actual and expected values are textual values
with the same class and size, and their corresponding elements are equal.
c = matlab.unittest.constraints.StringComparator(
sets additional options using one or more name-value arguments. For example, Name,Value
)c =
matlab.unittest.constraints.StringComparator("IgnoringCase",true)
creates a
comparator that is insensitive to case.
Input Arguments
Properties
Examples
Tips
In most cases, you are not required to use a
StringComparator
instance. TheIsEqualTo
class creates a constraint to test for the equality of various data types, including string arrays, character arrays, and cell arrays of character arrays.Use a
StringComparator
instance 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 not textual, include aStringComparator
instance in your test. You also can useStringComparator
to restrict the values contained in cell arrays, structures, dictionaries, tables, and public properties of MATLAB® object arrays. In this example, MATLAB throws an error because the actual and expected values are numeric arrays.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.StringComparator testCase = TestCase.forInteractiveUse; exp = magic(5); act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",StringComparator))
Version History
Introduced in R2013a
See Also
matlab.unittest.constraints.IsEqualTo
| verifyThat
| strcmp
| strncmpi