Main Content

matlab.unittest.constraints.IsInstanceOf 클래스

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

값이 지정된 클래스의 인스턴스인지 테스트

설명

matlab.unittest.constraints.IsInstanceOf 클래스는 값이 지정된 클래스의 인스턴스인지 테스트하는 제약 조건을 제공합니다.

IsInstanceOf 제약 조건은 클래스 계층 구조에 포함되는지 여부를 테스트합니다. 클래스가 정확하게 일치하는지 테스트하려면 IsOfClass 제약 조건을 사용하십시오.

생성

설명

예제

c = matlab.unittest.constraints.IsInstanceOf(class)는 값이 class의 인스턴스인지 테스트하는 제약 조건을 만들고 Class 속성을 설정합니다. 이 제약 조건은 값이 class의 인스턴스이거나 class에서 파생되는 경우 충족됩니다.

속성

모두 확장

예상 클래스로, 문자형 벡터로 반환됩니다. 제약 조건을 생성할 때 이 속성의 값을 string형 스칼라, 문자형 벡터 또는 matlab.metadata.Class 인스턴스로 지정합니다.

특성:

GetAccess
public
SetAccess
private

예제

모두 축소

IsInstanceOf 제약 조건을 사용하여 숫자형 값을 테스트합니다.

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsInstanceOf

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

testCase = TestCase.forInteractiveUse;

1double 클래스의 인스턴스인지 확인합니다.

testCase.verifyThat(1,IsInstanceOf("double"))
Verification passed.

string형 대신 matlab.metadata.Class 인스턴스를 사용하여 테스트를 반복합니다.

testCase.verifyThat(1,IsInstanceOf(?double))
Verification passed.

숫자형 값이 logical 클래스의 인스턴스가 아닌지 확인합니다.

testCase.verifyThat(1,~IsInstanceOf("logical"))
Verification passed.

IsInstanceOf 제약 조건을 사용하여 함수 핸들을 테스트합니다.

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsInstanceOf

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

testCase = TestCase.forInteractiveUse;

@sin이 함수 핸들인지 확인합니다.

testCase.verifyThat(@sin,IsInstanceOf(?function_handle))
Verification passed.

함수 이름 "sin"을 사용하여 테스트를 반복합니다. 테스트가 실패합니다.

testCase.verifyThat("sin",IsInstanceOf(?function_handle))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsInstanceOf failed.
    --> The value must be an instance of the expected type.
        
        Actual Class:
            string
        Expected Type:
            function_handle
    
    Actual Value:
        "sin"

IsInstanceOf 제약 조건을 사용하여 파생된 클래스의 인스턴스를 테스트합니다.

현재 폴더에 있는 파일에서 ExampleHandle 핸들 클래스를 만듭니다.

classdef ExampleHandle < handle
    properties
        Number = 1;
    end
end

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsInstanceOf

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

testCase = TestCase.forInteractiveUse;

IsInstanceOf 제약 조건을 사용하여 ExampleHandle 클래스의 인스턴스를 테스트합니다. 테스트가 통과합니다.

actual = ExampleHandle;
testCase.verifyThat(actual,IsInstanceOf(?ExampleHandle))
Verification passed.

actual도 핸들 클래스의 인스턴스인지 테스트합니다. ExampleHandle은 핸들 클래스에서 파생되므로 테스트가 통과합니다.

testCase.verifyThat(actual,IsInstanceOf(?handle))
Verification passed.

버전 내역

R2013a에 개발됨