matlab.unittest.constraints.IsSameHandleAs クラス
名前空間: matlab.unittest.constraints
スーパークラス: matlab.unittest.constraints.BooleanConstraint
2 つのハンドル配列が同じであるかどうかをテスト
説明
matlab.unittest.constraints.IsSameHandleAs
クラスは、ハンドル配列が別のハンドル配列と同じであるかどうかをテストするための制約を提供します。2 つのハンドル配列は、それらが同じサイズで、それらの対応する要素が同じハンドル オブジェクトをポイントしている場合に同じになります。
作成
説明
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
に代入する 2 つの 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
異なる形状の 2 つのハンドル配列が同じではないことを検証します。
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 コマンド ウィンドウに入力して実行してください。Web ブラウザーは 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)