matlab.unittest.constraints.AnyCellOf class

Package: matlab.unittest.constraints

Test if any element of cell array meets constraint

Description

The AnyCellOf class creates a proxy of the actual value to the framework. The proxy enables a test writer to apply a constraint against each element of a cell array, which ensures that a passing result occurs if at least one element of the cell array satisfies the constraint.

It is intended that you use this class through matlab.unittest qualifications as shown in the examples. The class does not modify the provided actual value, but serves as a wrapper to perform the constraint analysis. The testing framework analyzes the constraint on an element-by-element basis.

Construction

AnyCellOf(actVal) creates a proxy instance that tests if any element of a provided cell array, actVal, meets a constraint. The test passes if at least one element individually satisfies the constraint.

Input Arguments

actVal

Actual value to test against constraint

Properties

ActualValue

Actual value to test against constraint. Set this property through the constructor via the actVal 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.AnyCellOf

testCase = TestCase.forInteractiveUse;

Test that at least one cell of actVal is finite.

import matlab.unittest.constraints.IsFinite
actVal = {NaN, Inf, 5};
testCase.verifyThat(AnyCellOf(actVal), IsFinite)
Interactive verification passed.

Test that at least one cell of the actual value contains five elements.

import matlab.unittest.constraints.HasElementCount
testCase.verifyThat(AnyCellOf({42, [11 38], 1:5}), HasElementCount(5))
Interactive verification passed.

Test that at least one cell of the actual value matches 'tea' regardless of case.

import matlab.unittest.constraints.Matches
testCase.verifyThat(AnyCellOf({'Coffee','Tea','Water'}), ...
    Matches('tea','IgnoringCase',true))
Interactive verification passed.

Test that at least one cell of the actual value is less than zero.

import matlab.unittest.constraints.IsLessThan
testCase.verifyThat(AnyCellOf({1, 5}), IsLessThan(0))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
All cells failed. The first cell failed because:
--> IsLessThan failed.
    --> The value must be less than the maximum value.
    
    Actual double:
             1
    Maximum Value (Exclusive):
             0

Actual Value Cell Array:
        [1]    [5]

Neither actual value element is less than zero.

Test that neither cell of the actual value is empty.

import matlab.unittest.constraints.IsEmpty
testCase.verifyThat(AnyCellOf({inputParser.empty,''}), ~IsEmpty)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
All cells failed. The first cell failed because:
--> Negated IsEmpty failed.
    --> The value must not be empty.
    --> The value has a size of [0  0].
    
    Actual inputParser:
          0x0 inputParser array with properties:
        
            FunctionName
            CaseSensitive
            KeepUnmatched
            PartialMatching
            StructExpand
            Parameters
            Results
            Unmatched
            UsingDefaults

Actual Value Cell Array:
        [0x0 inputParser]    ''

Both actual value elements are empty.