Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

matlab.unittest.constraints.IssuesWarnings クラス

名前空間: matlab.unittest.constraints
スーパークラス: matlab.unittest.constraints.Constraint

必要な警告プロファイルを発行する関数を指定する制約

説明

IssuesWarnings クラスは、必要な警告プロファイルを発行する制約を作成します。この制約は、実際の値が特定のセットの警告を発行する関数ハンドルである場合にのみ満たされます。警告識別子を使用して警告を指定します。

既定では制約が確認するのは、テスト フレームワークが関数ハンドルを呼び出す際に MATLAB® が指定された警告のセットを発行するということだけです。警告の発行回数、警告の発行順、未指定の警告が発行されたかどうかは無視します。ただし、順番、回数、警告セットを考慮に入れるようにパラメーターを設定できます。または、比較のための厳密な警告プロファイルを指定できます。

構築

outConstObj = IssuesWarnings(warnArr) は、必要な警告 warnArr を発行する関数を指定する制約 outConstObj を作成します。

outConstObj = IssuesWarnings(expVal,Name,Value) は、1 つ以上の Name,Value のペアの引数で指定された追加オプションをもつ制約を作成します。Name は一重引用符 ('') で囲まれていなければなりません。Name1,Value1,...,NameN,ValueN のように、複数の名前と値のペアの引数を任意の順番で指定できます。

入力引数

warnArr

テスト フレームワークが関数ハンドルを呼び出すときに期待される警告識別子。警告識別子の cell 配列として指定します。warnArr が空の場合は、コンストラクターが MException をスローします。

名前と値の引数

引数のオプションのペアを Name1=Value1,...,NameN=ValueN として指定します。ここで Name は引数名で、Value は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。

R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name を引用符で囲みます。

Exactly

値の関数ハンドルが、完全に一致する警告プロファイルを発行しなければならないかどうかを示すインジケーター。false または true (logical 0 または 1) として指定します。この値が false の場合、比較の精度を決定するために、インスタンスは他のパラメーターの指定と既定のインスタンスの動作に依存します。この値が true に設定されている場合、インスタンスは、警告プロファイルが指定の警告プロファイルと厳密に同一であることが必要です。

既定値: false

RespectingCount

要素カウントを考慮に入れるかどうかを示すインジケーター。false または true (logical 0 または 1) として指定します。この値が false の場合、インスタンスはメンバーの出現回数に影響されず、その頻度は無視されます。この値が true に設定されている場合、インスタンスは集合メンバーの総数に影響されます。つまり、指定されたすべての警告を確実に発行するだけでなく、特定の警告の発行回数が warnArr で指定された警告の回数と異なる場合、このインスタンスは満たされません。

既定値: false

RespectingOrder

要素の順序を考慮に入れるかどうかを示すインジケーター。false または true (logical 0 または 1) として指定します。この値が false の場合、インスタンスは集合メンバーの順序に影響されません。この値が true に設定されている場合、インスタンスは集合メンバーの順序に影響されます。つまり、発行された警告の順序が warnArr で指定された警告の順序と異なる場合、このインスタンスは満たされません。

指定された警告セットの順序は、重複した隣接警告のないプロファイルに警告プロファイルを調整することで決定されます。たとえば、警告プロファイル {id:A, id:A, id:B, id:C, id:C, id:C, id:A, id:A, id:A} {id:A, id:B, id:C, id:A} にトリミングされます。

この制約が順序を考慮に入れる場合、発行された警告および期待される警告の順序は、期待される警告プロファイルの順序に一致しなければなりません。warnArr にリストされていない警告が発行されると、順序を決定するときに無視されます。

既定値: false

RespectingSet

集合要素を考慮に入れるかどうかを示すインジケーター。false または true (logical 0 または 1) として指定します。この値が false の場合、インスタンスは追加の集合メンバーを無視します。この値が true に設定されている場合、インスタンスは追加の集合メンバーに影響されます。つまり、指定されたすべての警告を確実に発行するだけでなく、未指定の余分な警告が発行された場合もこのインスタンスは満たされません。

既定値: false

WhenNargoutIs

関数ハンドルを呼び出すときに制約が要求しなければならない出力数。非負の実数のスカラー整数として指定します。

既定値: 0

プロパティ

Exact

制約が厳密な比較を実行するかどうかを示すインジケーター。このプロパティは、名前と値のペアの引数 'Exactly' を介してコンストラクターで設定します。

ExpectedWarnings

必要な警告識別子。この読み取り専用プロパティは、入力引数 warnArr を介してコンストラクターで設定します。

FunctionOutputs

指定した関数ハンドルを呼び出したときに生成される出力引数。cell 配列として指定します。このプロパティは出力引数へのアクセスを提供します。これは読み取り専用で、テスト フレームワークが関数ハンドルを呼び出す際に設定します。出力数は、Nargout プロパティによって決定されます。

Nargout

関数を実行するときにインスタンスが使用する出力引数の数。このプロパティは、名前と値のペアの引数 'WhenNargoutIs' を介してコンストラクターで設定します。

RespectCount

制約が要素数を考慮に入れるかどうかを示すインジケーター。名前と値のペアの引数 'RespectingCount' を介してコンストラクターで指定します。

RespectOrder

制約が要素の順序を考慮に入れるかどうかを示すインジケーター。名前と値のペアの引数 'RespectingOrder' を介してコンストラクターで指定します。

RespectSet

制約が集合要素を考慮に入れるかどうかを示すインジケーター。名前と値のペアの引数 'RespectingSet' を介してコンストラクターで指定します。

コピーのセマンティクス

ハンドル。コピー操作に対するハンドル クラスの影響については、オブジェクトのコピーを参照してください。

すべて折りたたむ

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IssuesWarnings

testCase = TestCase.forInteractiveUse;

この例で使用する補助無名関数を作成します。警告識別子をいくつか作成します。

issueWarnings = @(idCell) cellfun(@(id) warning(id,'Message'), idCell);
firstID =   'first:id';
secondID =  'second:id';
thirdID =   'third:id';

補助関数が特定の警告を発行することを検証します。

testCase.verifyThat(@() issueWarnings({firstID}),...
    IssuesWarnings({firstID}))
Interactive verification passed.

関数が、回数、警告セットおよび順序を無視して警告を発行することを検証します。

testCase.verifyThat(@() issueWarnings({firstID, thirdID, secondID,...
    firstID}), IssuesWarnings({secondID, firstID}))
Interactive verification passed.

関数が警告セットに応じて警告を発行することを検証します。

testCase.verifyThat(@() issueWarnings({firstID, thirdID, secondID,...
    firstID}), IssuesWarnings({firstID, secondID, thirdID}, ...
    'RespectingSet', true))
Interactive verification passed.

関数が警告の数に応じて警告を発行することを検証します。

testCase.verifyThat(@() issueWarnings({secondID, firstID, thirdID,...
    secondID}), IssuesWarnings({firstID, secondID, secondID}, ...
    'RespectingCount', true))
Interactive verification passed.

関数が警告の順序に応じて警告を発行することを検証します。

testCase.verifyThat(@() issueWarnings({firstID, secondID, secondID,...
    thirdID}), IssuesWarnings({firstID, secondID}, 'RespectingOrder', true))
Interactive verification passed.

関数が期待される警告プロファイルと完全に一致する警告プロファイルを発行することを検証します。

testCase.verifyThat(@() issueWarnings({firstID, secondID, secondID,...
    thirdID}), IssuesWarnings({firstID, secondID, secondID, thirdID}, ...
    'Exactly', true))
Interactive verification passed.

実際の値が関数ハンドルでない場合、制約が満たされないことを検証します。

testCase.verifyThat(5, IssuesWarnings({firstID}))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IssuesWarnings failed.
--> The value must be an instance of the expected type.
    
    Actual Class:
        double
    Expected Type:
        function_handle

Actual Value:
         5

関数が警告を発行しない場合、制約が満たされないことを検証します。

testCase.verifyThat(@rand, IssuesWarnings({firstID}))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IssuesWarnings failed.
--> The function handle did not issue a correct warning profile.
    The expected warning profile ignores:
      Set
      Count
      Order
    --> The function handle did not issue any warnings.
    
    Expected Warning Profile:
        --> 'first:id'

Evaluated Function:
        @rand

関数が未指定の警告識別子を発行した場合、制約が満たされないことを検証します。

testCase.verifyThat(@() issueWarnings({firstID}), IssuesWarnings({secondID}))
Warning: Message 
> In @(id)warning(id,'Message')
  In @(idCell)cellfun(@(id)warning(id,'Message'),idCell)
  In @()issueWarnings({firstID})
  In matlab.unittest.internal.constraints.FunctionHandleConstraint/invoke (line 36)
  In matlab.unittest.internal.constraints.WarningQualificationConstraint/invoke (line 39)
  In matlab.unittest.constraints.IssuesWarnings/invoke (line 431)
  In matlab.unittest.constraints.IssuesWarnings/invokeCapturingOutput (line 510)
  In matlab.unittest.constraints.IssuesWarnings/issuesExpectedWarnings (line 519)
  In matlab.unittest.constraints.IssuesWarnings/satisfiedBy (line 239)
  In matlab.unittest.internal.qualifications.QualificationDelegate/qualifyThat (line 62)
  In matlab.unittest.qualifications.Verifiable/verifyThat (line 228) 
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IssuesWarnings failed.
--> The function handle did not issue a correct warning profile.
    The expected warning profile ignores:
      Set
      Count
      Order
    --> The function handle did not issue the correct warnings.
        
        Missing Warnings:
            --> 'second:id'
    
    Actual Warning Profile:
        --> 'first:id'
    Expected Warning Profile:
        --> 'second:id'

Evaluated Function:
        @()issueWarnings({firstID})

次の実際の値と警告配列について考えます。

actVal = @() issueWarnings({firstID, firstID, secondID, firstID});
warnArr = {firstID, secondID, firstID, firstID};

期待された配列と警告配列が完全に同一かどうかをテストします。

testCase.verifyThat(actVal, IssuesWarnings(warnArr, 'Exactly', true))
Warning: Message 
> In @(id)warning(id,'Message')
  In @(idCell)cellfun(@(id)warning(id,'Message'),idCell)
  In @()issueWarnings({firstID,firstID,secondID,firstID})
  In matlab.unittest.internal.constraints.FunctionHandleConstraint/invoke (line 36)
  In matlab.unittest.internal.constraints.WarningQualificationConstraint/invoke (line 39)
  In matlab.unittest.constraints.IssuesWarnings/invoke (line 431)
  In matlab.unittest.constraints.IssuesWarnings/invokeCapturingOutput (line 510)
  In matlab.unittest.constraints.IssuesWarnings/issuesExpectedWarnings (line 519)
  In matlab.unittest.constraints.IssuesWarnings/satisfiedBy (line 239)
  In matlab.unittest.internal.qualifications.QualificationDelegate/qualifyThat (line 62)
  In matlab.unittest.qualifications.Verifiable/verifyThat (line 228) 
Warning: Message 
> In @(id)warning(id,'Message')
  In @(idCell)cellfun(@(id)warning(id,'Message'),idCell)
  In @()issueWarnings({firstID,firstID,secondID,firstID})
  In matlab.unittest.internal.constraints.FunctionHandleConstraint/invoke (line 36)
  In matlab.unittest.internal.constraints.WarningQualificationConstraint/invoke (line 39)
  In matlab.unittest.constraints.IssuesWarnings/invoke (line 431)
  In matlab.unittest.constraints.IssuesWarnings/invokeCapturingOutput (line 510)
  In matlab.unittest.constraints.IssuesWarnings/issuesExpectedWarnings (line 519)
  In matlab.unittest.constraints.IssuesWarnings/satisfiedBy (line 239)
  In matlab.unittest.internal.qualifications.QualificationDelegate/qualifyThat (line 62)
  In matlab.unittest.qualifications.Verifiable/verifyThat (line 228) 
Warning: Message 
> In @(id)warning(id,'Message')
  In @(idCell)cellfun(@(id)warning(id,'Message'),idCell)
  In @()issueWarnings({firstID,firstID,secondID,firstID})
  In matlab.unittest.internal.constraints.FunctionHandleConstraint/invoke (line 36)
  In matlab.unittest.internal.constraints.WarningQualificationConstraint/invoke (line 39)
  In matlab.unittest.constraints.IssuesWarnings/invoke (line 431)
  In matlab.unittest.constraints.IssuesWarnings/invokeCapturingOutput (line 510)
  In matlab.unittest.constraints.IssuesWarnings/issuesExpectedWarnings (line 519)
  In matlab.unittest.constraints.IssuesWarnings/satisfiedBy (line 239)
  In matlab.unittest.internal.qualifications.QualificationDelegate/qualifyThat (line 62)
  In matlab.unittest.qualifications.Verifiable/verifyThat (line 228) 
Warning: Message 
> In @(id)warning(id,'Message')
  In @(idCell)cellfun(@(id)warning(id,'Message'),idCell)
  In @()issueWarnings({firstID,firstID,secondID,firstID})
  In matlab.unittest.internal.constraints.FunctionHandleConstraint/invoke (line 36)
  In matlab.unittest.internal.constraints.WarningQualificationConstraint/invoke (line 39)
  In matlab.unittest.constraints.IssuesWarnings/invoke (line 431)
  In matlab.unittest.constraints.IssuesWarnings/invokeCapturingOutput (line 510)
  In matlab.unittest.constraints.IssuesWarnings/issuesExpectedWarnings (line 519)
  In matlab.unittest.constraints.IssuesWarnings/satisfiedBy (line 239)
  In matlab.unittest.internal.qualifications.QualificationDelegate/qualifyThat (line 62)
  In matlab.unittest.qualifications.Verifiable/verifyThat (line 228) 
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IssuesWarnings failed.
--> The function handle did not issue a correct warning profile.
    The expected warning profile must match exactly.
    --> The function handle did not issue the exact warning profile expected.
    
    Actual Warning Profile:
        --> 'first:id'
        --> 'first:id'
        --> 'second:id'
        --> 'first:id'
    Expected Warning Profile:
        --> 'first:id'
        --> 'second:id'
        --> 'first:id'
        --> 'first:id'

Evaluated Function:
        @()issueWarnings({firstID,firstID,secondID,firstID})

期待された配列と警告配列が、セット、順序および回数を含めて同一かどうかをテストします。

testCase.verifyThat(actVal, IssuesWarnings(warnArr,...
    'RespectingSet',true,'RespectingOrder',true,'RespectingCount',true))
Interactive verification passed.

この例では、セット、順序および回数を考慮する警告プロファイルを指定する制約は、厳密な警告プロファイルを指定する制約と同一ではありません。