Main Content

matlab.unittest.constraints.IsTrue 클래스

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

값이 true인지 테스트

설명

matlab.unittest.constraints.IsTrue 클래스는 값이 true인지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

c = matlab.unittest.constraints.IsTrue는 값이 true인지 테스트하는 제약 조건을 만듭니다. 이 제약 조건은 논리형 스칼라 값이 1(true)인 경우 충족됩니다.

예제

모두 축소

IsTrue 제약 조건을 사용하여 값을 테스트합니다.

먼저 이 예제에서 사용되는 클래스를 가져옵니다.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsTrue

대화형 방식 테스트를 위한 테스트 케이스를 생성합니다.

testCase = TestCase.forInteractiveUse;

trueIsTrue 제약 조건을 충족하는지 확인합니다.

testCase.verifyThat(true,IsTrue)
Verification passed.

false가 제약 조건을 충족하는지 테스트합니다. 테스트가 실패합니다.

testCase.verifyThat(false,IsTrue)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsTrue failed.
    --> The value must evaluate to "true".
    
    Actual Value:
      logical
    
       0

1을 테스트합니다. 값이 double형이므로 테스트가 실패합니다.

testCase.verifyThat(1,IsTrue)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsTrue failed.
    --> The value must be logical. It is of type "double".
    
    Actual Value:
         1

[true true]를 테스트합니다. 값이 비 스칼라이므로 테스트가 실패합니다.

testCase.verifyThat([true true],IsTrue)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsTrue failed.
    --> The value must be scalar. It has a size of [1  2].
    
    Actual Value:
      1×2 logical array
    
       1   1

  • IsTrue 대신에 ReturnsTrue 제약 조건을 사용할 수 있습니다. IsTrue가 더 빠르고 사용하기 더 쉽지만 ReturnsTrue는 보다 개선된 진단 정보를 제공합니다. 이 예제에서는 두 테스트가 모두 실패하지만 두 번째 테스트에서는 진단에 함수 핸들을 표시합니다.

    import matlab.unittest.TestCase
    import matlab.unittest.constraints.IsTrue
    import matlab.unittest.constraints.ReturnsTrue
    
    testCase = TestCase.forInteractiveUse;
    actual = 1;
    expected = 2;
    testCase.verifyThat(isequal(actual,expected),IsTrue)
    testCase.verifyThat(@() isequal(actual,expected),ReturnsTrue)

버전 내역

R2013a에 개발됨