Main Content

matlab.unittest.constraints.HasInf クラス

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

配列に無限値があるかどうかをテスト

説明

matlab.unittest.constraints.HasInf クラスは、配列に無限値があるかどうかをテストするための制約を提供します。

作成

説明

c = matlab.unittest.constraints.HasInf は、配列に無限値があるかどうかをテストするための制約を作成します。この制約は、少なくとも 1 つの無限値を含む数値配列で満たされます。

すべて折りたたむ

HasInf 制約を使用して、数値配列をテストします。

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasInf

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

testCase = TestCase.forInteractiveUse;

InfHasInf 制約を満たすことを検証します。

testCase.verifyThat(Inf,HasInf)
Verification passed.

ベクトル [1 1 2 3 5 8 13] に無限値があるかどうかをテストします。すべてのベクトル要素が有限であるため、テストは失敗します。

testCase.verifyThat([1 1 2 3 5 8 13],HasInf)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    HasInf failed.
    --> At least one element must be Inf or -Inf.
    
    Actual Value:
         1     1     2     3     5     8    13

[-Inf 5 NaN] をテストします。ベクトルに無限値が含まれているため、テストはパスします。

testCase.verifyThat([-Inf 5 NaN],HasInf)
Verification passed.

虚数部が無限である複素数が制約を満たすかどうかをテストします。テストはパスします。

testCase.verifyThat(3+1i/0,HasInf)
Verification passed.

行列 [1 NaN; -Inf 3] に無限値がないかどうかをテストします。テストは失敗します。

testCase.verifyThat([1 NaN; -Inf 3],~HasInf)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    Negated HasInf failed.
    --> All elements must be finite or NaN.
        Failing indices:
            2
    
    Actual Value:
         1   NaN
      -Inf     3

バージョン履歴

R2013a で導入