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