Main Content

matlab.unittest.constraints.HasSize 클래스

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

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

설명

matlab.unittest.constraints.HasSize 클래스는 배열이 지정된 크기를 갖는지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

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

속성

모두 확장

예상 배열 크기로, 음이 아닌 정수로 구성된 행 벡터로 반환됩니다. 제약 조건을 생성할 때 이 속성의 값을 지정합니다.

특성:

GetAccess
public
SetAccess
private

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

예제

모두 축소

HasSize 제약 조건을 사용하여 배열 크기를 테스트합니다.

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasSize

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

testCase = TestCase.forInteractiveUse;

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

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

2×5×3 배열의 크기를 테스트합니다. 테스트가 통과합니다.

testCase.verifyThat(rand(2,5,3),HasSize([2 5 3]))
Verification passed.

2×2 행렬의 크기가 [2 2]가 아닌지 테스트합니다. 테스트가 실패합니다.

testCase.verifyThat(eye(2),~HasSize([2 2]))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    Negated HasSize failed.
    --> The value must not have the size specified.
    
    Actual Value:
         1     0
         0     1
    Prohibited Size:
         2     2

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

C = {'Mercury','Gemini','Apollo'};
testCase.verifyThat(C,HasSize([1 3]))
Verification passed.

버전 내역

R2013a에 개발됨