Main Content

matlab.unittest.constraints.IsSubsetOf class

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

Constraint specifying actual set is subset of expected set

Construction

IsSubsetOf(expSet) creates a constraint specifying that the actual value set is a subset of the expected value set. The constraint produces a qualification failure for any actual value set that is not a subset of the expected value set. An actual value set is considered a subset of the expected value set if ismember(actSet,expSet) 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

Superset 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 subset of Superset. 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.IsSubsetOf;

testCase = TestCase.forInteractiveUse;

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

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

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

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

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

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

---------------------
Framework Diagnostic:
---------------------
IsSubsetOf failed.
--> The actual value contains 5 element(s) not found in the expected superset:
    --> Element at index 1 not found in the expected superset:
                25
    --> Element at index 2 not found in the expected superset:
                26
    --> Element at index 3 not found in the expected superset:
                27
    --> Element at index 4 not found in the expected superset:
                28
    --> Element at index 5 not found in the expected superset:
                29

Actual Value (double):
        25    26    27    28    29    30    31    32    33
Expected Superset (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([3,1]',{'C';'A'},logical([0;1]));
expT = table([1:2:5]',{'A';'C';'E'},logical([1;0;0]));
testCase.verifyThat(actT, IsSubsetOf(expT));
Interactive verification passed.

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

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

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

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