Main Content

matlab.unittest.constraints.IsSupersetOf class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying actual set is superset of expected set

Construction

IsSupersetOf(expSet) creates a constraint specifying that the actual value set is a superset of the expected value set. The constraint produces a qualification failure for any actual value set that is not a superset of the expected value set. An actual value set is considered a superset of the expected value set if ismember(expSet,actSet) contains all true values and the actual and expected values satisfy one of the following conditions:

  • The actual and expected values are of the same class.

  • The actual value is an object.

  • The expected value is an object.

Input Arguments

expand all

Expected value set to compare to actual value set. The type of the input depends on the test values.

Properties

expand all

Subset of the actual value set. The data type of the property depends on the test values. To satisfy the constraint, the actual value set must be a superset of Subset. Set this property through the constructor via the expSet input argument.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.

Examples

collapse all

Create a test case for interactive testing.

import matlab.unittest.TestCase;
import matlab.unittest.constraints.IsSupersetOf;

testCase = TestCase.forInteractiveUse;

Verify that the actual cell array is a subset of the expected set.

testCase.verifyThat({'a','b','c'}, IsSupersetOf({'c';'b'}));
Interactive verification passed.
testCase.verifyThat({'a','b','c'}, IsSupersetOf({'a','d'}));
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsSupersetOf failed.
--> The expected subset contains 1 element(s) not found in the actual value:
    --> Element at index 2 not found in the actual value:
                'd'

Actual Value (cell):
        'a'    'b'    'c'
Expected Subset (cell):
        'a'    'd'

Assert that a set of doubles is a subset of the expected set.

testCase.assertThat(magic(21), IsSupersetOf([25;209]));
Interactive assertion passed.
testCase.assertThat(25:33, IsSupersetOf(30:40));
Interactive assertion failed.

---------------------
Framework Diagnostic:
---------------------
IsSupersetOf failed.
--> The expected subset contains elements not found in the actual value (First 5 of 7):
    --> Element at index 5 not found in the actual value:
                34
    --> Element at index 6 not found in the actual value:
                35
    --> Element at index 7 not found in the actual value:
                36
    --> Element at index 8 not found in the actual value:
                37
    --> Element at index 9 not found in the actual value:
                38

Actual Value (double):
        25    26    27    28    29    30    31    32    33
Expected Subset (double):
        30    31    32    33    34    35    36    37    38    39    40
Assertion failed.

Verify that the rows of a table are a subset of the expected table.

actT = table([1:2:5]',{'A';'C';'E'},logical([1;0;0]));
expT = table([3,1]',{'C';'A'},logical([0;1]));
testCase.verifyThat(actT, IsSupersetOf(expT));
Interactive verification passed.

Test that if the actual and expected sets have different types, the IsSubsetOf constraint is not satisfied.

testCase.assumeThat(single(0:5), IsSupersetOf(1:3));
Interactive assumption failed.

---------------------
Framework Diagnostic:
---------------------
IsSupersetOf failed.
--> Classes do not match.
    
    Actual Class:
        single
    Expected Class:
        double

Actual Value (single):
         0     1     2     3     4     5
Expected Subset (double):
         1     2     3
Assumption failed.
Introduced in R2016a