Main Content

matlab.unittest.constraints.IsEmpty Class

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

Test if value is empty

Description

The matlab.unittest.constraints.IsEmpty class provides a constraint to test if a value is empty.

Creation

Description

example

c = matlab.unittest.constraints.IsEmpty creates a constraint to test if a value is empty. The constraint is satisfied by an array that has at least one dimension length equal to zero.

Examples

collapse all

Test values using the IsEmpty constraint.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.unittest.TestSuite
import matlab.unittest.constraints.IsEmpty

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Verify that an empty character vector satisfies the IsEmpty constraint.

testCase.verifyThat('',IsEmpty)
Verification passed.

Verify that an array with a zero dimension length is empty. The test passes.

testCase.verifyThat(rand(2,5,0,3),IsEmpty)
Verification passed.

Verify that the vector [1 1 2 3 5 8 13] is not empty. The test passes.

testCase.verifyThat([1 1 2 3 5 8 13],~IsEmpty)
Verification passed.

Test a cell array of empty numeric arrays. The test fails because the cell array is not empty.

testCase.verifyThat({[],[],[]},IsEmpty)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsEmpty failed.
    --> The value must be empty.
    --> The value has a size of [1  3].
    
    Actual Value:
      1×3 cell array
    
        {0×0 double}    {0×0 double}    {0×0 double}

Test an empty test suite. The test passes.

testCase.verifyThat(TestSuite.empty,IsEmpty)
Verification passed.

Version History

Introduced in R2013a