Main Content

matlab.unittest.constraints.EveryCellOf クラス

名前空間: matlab.unittest.constraints

cell 配列のすべての要素が制約を満たしているかどうかをテスト

説明

matlab.unittest.constraints.EveryCellOf クラスは、cell 配列のすべての要素が特定の制約を満たしているかどうかをテストするために使用できる実際の値のプロキシを提供します。テストにプロキシを含めると、テスト フレームワークにおいて要素単位で制約が調べられます。

このクラスのインスタンスは、検定メソッド assertThatassumeThatfatalAssertThat、または verifyThat を使用して実行されるテストで使用できます。このクラスでは、与えられた実際の値は変更されません。制約の解析を実行するラッパーとしてのみ機能します。

作成

説明

p = matlab.unittest.constraints.EveryCellOf(actualValue) は、指定された cell 配列のすべての要素が制約を満たしているかどうかをテストするためのプロキシを作成し、ActualValue プロパティを設定します。このプロキシを使用して制約についてテストすると、actualValue のすべての要素が制約を満たしている場合にテストにパスします。

プロパティ

すべて展開する

制約に対してテストする実際の値。任意のデータ型の値として返されます。このプロパティの値は、プロキシの作成時に指定します。任意のデータ型の値を指定できますが、実際の値が空でない cell 配列でないとテストは失敗します。

属性:

GetAccess
public
SetAccess
private

すべて折りたたむ

EveryCellOf クラスを使用して、cell 配列のすべての要素が制約を満たしているかどうかをテストします。

最初に、この例で使用するクラスをインポートします。

import matlab.unittest.TestCase
import matlab.unittest.constraints.EveryCellOf
import matlab.unittest.constraints.HasElementCount
import matlab.unittest.constraints.ContainsSubstring
import matlab.unittest.constraints.IsEmpty
import matlab.unittest.constraints.IsReal

対話型テスト用にテスト ケースを作成します。

testCase = TestCase.forInteractiveUse;

{{'hello','world'},{11,38}} のすべての cell に 2 つの要素が格納されていることを検証します。

testCase.verifyThat(EveryCellOf({{'hello','world'},{11,38}}), ...
    HasElementCount(2))
Verification passed.

cell 配列 {'Rain','Main','Plain'} のすべての要素に部分文字列 "ain" が含まれていることを検証します。

testCase.verifyThat(EveryCellOf({'Rain','Main','Plain'}), ...
    ContainsSubstring("ain"))
Verification passed.

cell 配列 {struct([]),''} のすべての要素が空であるかどうかをテストします。テストはパスします。

testCase.verifyThat(EveryCellOf({struct([]),''}),IsEmpty)
Verification passed.

cell 配列 {0,4i} のすべての要素が複素数であるかどうかをテストします。要素の 1 つが実数値であるため、テストは失敗します。

testCase.verifyThat(EveryCellOf({0,4i}),~IsReal)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    At least one cell failed.
    
    Failing indices:
        1
    The first failing cell failed because:
    --> Negated IsReal failed.
        --> The value must not be real.
        
        Actual Value:
             0
    
    Actual Value Cell Array:
      1×2 cell array
    
        {[0]}    {[0.000000000000000 + 4.000000000000000i]}

バージョン履歴

R2013a で導入