Main Content

matlab.unittest.constraints.HasElementCount 클래스

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

배열에 지정된 개수의 요소가 있는지 테스트

설명

matlab.unittest.constraints.HasElementCount 클래스는 배열에 지정된 개수의 요소가 있는지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

c = matlab.unittest.constraints.HasElementCount(count)는 배열에 지정된 개수의 요소가 있는지 테스트하는 제약 조건을 만들고 Count 속성을 설정합니다. 이 제약 조건은 배열 요소 개수가 count와 같은 경우에 충족됩니다.

속성

모두 확장

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

특성:

GetAccess
public
SetAccess
private

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

예제

모두 축소

HasElementCount 제약 조건을 사용하여 배열 요소의 개수를 테스트합니다.

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasElementCount

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

testCase = TestCase.forInteractiveUse;

스칼라의 요소 개수가 1개인지 확인합니다.

testCase.verifyThat(3,HasElementCount(1))
Verification passed.

행렬 [1 2 3; 4 5 6]에 세 개의 요소가 없는지 확인합니다.

testCase.verifyThat([1 2 3; 4 5 6],~HasElementCount(3))
Verification passed.

단위 행렬에 예상되는 개수의 요소가 있는지 확인합니다.

n = 7;
testCase.verifyThat(eye(n),HasElementCount(n^2))
Verification passed.

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

C = {'Mercury','Gemini','Apollo'};
testCase.verifyThat(C,HasElementCount(3))
Verification passed.

두 개의 필드가 있는 스칼라 구조체의 요소 개수를 테스트합니다. 구조체에 요소가 하나만 있으므로 테스트가 실패합니다.

s.field1 = 1;
s.field2 = zeros(1,10);
testCase.verifyThat(s,HasElementCount(2))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    HasElementCount failed.
    --> The value did not have the correct number of elements.
        
        Actual Number of Elements:
             1
        Expected Number of Elements:
             2
    
    Actual Value:
      struct with fields:
    
        field1: 1
        field2: [0 0 0 0 0 0 0 0 0 0]

버전 내역

R2013a에 개발됨