matlab.unittest.constraints.DictionaryComparator Class
Namespace: matlab.unittest.constraints
Description
The matlab.unittest.constraints.DictionaryComparator class provides a
comparator for dictionaries. To use this comparator in your tests, create a
DictionaryComparator instance, and specify it as the value of the
Using name-value argument of the IsEqualTo constraint constructor.
Creation
Description
c = matlab.unittest.constraints.DictionaryComparator
creates a comparator for unconfigured dictionaries. The comparator is satisfied if the
actual and expected values are dictionaries with no keys or values.
c = matlab.unittest.constraints.DictionaryComparator(
uses the specified comparators comp)comp to compare the values contained
in the dictionaries. When you use this syntax, the comparator is satisfied if the actual
and expected values are dictionaries with the same keys, and the values assigned to
corresponding keys satisfy any of the comparators in comp.
c = matlab.unittest.constraints.DictionaryComparator(___,Recursively=
also specifies whether to operate recursively when comparing the values contained in the
dictionaries. 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
DictionaryComparatorinstance. TheIsEqualToclass creates a constraint to test for the equality of various data types, including dictionaries.Use a
DictionaryComparatorinstance when you need to override the comparison performed by theIsEqualToclass. For example, if you want the comparison to fail when dictionaries contain nonnumeric values, include aDictionaryComparatorinstance in your test. In this example, MATLAB® throws an error because the actual and expected dictionaries contain nonnumeric values assigned to their keys.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.DictionaryComparator import matlab.unittest.constraints.NumericComparator testCase = TestCase.forInteractiveUse; exp = dictionary([1 2 3],[true true false]); act = exp; testCase.verifyThat(act,IsEqualTo(exp,Using=DictionaryComparator(NumericComparator)))
Version History
Introduced in R2022b