matlab.unittest.qualifications.Verifiable.verifySize - Verify value has specified size - MATLAB (original) (raw)

Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications

Verify value has specified size

Syntax

Description

verifySize([testCase](#bt00res-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Fc4c3cc41-6d7f-4804-8449-ac4c685aa531),[expectedSize](#mw%5F1e4e3bbf-60be-4dae-ba06-f022ea718e57)) verifies that actual is a MATLABĀ® array with the expected size.

example

verifySize([testCase](#bt00res-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Fc4c3cc41-6d7f-4804-8449-ac4c685aa531),[expectedSize](#mw%5F1e4e3bbf-60be-4dae-ba06-f022ea718e57),[diagnostic](#mw%5F2bf4aaee-3634-4f2b-a842-6f7a19450b01)) also associates the diagnostic information in diagnostic with the qualification.

example

Input Arguments

expand all

Test case, specified as a matlab.unittest.qualifications.Verifiable object. Because the matlab.unittest.TestCase class subclasses matlab.unittest.qualifications.Verifiable and inherits its methods, testCase is typically amatlab.unittest.TestCase object.

Value to test, specified as an array of any data type.

Expected array size, specified as a row vector of nonnegative integers. Each element of expectedSize represents the expected length of the corresponding dimension of actual.

Diagnostic information to display when the qualification passes or fails, specified as a string array, character array, function handle, or array of matlab.automation.diagnostics.Diagnostic objects.

Depending on the test runner configuration, the testing framework can display diagnostics when the qualification passes or fails. By default, the framework displays diagnostics only when the qualification fails. You can override the default behavior by customizing the test runner. For example, use a DiagnosticsOutputPlugin instance to display both failing and passing event diagnostics.

Example: "My Custom Diagnostic"

Example: @dir

Examples

expand all

Test if the actual value has the specified size.

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Verify that the size of the row vector [1 3 5] is [1 3].

verifySize(testCase,[1 3 5],[1 3])

Test the size of a 2-by-5-by-3 array.

verifySize(testCase,rand(2,5,3),[2 5 3])

Test if the size of a 2-by-2 matrix is [4 1]. The test fails.

verifySize(testCase,eye(2),[4 1],"Value must be a 4-by-1 vector.")

Verification failed. ---------------- Test Diagnostic: ---------------- Value must be a 4-by-1 vector. --------------------- Framework Diagnostic: --------------------- verifySize failed. --> The value had an incorrect size.

    Actual Size:
         2     2
    Expected Size:
         4     1

Actual Value:
     1     0
     0     1
------------------
Stack Information:
------------------
In C:\work\TestForArraySizesExample.m (TestForArraySizesExample) at 21

Test the size of a cell array of character vectors.

actual = {'Mercury','Gemini','Apollo'}; verifySize(testCase,actual,[1 3])

Tips

Version History

Introduced in R2013a