matlab.unittest.constraints.IsSameHandleAs 클래스
네임스페이스: matlab.unittest.constraints
슈퍼클래스: matlab.unittest.constraints.BooleanConstraint
두 핸들 배열이 동일한지 테스트
설명
matlab.unittest.constraints.IsSameHandleAs
클래스는 핸들 배열이 또 다른 핸들 배열과 동일한지 테스트하는 제약 조건을 제공합니다. 두 핸들 배열은 크기가 같고 그에 대응하는 요소가 같은 핸들 객체를 가리키는 경우에 동일합니다.
생성
설명
c = matlab.unittest.constraints.IsSameHandleAs(expectedHandle)
은 핸들 배열이 예상 핸들 배열과 동일한지 테스트하는 제약 조건을 만들고 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;
변수 h1
및 h2
에 할당된 ExampleHandle
객체를 두 개 만듭니다. 그런 다음 h2
의 값을 다른 변수 h3
에 할당합니다. 변수 h1
및 h2
는 서로 다른 객체를 가리키지만, 변수 h2
및 h3
은 같은 객체를 가리킵니다.
h1 = ExampleHandle; h2 = ExampleHandle; h3 = h2;
h1
및 h2
가 같은 객체를 가리키는지 테스트합니다. 테스트가 실패합니다.
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
h2
및 h3
이 같은 객체를 가리키는지 확인합니다.
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에 개발됨R2019b: 텍스트 값이 더 이상 열거형과 동등하지 않음
가설 검정에서 텍스트 값은 더 이상 핸들 클래스의 열거형과 동등하지 않습니다. 예를 들어 다음 열거형 클래스를 살펴보십시오.
classdef MyClass < handle enumeration X Y end end
"X"
가 열거형 MyClass.X
를 나타내지 않으므로 이 테스트는 실패합니다. 이전 릴리스에서는 이 테스트가 통과합니다.
import matlab.unittest.TestCase import matlab.unittest.constraints.IsSameHandleAs testCase = TestCase.forInteractiveUse; testCase.verifyThat("X",IsSameHandleAs(MyClass.X))
Verification failed. --------------------- Framework Diagnostic: --------------------- IsSameHandleAs failed. --> Values do not refer to the same handle. --> Value must be a handle object. It is of class "string". --> Classes do not match. Actual Value class : [string] Expected Handle Object class : [MyClass] Actual Value: "X" Expected Handle Object: MyClass enumeration X
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)