Main Content

matlab.unittest.constraints.IsSameHandleAs 클래스

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

두 핸들 배열이 동일한지 테스트

설명

matlab.unittest.constraints.IsSameHandleAs 클래스는 핸들 배열이 또 다른 핸들 배열과 동일한지 테스트하는 제약 조건을 제공합니다. 두 핸들 배열은 크기가 같고 그에 대응하는 요소가 같은 핸들 객체를 가리키는 경우에 동일합니다.

생성

설명

예제

c = matlab.unittest.constraints.IsSameHandleAs(expectedHandle)은 핸들 배열이 예상 핸들 배열과 동일한지 테스트하는 제약 조건을 만들고 ExpectedHandle 속성을 설정합니다. 이 제약 조건은 핸들 배열과 expectedHandle이 크기가 같고 그에 대응하는 요소가 같은 핸들 객체를 가리키는 경우 충족됩니다.

속성

모두 확장

예상 값으로, 핸들 배열로 반환됩니다. 제약 조건을 생성할 때 이 속성의 값을 지정합니다.

특성:

GetAccess
public
SetAccess
private

예제

모두 축소

IsSameHandleAs 제약 조건을 사용하여 핸들 배열을 비교합니다.

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

classdef ExampleHandle < handle
    properties
        Number = 1;
    end
end

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsSameHandleAs

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

testCase = TestCase.forInteractiveUse;

변수 h1h2에 할당된 ExampleHandle 객체를 두 개 만듭니다. 그런 다음 h2의 값을 다른 변수 h3에 할당합니다. 변수 h1h2는 서로 다른 객체를 가리키지만, 변수 h2h3은 같은 객체를 가리킵니다.

h1 = ExampleHandle;
h2 = ExampleHandle;
h3 = h2;

h1h2가 같은 객체를 가리키는지 테스트합니다. 테스트가 실패합니다.

testCase.verifyThat(h1,IsSameHandleAs(h2))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsSameHandleAs failed.
    --> Values do not refer to the same handle.
    
    Actual Value:
      ExampleHandle with properties:
    
        Number: 1
    Expected Handle Object:
      ExampleHandle with properties:
    
        Number: 1

h2h3이 같은 객체를 가리키는지 확인합니다.

testCase.verifyThat(h2,IsSameHandleAs(h3))
Verification passed.

[h2 h3][h3 h2]가 동일한지 테스트합니다. 대응하는 벡터 요소가 같은 객체를 가리키므로 테스트가 통과합니다.

testCase.verifyThat([h2 h3],IsSameHandleAs([h3 h2]))
Verification passed.

[h1 h2][h2 h1]이 동일한지 테스트합니다. 대응하는 벡터 요소가 다른 객체를 가리키므로 테스트가 실패합니다.

testCase.verifyThat([h1 h2],IsSameHandleAs([h2 h1]))
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsSameHandleAs failed.
    --> Some elements in the handle array refer to the wrong handle.
    
    Actual Value:
      1×2 ExampleHandle array with properties:
    
        Number
    Expected Handle Object:
      1×2 ExampleHandle array with properties:
    
        Number

모양이 다른 두 핸들 배열이 동일하지 않은지 확인합니다.

testCase.verifyThat([h1 h1 h2 h3],~IsSameHandleAs([h1 h1; h2 h3]))
Verification passed.

버전 내역

R2013a에 개발됨

모두 확장