matlab.unittest.constraints.IsSubstringOf クラス
パッケージ: matlab.unittest.constraints
スーパークラス: matlab.unittest.constraints.BooleanConstraint
値が指定の文字列の部分文字列であるかどうかをテスト
説明
matlab.unittest.constraints.IsSubstringOf
クラスは、値が指定の文字列の部分文字列であるかどうかをテストするための制約を提供します。
作成
説明
c = matlab.unittest.constraints.IsSubstringOf(
は、値が指定の文字列の部分文字列であるかどうかをテストするための制約を作成します。この制約は、superstring
)superstring
に出現する string スカラーまたは文字ベクトルで満たされます。
c = matlab.unittest.constraints.IsSubstringOf(
は、1 つ以上の名前と値の引数を使用して追加のオプションを設定します。たとえば、superstring
,Name,Value
)c = matlab.unittest.constraints.IsSubstringOf(superstring,"IgnoringCase",true)
は大文字と小文字を区別しない制約を作成します。
入力引数
superstring
— 期待される上位文字列
string スカラー | 文字ベクトル
期待される上位文字列。空でない string スカラーまたは文字ベクトルとして指定します。
この引数は Superstring
プロパティを設定します。
引数のオプションのペアを Name1=Value1,...,NameN=ValueN
として指定します。ここで Name
は引数名で、Value
は対応する値です。名前と値の引数は他の引数の後になければなりませんが、ペアの順序は重要ではありません。
例: c = matlab.unittest.constraints.IsSubstringOf(superstring,IgnoringCase=true)
R2021a より前では、コンマを使用してそれぞれの名前と値を区切り、Name
を引用符で囲みます。
例: c = matlab.unittest.constraints.IsSubstringOf(superstring,"IgnoringCase",true)
IgnoringCase
— 大文字小文字の区別を無視するかどうか
false
または 0
(既定値) | true
または 1
大文字小文字の区別を無視するかどうか。数値または logical 0
(false
) または 1
(true
) として指定します。既定では、制約で大文字と小文字が区別されます。
この引数は IgnoreCase
プロパティを設定します。
IgnoringWhitespace
— 空白を無視するかどうか
false
または 0
(既定値) | true
または 1
空白を無視するかどうか。数値または logical 0
(false
) または 1
(true
) として指定します。既定では、制約で空白文字が区別されます。空白文字は、スペース (' '
)、フォーム フィード ('\f'
)、改行 ('\n'
)、キャリッジ リターン ('\r'
)、水平タブ ('\t'
)、垂直タブ ('\v'
) です。
この引数は IgnoreWhitespace
プロパティを設定します。
メモ
IgnoringWhitespace
が true
の場合、superstring
に空白以外の文字が少なくとも 1 つ含まれていなければなりません。
WithCount
— テストする値の必要な出現回数
正の整数スカラー
テストする値の superstring
での必要な出現回数。正の整数スカラーとして指定します。
この名前と値の引数を指定して、部分文字列のオーバーラップしない出現のみをカウントできます。たとえば、次のテストは失敗します。
import matlab.unittest.TestCase import matlab.unittest.constraints.IsSubstringOf testCase = TestCase.forInteractiveUse; testCase.verifyThat("aba",IsSubstringOf("ababa","WithCount",2))
テスト フレームワークでは、テストする値の出現回数を関数 count
を使用してカウントします。テストする値が空の文字列である場合、関数 count
は、superstring
の先頭と末尾、およびすべての文字と文字の間にある空の文字列をカウントします。つまり、superstring
に n 個の文字がある場合は、n+1 個の空の部分文字列があることになります。
データ型: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
プロパティ
Superstring
— 期待される上位文字列
string スカラー | 文字ベクトル
期待される上位文字列。string スカラーまたは文字ベクトルとして返されます。
このプロパティは入力引数 superstring
によって設定されます。
属性:
GetAccess | public |
SetAccess | immutable |
IgnoreCase
— 大文字小文字の区別を無視するかどうか
false
または 0
(既定値) | true
または 1
大文字小文字の区別を無視するかどうか。logical 0
(false
) または 1
(true
) として返されます。既定では、制約で大文字と小文字が区別されます。
このプロパティは名前と値の引数 IgnoringCase
によって設定されます。
属性:
GetAccess | public |
SetAccess | private |
IgnoreWhitespace
— 空白を無視するかどうか
false
または 0
(既定値) | true
または 1
空白を無視するかどうか。logical 0
(false
) または 1
(true
) として返されます。既定では、制約で空白文字が区別されます。
このプロパティは名前と値の引数 IgnoringWhitespace
によって設定されます。
属性:
GetAccess | public |
SetAccess | private |
例
値が指定の文字列の部分文字列であるかどうかをテスト
IsSubstringOf
制約を使用して、部分文字列の出現についてテストします。
最初に、この例で使用するクラスをインポートします。
import matlab.unittest.TestCase import matlab.unittest.constraints.IsSubstringOf
対話型テスト用にテスト ケースを作成します。
testCase = TestCase.forInteractiveUse;
期待される上位文字列を指定します。
str = "This Is One Long Message!";
値 "One"
が str
の部分文字列であることを検証します。
testCase.verifyThat("One",IsSubstringOf(str))
Verification passed.
"long"
が str
の部分文字列であるかどうかをテストします。制約で大文字と小文字が区別されるため、テストは失敗します。
testCase.verifyThat("long",IsSubstringOf(str))
Verification failed. --------------------- Framework Diagnostic: --------------------- IsSubstringOf failed. --> The value is not found within the superstring. Actual Value: "long" Expected Superstring: "This Is One Long Message!"
値 "is"
が str
に 2 回出現するかどうかをテストします。テストにパスするように、大文字小文字の区別を無視します。
testCase.verifyThat("is",IsSubstringOf(str, ... "WithCount",2,"IgnoringCase",true))
Verification passed.
値 "thisisone"
が str
の部分文字列であるかどうかをテストします。テストにパスするように、大文字小文字の区別および空白文字を無視します。
testCase.verifyThat("thisisone",IsSubstringOf(str, ... "IgnoringCase",true,"IgnoringWhitespace",true))
Verification passed.
"Longer"
が str
の部分文字列でないことを検証します。
testCase.verifyThat("Longer",~IsSubstringOf(str))
Verification passed.
バージョン履歴
R2013a で導入R2019b: 文字列の出現回数の検証
string スカラーまたは文字ベクトルの必要な出現回数を指定するには、名前と値の引数 WithCount
を使用します。
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)