Main Content

matlab.unittest.constraints.IsSupersetOf Class

Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Test if set is superset of specified set

Description

The matlab.unittest.constraints.IsSupersetOf class provides a constraint to test if a set is a superset of another set.

The constraint uses the ismember function to compare sets. So, the actual and expected values you use with the constraint must be supported by the ismember function.

Creation

Description

c = matlab.unittest.constraints.IsSupersetOf(subset) creates a constraint to test if a set is a superset of the specified subset and sets the Subset property. For an actual set actual, the constraint is satisfied if ismember(subset,actual) returns an array that contains all true values and at least one of these conditions is met:

  • actual and subset are of the same class.

  • isobject(actual) returns true.

  • isobject(subset) returns true.

example

Properties

expand all

Expected subset, returned as a value of any data type supported by the ismember function. Specify the value of this property during creation of the constraint.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Test for supersets using the IsSupersetOf constraint.

First, import the classes used in this example.

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

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Test if {'c','a','b'} is a superset of {'a';'b'}. The test passes because the elements of the expected subset appear in the actual set and the two sets are of the same class.

testCase.verifyThat({'c','a','b'},IsSupersetOf({'a';'b'}))
Verification passed.

Test again with {'c','a','d'} as the actual set. The test fails because an element of the expected subset does not appear in the actual set.

testCase.verifyThat({'c','a','d'},IsSupersetOf({'a';'b'}))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsSupersetOf failed.
    --> The actual value is missing 1 element(s) found in the expected subset:
        --> Element at index 2:
                {'b'}
    
    Actual Value:
      1×3 cell array
    
        {'c'}    {'a'}    {'d'}
    Expected Subset:
      2×1 cell array
    
        {'a'}
        {'b'}

Verify that the numeric matrix eye(3) is not a superset of the numeric vector [1 2 3].

testCase.verifyThat(eye(3),~IsSupersetOf([1 2 3]))
Verification passed.

Test if the numeric vector 0:5 is a superset of the numeric vector single(1:3). The test fails because the actual and expected values have different types.

testCase.verifyThat(0:5,IsSupersetOf(single(1:3)))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsSupersetOf failed.
    --> Classes do not match.
        
        Actual Class:
            double
        Expected Class:
            single
    
    Actual Value:
         0     1     2     3     4     5
    Expected Subset:
      1×3 single row vector
    
         1     2     3

Compare two tables using the IsSupersetOf constraint. This test passes because the rows of the expected table appear in the actual table.

actual = table([1:2:5]',{'A';'C';'E'},logical([1;0;0]));
expected = table([3,1]',{'C';'A'},logical([0;1]));
testCase.verifyThat(actual,IsSupersetOf(expected))
Verification passed.

Version History

Introduced in R2016a