Main Content

matlab.unittest.constraints.IsScalar クラス

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

値がスカラーであるかどうかをテスト

説明

matlab.unittest.constraints.IsScalar クラスは、値がスカラーであるかどうかをテストするための制約を提供します。

作成

説明

c = matlab.unittest.constraints.IsScalar は、値がスカラーであるかどうかをテストするための制約を作成します。この制約は、1 行 1 列の配列で満たされます。

すべて折りたたむ

IsScalar 制約を使用して、値をテストします。

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsScalar

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

testCase = TestCase.forInteractiveUse;

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

testCase.verifyThat(1,IsScalar)
Verification passed.

ベクトル [1 1 2 3 5 8 13] が制約を満たすかどうかをテストします。テストは失敗します。

testCase.verifyThat([1 1 2 3 5 8 13],IsScalar)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsScalar failed.
    --> The value must be a scalar.
    --> The value has a size of [1  7].
    
    Actual Value:
         1     1     2     3     5     8    13

"Hello, World!" をテストします。値が string スカラーであるため、テストはパスします。

testCase.verifyThat("Hello, World!",IsScalar)
Verification passed.

空の構造体をテストします。値が 1 行 1 列の配列でないため、テストは失敗します。

testCase.verifyThat(struct([]),IsScalar)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsScalar failed.
    --> The value must be a scalar.
    --> The value has a size of [0  0].
    
    Actual Value:
      0×0 empty struct array with no fields.

バージョン履歴

R2014b で導入