Main Content

matlab.unittest.constraints.HasField 클래스

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

구조체형 배열에 지정된 필드가 있는지 테스트

설명

matlab.unittest.constraints.HasField 클래스는 값이 지정된 필드를 갖는 구조체형 배열인지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

c = matlab.unittest.constraints.HasField(field)는 값이 지정된 필드를 갖는 구조체형 배열인지 테스트하는 제약 조건을 만들고 Field 속성을 설정합니다. 이 제약 조건은 구조체형 배열이 field라는 필드를 가지는 경우 충족됩니다.

속성

모두 확장

예상 필드의 이름으로, 문자형 벡터로 반환됩니다. 제약 조건을 생성할 때 이 속성의 값을 string형 스칼라 또는 문자형 벡터로 지정합니다.

특성:

GetAccess
public
SetAccess
private

예제

모두 축소

HasField 제약 조건을 사용하여 구조체를 테스트합니다.

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasField

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

testCase = TestCase.forInteractiveUse;

두 개의 필드를 갖는 구조체를 만듭니다.

s = struct("ID",10,"score",90);

s"ID" 필드를 포함하는 구조체인지 확인합니다.

testCase.verifyThat(s,HasField("ID"))
Verification passed.

구조체에 "Score" 필드가 있는지 테스트합니다. 필드 이름 비교가 대/소문자를 구분하기 때문에 테스트가 실패합니다.

testCase.verifyThat(s,HasField("Score"))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    HasField failed.
    --> The value did not have the expected field.
        
        Actual Fieldnames:
                'ID'
                'score'
        Expected Fieldname:
                'Score'
    
    Actual Value:
      struct with fields:
    
           ID: 10
        score: 90

구조체에 "ID" 필드와 "score" 필드가 모두 있는지 테스트합니다. 테스트가 통과합니다.

testCase.verifyThat(s,HasField("ID") & HasField("score"))
Verification passed.

구조체에 "Name" 필드가 없는지 확인합니다.

testCase.verifyThat(s,~HasField("Name"))
Verification passed.

버전 내역

R2013b에 개발됨

참고 항목

도움말 항목