This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.unittest.constraints.HasSize class

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

Constraint specifying expected size of array


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


Size a value must have to satisfy the constraint.



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.


expand 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.

Was this topic helpful?