Main Content

matlab.unittest.constraints.HasLength 클래스

네임스페이스: matlab.unittest.constraints
슈퍼클래스: matlab.unittest.constraints.BooleanConstraint

배열이 지정된 길이를 갖는지 테스트

설명

matlab.unittest.constraints.HasLength 클래스는 배열이 지정된 길이를 갖는지 테스트하는 제약 조건을 제공합니다. 배열의 길이는 해당 배열에서 가장 큰 차원의 길이로 정의됩니다.

생성

설명

예제

c = matlab.unittest.constraints.HasLength(length)는 배열이 지정된 길이를 갖는지 테스트하는 제약 조건을 만들고 Length 속성을 설정합니다. 이 제약 조건은 배열 길이가 length와 같은 경우 충족됩니다.

속성

모두 확장

예상 배열 길이로, 음이 아닌 정수 스칼라로 반환됩니다. 제약 조건을 생성할 때 이 속성의 값을 지정합니다.

특성:

GetAccess
public
SetAccess
private

데이터형: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

예제

모두 축소

HasLength 제약 조건을 사용하여 배열 길이를 테스트합니다.

먼저 이 예제에서 사용되는 클래스를 가져옵니다.

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasLength

대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.

testCase = TestCase.forInteractiveUse;

행 벡터 [1 3 5]의 길이가 3인지 확인합니다.

testCase.verifyThat([1 3 5],HasLength(3))
Verification passed.

배열의 길이가 해당 배열에서 가장 큰 차원의 길이인지 확인합니다.

testCase.verifyThat(ones(2,5,3),HasLength(5))
Verification passed.

2×2 단위 행렬의 길이가 2가 아닌지 테스트합니다. 테스트가 실패합니다.

testCase.verifyThat(eye(2),~HasLength(2))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    Negated HasLength failed.
    --> The array must not have the specified length.
    
    Actual Value:
         1     0
         0     1
    Prohibited Length:
         2

문자형 벡터로 구성된 셀형 배열의 길이를 테스트합니다. 테스트가 통과합니다.

C = {'Mercury','Gemini','Apollo'; 'Skylab','Skylab B','ISS'};
testCase.verifyThat(C,HasLength(3))
Verification passed.

버전 내역

R2013a에 개발됨