matlab.unittest.constraints.HasSize class

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

Constraint specifying expected size of array

Construction

HasSize(sizeVal) provides a constraint that specifies an expected size of an array. The constraint is satisfied if the actual value array size is equal to the size specified by sizeVal.

Input Arguments

sizeVal

Size a value must have to satisfy the constraint.

Properties

Size

Size a value must have to satisfy the constraint. Set this property through the constructor via the sizeVal 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.HasSize

testCase = TestCase.forInteractiveUse;

Assert that a 2x5x3 array has an expected size.

testCase.assertThat(rand(2, 5, 3), HasSize([2 5 3]))
Interactive assertion passed.

Verify that a cell array of character vectors has an expected size.

testCase.verifyThat({'SomeText', 'SomeOtherText'}, HasSize([1 2]))
Interactive verification passed.

Verify that an identity matrix has an expected size.

testCase.verifyThat(eye(2), HasSize([4 1]))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
HasSize failed.
--> The value had an incorrect size.
    
    Actual Size:
             2     2
    Expected Size:
             4     1

Actual Value:
         1     0
         0     1

The matrix has a size of 2x2.