Main Content

matlab.unittest.constraints.AnyCellOf クラス

名前空間: matlab.unittest.constraints

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

説明

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

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

作成

説明

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

プロパティ

すべて展開する

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

属性:

GetAccess
public
SetAccess
private

すべて折りたたむ

AnyCellOf クラスを使用して、cell 配列の少なくとも 1 つの要素が制約を満たしているかどうかをテストします。

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.AnyCellOf
import matlab.unittest.constraints.HasElementCount
import matlab.unittest.constraints.IsFinite
import matlab.unittest.constraints.IsLessThan
import matlab.unittest.constraints.Matches
import matlab.unittest.constraints.IsEmpty

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

testCase = TestCase.forInteractiveUse;

{42,[11 38],1:5} の少なくとも 1 つの cell に 5 つの要素が含まれていることを検証します。

testCase.verifyThat(AnyCellOf({42,[11 38],1:5}),HasElementCount(5))
Verification passed.

cell 配列 {NaN,Inf,5} の少なくとも 1 つの要素が有限であることを検証します。

testCase.verifyThat(AnyCellOf({NaN,Inf,5}),IsFinite)
Verification passed.

cell 配列 {-1,5} の少なくとも 1 つの要素が負であることを検証します。

testCase.verifyThat(AnyCellOf({-1,5}),IsLessThan(0))
Verification passed.

cell 配列 {'Coffee','Tea','Water'} の少なくとも 1 つの要素が大文字と小文字を区別せずに "tea" と一致するかどうかをテストします。テストはパスします。

testCase.verifyThat(AnyCellOf({'Coffee','Tea','Water'}), ...
    Matches("tea","IgnoringCase",true))
Verification passed.

cell 配列 {struct([]),''} の少なくとも 1 つの要素が空でないかどうかをテストします。両方の要素が空であるため、テストは失敗します。

testCase.verifyThat(AnyCellOf({struct([]),''}),~IsEmpty)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    All cells failed. The first cell failed because:
    --> Negated IsEmpty failed.
        --> The value must not be empty.
        --> The value has a size of [0  0].
        
        Actual Value:
          0×0 empty struct array with no fields.
    
    Actual Value Cell Array:
      1×2 cell array
    
        {0×0 struct}    {0×0 char}

バージョン履歴

R2013a で導入