Main Content

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

matlab.unittest.constraints.HasUniqueElements クラス

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

セットに一意の要素が含まれているかどうかのテスト

構築

HasUniqueElements は、一意の要素を含むセットを指定する制約を作成します。この制約は、実際の値のセットに一意の要素が含まれない場合に検定エラーを生成します。numel(unique(actualSet))numel(actualSet) に等しい場合、制約は実際の値セットが一意の要素をもつと見なします。

コピーのセマンティクス

値。値クラスがコピー操作に与える影響については、オブジェクトのコピーを参照してください。

すべて折りたたむ

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

import matlab.unittest.TestCase;
import matlab.unittest.constraints.HasUniqueElements;

testCase = TestCase.forInteractiveUse;

'abc''Mississippi' が一意の要素をもつかどうかをテストします。

testCase.verifyThat('abc', HasUniqueElements);
Interactive verification passed.
testCase.verifyThat('Mississippi', HasUniqueElements);
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
HasUniqueElements failed.
--> The value contains 3 nonunique element(s):
    --> Nonunique element found at indices [2 5 8 11]:
            i
    --> Nonunique element found at indices [9 10]:
            p
    --> Nonunique element found at indices [3 4 6 7]:
            s

Actual char:
    Mississippi

double のセットが一意の要素をもつことをアサートします。

testCase.assertThat(magic(6), HasUniqueElements);
Interactive assertion passed.
testCase.assertThat(abs(-3:3), HasUniqueElements);
Interactive assertion failed.

---------------------
Framework Diagnostic:
---------------------
HasUniqueElements failed.
--> The value contains 3 nonunique element(s):
    --> Nonunique element found at indices [3 5]:
                 1
    --> Nonunique element found at indices [2 6]:
                 2
    --> Nonunique element found at indices [1 7]:
                 3

Actual double:
         3     2     1     0     1     2     3
Assertion failed.

cell 配列が一意の要素をもつことを検証します。

testCase.verifyThat({'abc','123';'abc','345'},HasUniqueElements);
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
HasUniqueElements failed.
--> The value contains 1 nonunique element(s):
    --> Nonunique element found at indices [1 2]:
                'abc'

Actual cell:
        'abc'    '123'
        'abc'    '345'

テーブルが一意の行をもつことをアサートします。

t = table([3;3;5],{'A';'C';'E'},logical([1;0;0]));
testCase.assertThat(t,HasUniqueElements);
Interactive assertion passed.

バージョン履歴

R2016a で導入