Main Content

matlab.unittest.constraints.IsSubstringOf 클래스

네임스페이스: matlab.unittest.constraints
슈퍼클래스: matlab.unittest.constraints.BooleanConstraint

값이 지정된 문자열의 부분문자열인지 테스트

설명

matlab.unittest.constraints.IsSubstringOf 클래스는 값이 지정된 문자열의 부분문자열인지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

c = matlab.unittest.constraints.IsSubstringOf(superstring)은 값이 지정된 문자열의 부분문자열인지 테스트하는 제약 조건을 만듭니다. 이 제약 조건은 string형 스칼라 또는 문자형 벡터가 superstring에 나타나는 경우 충족됩니다.

예제

c = matlab.unittest.constraints.IsSubstringOf(superstring,Name,Value)는 하나 이상의 이름-값 인수를 사용하여 옵션을 추가로 설정합니다. 예를 들어, c = matlab.unittest.constraints.IsSubstringOf(superstring,"IgnoringCase",true)는 대/소문자를 무시하는 제약 조건을 만듭니다.

입력 인수

모두 확장

예상 상위 문자열로, 비어 있지 않은 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)

대/소문자 무시 여부로, 숫자형 또는 논리값 0(false) 또는 1(true)로 지정됩니다. 기본적으로 이 제약 조건은 대/소문자를 구분합니다.

이 인수는 IgnoreCase 속성을 설정합니다.

공백 무시 여부로, 숫자형 또는 논리값 0(false) 또는 1(true)로 지정됩니다. 기본적으로 이 제약 조건은 공백을 무시하지 않습니다. 공백 문자로는 공백(' '), 폼 피드('\f'), 새 줄('\n'), 캐리지 리턴('\r'), 가로 탭('\t'), 세로 탭('\v')이 있습니다.

이 인수는 IgnoreWhitespace 속성을 설정합니다.

참고

IgnoringWhitespacetrue인 경우 superstring은 공백이 아닌 문자를 하나 이상 포함해야 합니다.

테스트할 값이 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

속성

모두 확장

예상 상위 문자열로, string형 스칼라 또는 문자형 벡터로 반환됩니다.

이 속성은 superstring 입력 인수에 의해 설정됩니다.

특성:

GetAccess
public
SetAccess
immutable

대/소문자 무시 여부로, 논리값 0(false) 또는 1(true)로 반환됩니다. 기본적으로 이 제약 조건은 대/소문자를 구분합니다.

이 속성은 IgnoringCase 이름-값 인수에 의해 설정됩니다.

특성:

GetAccess
public
SetAccess
private

공백 무시 여부로, 논리형 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에 두 번 나타나는지 테스트합니다. 테스트가 통과하도록 하기 위해, 대/소문자를 무시합니다.

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에 개발됨

모두 확장