Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.2 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Development tools > Assert > assert_checkfilesequal

assert_checkfilesequal

2つのファイルが等しいことを確認する.

呼び出し手順

flag = assert_checkfilesequal ( filecomp , fileref )
flag = assert_checkfilesequal ( filecomp , fileref , compfun )
[flag,errmsg] = assert_checkfilesequal ( ... )

パラメータ

filecomp :

1行1列の文字列行列, 計算されたファイル.

fileref :

1行1列の文字列行列, 基準ファイル.

compfun :

関数またはリスト, 比較用関数 (デフォルト:compfun = []). 比較用関数が使用されない場合, 等価演算子 "==" が使用されます. 詳細については以下を参照ください.

flag :

1行1列の論理値行列, computedがexpectedに近い場合に %t, そうでない場合に %f

errmsg :

1行1列の文字列行列, エラーメッセージ. flag==%t の場合, errmsg="". flag==%f の場合, errmsgにエラーメッセージが代入されます.

説明

ファイルが等しい場合,そのまま実行されます. filecompまたはfilerefが存在しない場合,エラーが発生します. ファイルの内容が等しくない場合,エラーが発生します.

ファイルが等しくない場合,

  • 出力変数errmsgが使用されない場合,エラーが発生し,

  • 出力変数errmsgが使用された場合,エラーは発生しません.

比較用関数compfunが関数の場合, ヘッダareequal = compfun ( txtcomp , txtref )を有する必要があります. ただし, txtcomp は computed ファイルの内容, txtref は基準ファイルの内容, areequalは論理値です. 2つの内容が等しい場合,論理値areequalはtrueとなります. compfunがリストの場合,リスト(cf,a1,a2,...)とする必要があります. ただし, cf は比較関数で, 引数 a1, a2 がcfの呼び出し手順の最後に 自動的に付加されます.

//
// テスト用のデータを準備
// fileref1 : 3行分のテキスト
// filecomp1 : == fileref1
// filecomp2 : <> fileref1
fileref1 = fullfile(TMPDIR,"fileref.txt");
txt1 = [
"Line #1"
"Line #2"
"Line #3"
];
fd = mopen(fileref1,"w");
mputl(txt1,fd);
mclose(fd);
filecomp1 = fullfile(TMPDIR,"filecomp1.txt");
fd = mopen(filecomp1,"w");
mputl(txt1,fd);
mclose(fd);
filecomp2 = fullfile(TMPDIR,"filecomp2.txt");
txt2 = [
"Line #1"
"Line #4"
"Line #3"
];
fd = mopen(filecomp2,"w");
mputl(txt2,fd);
mclose(fd);
// パスするテスト
flag = assert_checkfilesequal ( filecomp1 , fileref1 )
[flag,errmsg] = assert_checkfilesequal ( filecomp1 , fileref1 )
// 失敗: filecomp2 <> fileref1
// エラーが発生
flag = assert_checkfilesequal ( filecomp2 , fileref1 )
// エラーは発生しない
[flag,errmsg] = assert_checkfilesequal ( filecomp2 , fileref1 )
// テスト用のデータを準備
// fileref2 == filecomp3, コメント行を無視した場合
// fileref2 <> filecomp4, コメント行を無視した場合
// コメントはファイルの異なる位置に挿入されることに注意してください:
// ある時は先頭, ある時は中央.
fileref2 = fullfile(TMPDIR,"fileref2.txt");
txt = [
"// bla 2"
"Line #1"
"// bla 2"
"Line #2"
"Line #3"
];
fd = mopen(fileref2,"w");
mputl(txt,fd);
mclose(fd);
filecomp3 = fullfile(TMPDIR,"filecomp3.txt");
txt = [
"Line #1"
"// bla 5168"
"Line #2"
"Line #3"
"// bla oups"
];
fd = mopen(filecomp3,"w");
mputl(txt,fd);
mclose(fd);
filecomp4 = fullfile(TMPDIR,"filecomp4.txt");
txt = [
"// bla 3"
"Line #1"
"Line #4"
"// bla 5168"
"Line #3"
"// bla oups"
];
fd = mopen(filecomp4,"w");
mputl(txt,fd);
mclose(fd);
// コメント行を無視する比較用関数でテスト
function otxt=myfilter(itxt)
nr = size(itxt,"r")
// 形式 "// blabla" のコメント行用のパターン
pattern = "/\/\/.*/"
k = 1
for i = 1 : nr
start = regexp(itxt(i),pattern)
if ( start == [] ) then
otxt(k) = itxt(i)
k = k + 1
end
end
endfunction
function areequal=mycompfun(ctxt, etxt)
ctxt = myfilter ( ctxt )
etxt = myfilter ( etxt )
areequal = ( ctxt == etxt )
endfunction
//
// パスするテスト
[flag,errmsg] = assert_checkfilesequal ( filecomp3 , fileref2 , mycompfun )
// 失敗するテスト
[flag,errmsg] = assert_checkfilesequal ( filecomp4 , fileref2 , mycompfun )

履歴

バージョン記述
5.4.0 関数が導入されました
Report an issue
<< assert_checkfalse Assert assert_checktrue >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:02:37 CET 2019