Documentation Center |
Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint
General constraint to compare for equality
The IsEqualTo class creates a constraint that compares data for equality. The type of comparison it uses is governed by the data type of the expected value. First, the testing framework checks if the expected value is an object. This check is performed first because it is possible for the object to have overridden methods that are used in subsequent checks (e.g. islogical). The following list categorizes and describes the various tests.
Data Type | Equality Comparison Method |
---|---|
MATLAB^{®} & Java^{®} Objects | If the expected value is a MATLAB or Java object, the IsEqualTo constraint calls the isequal method on the expected value object. If isequal returns false and a supported tolerance is specified, the constraint checks the actual and expected values for equivalent class, size, and sparsity. If these checks fail, the constraint is not satisfied. If these checks pass, the constraint uses the tolerance in the comparison. |
Logicals | If the expected value is a logical, the constraint checks the actual and expected values for equivalent sparsity. If the sparsity matches, the constraint compares the values with the isequal method. Otherwise, the constraint is not satisfied. |
Numerics | If the expected value is numeric, the constraint checks the actual and expected values for equivalent class, size, and sparsity. If the all these checks match, the constraint uses the isequaln method for comparison. If isequaln returns true, the constraint is satisfied. If the complexity does not match or isequaln returns false, and a supported tolerance is supplied, the constraint uses the tolerance in the comparison. Otherwise, the constraint is not satisfied. |
Strings | If the expected value is a string, the constraint uses the strcmp function to check the actual and expected values for equality. However, if the IgnoreCase property is true, the strings are compared using strcmpi. If the IgnoreWhitespace is true, all whitespace characters are removed from the actual and expected strings before passing them to strcmp or strcmpi. |
Structures | If the expected value is a struct, the constraint compares the field count of the actual and expected values. If not equal, the constraint is not satisfied. Otherwise, each field of the expected value struct must exist on the actual value struct. If any field names are different, the constraint is not satisfied. Then, the constraint recursively compares the fields in a depth first examination. The recursion continues until a fundamental data type is encountered (i.e. logical, numeric, string, or object), and then the values are compared as described above. |
Cell Arrays | If the expected value is a cell array, the constraint checks the actual and expected values for size equality. If they are not equal in size, the constraint is not satisfied. Otherwise, each element of the array is recursively compared in a manner identical to fields in a structure, described above. |
IsEqualTo(expVal) provides a general constraint to compare for equality.
IsEqualTo(expVal,Name,Value) provides a constraint with additional options specified by one or more Name,Value pair arguments. Name must appear inside single quotes (''). You can specify several name-value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
expVal |
The expected value that will be compared to the actual value. |
Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB documentation.
matlab.unittest.constraints.Constraint | matlab.unittest.constraints.Tolerance