Package: matlab.unittest.constraints
Comparator for MATLAB or Java objects
ObjectComparator creates a comparator for MATLAB® or Java® objects. The comparator is satisfied if isequaln returns true. However, if the class of the expected value defines an isequal method, whether visible or hidden, but not an isequaln method, the ObjectComparator uses that method for comparison instead of isequaln.
ObjectComparator('Within', creates a comparator using a specified tolerance. tolObj)ObjectComparator first checks that a call to isequaln or isequal returns true. If the check fails, the ObjectComparator checks for equivalent class, size, and sparsity of the actual and expected values. If these checks pass, ObjectComparator delegates comparison to the supplied tolerance, tolObj. The value of this tolerance must be of the same class as the actual and expected values.
|
|
|
Specific tolerance used in construction of the comparator, specified
as a |
Value. To learn how value classes affect copy operations, see Copying Objects.
In most cases, you are not required to use an ObjectComparator
instance. The IsEqualTo class creates a
constraint to test for equality between data of various types, including
MATLAB and Java objects.
Use an ObjectComparator instance when you need to override the
comparison performed by the IsEqualTo class. For example, if
you want the comparison to fail when actual and expected values are not
MATLAB objects, include an ObjectComparator instance in
your test. In this example, MATLAB throws an exception because the actual and expected values are
numeric
scalars.
import matlab.unittest.constraints.IsEqualTo import matlab.unittest.constraints.ObjectComparator exp = 5; act = exp; testCase = matlab.unittest.TestCase.forInteractiveUse; testCase.verifyThat(act,IsEqualTo(exp,'Using',ObjectComparator))