matlab.unittest.constraints.ObjectComparator Class
Namespace: matlab.unittest.constraints
Comparator for MATLAB or Java object arrays
Description
The matlab.unittest.constraints.ObjectComparator
class provides a
comparator for MATLAB® or Java® object arrays. To use this comparator in your tests, create an
ObjectComparator
instance, and specify it as the value of the
Using
name-value argument of the IsEqualTo
constraint constructor.
Creation
Description
c = matlab.unittest.constraints.ObjectComparator
creates a comparator for MATLAB or Java object arrays. The comparator first checks if the actual and expected values
are object arrays of the same class and size with equal values for all properties. If so,
then the comparator is satisfied. Otherwise, the comparator calls
isequaln
or isequal
to make a comparison. (If the
class of the expected value defines an isequaln
method, the comparator
calls isequaln
. Otherwise, it calls isequal
.) The
comparator is satisfied if the call returns true
.
c = matlab.unittest.constraints.ObjectComparator("Within",
uses the specified tolerance in comparison. When you use this syntax, the comparator first
checks for equality, as described above. If the check passes, the comparator is satisfied.
Otherwise, the comparator checks for equal class, size, and sparsity of the actual and
expected values. If any of these checks fail, the comparator is not satisfied. If they
pass, the comparator delegates comparison to tol
)tol
.
Input Arguments
Properties
Examples
Tips
In most cases, you are not required to use an
ObjectComparator
instance. TheIsEqualTo
class creates a constraint to test for the equality of various data types, including MATLAB and Java object arrays.Use an
ObjectComparator
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 MATLAB object arrays, include anObjectComparator
instance in your test. You also can useObjectComparator
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 scalars.import matlab.unittest.TestCase import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.ObjectComparator testCase = TestCase.forInteractiveUse; exp = 5; act = exp; testCase.verifyThat(act,IsEqualTo(exp,"Using",ObjectComparator))
Version History
Introduced in R2013a