Main Content

matlab.unittest.constraints.IsFile 클래스

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

값이 파일인지 테스트

설명

matlab.unittest.constraints.IsFile 클래스는 값이 파일을 나타내는지 테스트하는 제약 조건을 제공합니다.

생성

설명

예제

c = matlab.unittest.constraints.IsFile은 값이 파일을 나타내는지 테스트하는 제약 조건을 만듭니다. 이 제약 조건은 string형 스칼라 또는 문자형 벡터가 기존 파일에 대한 경로를 지정하는 경우 충족됩니다. 이 값은 상대 경로일 수 있지만 그 상대 경로가 현재 폴더에 있어야 합니다. 그렇지 않으면 값은 전체 경로여야 합니다. 파일의 경로는 파일 확장자를 포함해야 합니다.

예제

모두 축소

IsFile 제약 조건을 사용하여 파일이 존재하는지 테스트합니다.

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

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsFile

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

testCase = TestCase.forInteractiveUse;

현재 폴더에 하위 폴더를 생성합니다.

folderName = "myFolder_" + string( ...
    datetime("now",Format="yyyyMMdd'T'HHmmss"));
mkdir(folderName)

myFile.dat라는 파일이 하위 폴더에 존재하지 않는지 확인합니다.

filename = folderName + filesep + "myFile.dat";
testCase.verifyThat(filename,~IsFile)
Verification passed.

파일 myFile.dat를 만든 다음 이 파일이 존재하는지 테스트합니다. 테스트가 통과합니다.

writematrix(magic(20),filename)
testCase.verifyThat(filename,IsFile)
Verification passed.

파일을 삭제하고 다시 테스트합니다. 파일이 더 이상 존재하지 않으므로 테스트가 실패합니다.

delete(filename)
testCase.verifyThat(filename,IsFile)
Verification failed.
    ---------------------
    Framework Diagnostic:
    ---------------------
    IsFile failed.
    --> Value does not point to an existing file.
    --> Current folder during evaluation:
            'C:\work'
    
    Actual Value:
        "myFolder_20220622T160205\myFile.dat"

버전 내역

R2018a에 개발됨