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;

1 がクラス double のインスタンスであることを検証します。

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 で導入