matlab.unittest.constraints.TableComparator Class
Namespace: matlab.unittest.constraints
Comparator for table arrays
Description
The matlab.unittest.constraints.TableComparator
class provides a comparator
for MATLAB® table arrays. To use this comparator in your tests, create a
TableComparator
instance, and specify it as the value of the
Using
name-value argument of the IsEqualTo
constraint constructor.
Creation
Description
c = matlab.unittest.constraints.TableComparator
creates a comparator for empty table arrays. The comparator is satisfied if the actual and
expected values are empty table arrays with the same size and property values.
c = matlab.unittest.constraints.TableComparator(
uses the specified comparators comp
)comp
to compare the values contained
in the table arrays. When you use this syntax, the comparator is satisfied if the actual
and expected values are table arrays with the same size and property values, and the
corresponding table variables satisfy any of the comparators in
comp
.
c = matlab.unittest.constraints.TableComparator(___,"Recursively",
also specifies whether to operate recursively when comparing the values contained in the
table arrays. If tf
)tf
is true
, the recursion
continues until all nested values are examined for equality. You can use this syntax with
any of the input argument combinations in the previous syntaxes.
Input Arguments
Properties
Examples
Tips
In most cases, you are not required to use a
TableComparator
instance. TheIsEqualTo
class creates a constraint to test for the equality of various data types, including table arrays.Use a
TableComparator
instance when you need to override the comparison performed by theIsEqualTo
class. For example, if you want the comparison to fail when table arrays contain nonnumeric values, include aTableComparator
instance in your test. In this example, MATLAB throws an error because the actual and expected tables contain nonnumeric values.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.TableComparator import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = table([45;32;34],logical([1;0;0]),'VariableNames',["Age" "Vote"]); act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",TableComparator(NumericComparator)))
Version History
Introduced in R2017a