matlab.unittest.qualifications.Verifiable.verifyLength - Verify value has specified length - MATLAB (original) (raw)

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

Verify value has specified length

Syntax

Description

verifyLength([testCase](#bt00qkp-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Ffbde2f4e-25ca-48a4-87fb-adcd267da8fd),[expectedLength](#mw%5F40c7a19e-b737-4304-b8d3-548357b06ec2)) verifies that actual is a MATLABĀ® array with the expected length. The length of an array is defined as the length of the largest dimension of that array.

example

verifyLength([testCase](#bt00qkp-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Ffbde2f4e-25ca-48a4-87fb-adcd267da8fd),[expectedLength](#mw%5F40c7a19e-b737-4304-b8d3-548357b06ec2),[diagnostic](#mw%5F8fe3524e-d570-4c52-ae2f-87ef7df0f733)) 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 length, specified as a nonnegative integer scalar.

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

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Verify that the row vector [1 3 5] has a length of three.

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

Verify that the length of an array is the length of its largest dimension.

verifyLength(testCase,ones(2,5,3),5)

Test if the length of a 2-by-2 identity matrix is four. The test fails.

verifyLength(testCase,eye(2),4,"Value must have a length of four.")

Verification failed. ---------------- Test Diagnostic: ---------------- Value must have a length of four. --------------------- Framework Diagnostic: --------------------- verifyLength failed. --> The array has an incorrect length.

    Actual Length:
         2
    Expected Length:
         4

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

Test the length of a cell array of character vectors.

actual = {'Mercury','Gemini','Apollo'; ... 'Skylab','Skylab B','ISS'}; verifyLength(testCase,actual,3)

Tips

Version History

Introduced in R2013a