Main Content

matlab.unittest.constraints.EveryCellOf class

Package: matlab.unittest.constraints

Test if every element of cell array satisfies constraint

Description

The matlab.unittest.constraints.EveryCellOf class provides a proxy of the actual value, so you can test if every element of a cell array satisfies a given constraint. When you include the proxy in your test, the testing framework examines the constraint on an element-by-element basis.

You can use an instance of this class in tests performed with the qualification methods assertThat, assumeThat, fatalAssertThat, or verifyThat. The class does not modify the supplied actual value. It serves only as a wrapper to perform the constraint analysis.

Creation

Description

example

p = matlab.unittest.constraints.EveryCellOf(actualValue) creates a proxy to test if every element of the specified cell array satisfies a constraint and sets the ActualValue property. When you use this proxy to test against a constraint, the test passes if every element of actualValue satisfies the constraint.

Properties

expand all

Actual value to test against the constraint, returned as a value of any data type. Specify the value of this property during creation of the proxy. Even though you can specify a value of any data type, the test fails if the actual value is not a nonempty cell array.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Test if all elements of a cell array satisfy a constraint by using the EveryCellOf class.

First, import the classes used in this example.

import matlab.unittest.TestCase
import matlab.unittest.constraints.EveryCellOf
import matlab.unittest.constraints.HasElementCount
import matlab.unittest.constraints.ContainsSubstring
import matlab.unittest.constraints.IsEmpty
import matlab.unittest.constraints.IsReal

Create a test case for interactive testing.

testCase = TestCase.forInteractiveUse;

Verify that every cell of {{'hello','world'},{11,38}} contains two elements.

testCase.verifyThat(EveryCellOf({{'hello','world'},{11,38}}), ...
    HasElementCount(2))
Verification passed.

Verify that every element of the cell array {'Rain','Main','Plain'} contains the substring "ain".

testCase.verifyThat(EveryCellOf({'Rain','Main','Plain'}), ...
    ContainsSubstring("ain"))
Verification passed.

Test if every element of the cell array {struct([]),''} is empty. The test passes.

testCase.verifyThat(EveryCellOf({struct([]),''}),IsEmpty)
Verification passed.

Test if every element of the cell array {0,4i} is complex. The test fails because one of the elements is a real value.

testCase.verifyThat(EveryCellOf({0,4i}),~IsReal)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    At least one cell failed.
    
    Failing indices:
        1
    The first failing cell failed because:
    --> Negated IsReal failed.
        --> The value must not be real.
        
        Actual Value:
             0
    
    Actual Value Cell Array:
      1×2 cell array
    
        {[0]}    {[0.000000000000000 + 4.000000000000000i]}

Version History

Introduced in R2013a