Main Content

matlab.unittest.constraints.IsSameSetAs class

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

Constraint specifying set contains same elements as another set

Construction

IsSameSetAs(expSet) creates a constraint specifying that a set contains same elements as another set. The constraint produces a qualification failure for any actual-value set that is not the same set as the expected-value set.

Sets can have the same elements in different orders, different numbers, or different shapes. An actual value is considered the same set as the expected set if ismember(actual,expected) and ismember(expected,actual) both return arrays that contain all true values and at least one of the following conditions is met:

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

  • The actual set is an object.

  • The expected set 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

This property is read-only.

Expected-value set to compare to actual-value set. The data type of the property depends on the test values. 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.IsSameSetAs;

testCase = TestCase.forInteractiveUse;

Verify that two sets are the same.

actSet = {'a' 'b' 'c'};
expSet = {'a' 'b' 'c'};

testCase.verifyThat(actSet,IsSameSetAs(expSet))
Interactive verification passed.

Repeat the test with a different expected set. The test fails because the sets do not contain the same elements.

expSet = {'a' 'b' 'd'};

testCase.verifyThat(actSet,IsSameSetAs(expSet))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsSameSetAs failed.
--> The actual value contains 1 element(s) not found in the expected set:
    --> Element at index 3:
            {'c'}
--> The actual value is missing 1 element(s) found in the expected set:
    --> Element at index 3:
            {'d'}

Actual Value:
  1×3 cell array

    {'a'}    {'b'}    {'c'}
Expected Set:
  1×3 cell array

    {'a'}    {'b'}    {'d'}

Verify that two sets are the same. Although the order of the elements and the shape of the sets are different, the sets contain the same elements.

actSet = [1 2 3];
expSet = [3;2;1];

testCase.verifyThat(actSet,IsSameSetAs(expSet))
Interactive verification passed.

Verify that two sets are the same. Although the expSet contains elements that are not unique and has a size that does not match actSet, the two sets have the same elements.

expSet = [1 2 3 1 2];

testCase.verifyThat(actSet,IsSameSetAs(expSet))
Interactive verification passed.
Introduced in R2018a