diff --git a/test/services/file_service_test.dart b/test/services/file_service_test.dart index 00d5f5d..836f0de 100644 --- a/test/services/file_service_test.dart +++ b/test/services/file_service_test.dart @@ -250,86 +250,76 @@ }); group('FileService.generateQuantitativeBaseNameSync', () { - test('同秒のファイルが存在しない場合,サフィックスなしの baseName を返す', () { - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - [], - ); - expect(result, 'MiniTIAS_QM_20260404_120000'); - }); + const timestamp = '20260404_120000'; + const baseName = 'MiniTIAS_QM_$timestamp'; - test('同秒の .dng が存在する場合,_1 サフィックスを付与する', () { - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - ['MiniTIAS_QM_20260404_120000.dng'], - ); - expect(result, 'MiniTIAS_QM_20260404_120000_1'); - }); - - test('_1.dng も存在する場合,_2 サフィックスを付与する', () { - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - [ - 'MiniTIAS_QM_20260404_120000.dng', - 'MiniTIAS_QM_20260404_120000_1.dng', + // 「タイムスタンプ+既存ファイル一覧 → baseName」の等価検証は, + // 入力(existing)と期待値だけが異なる同型ケースのためテーブル駆動でまとめる. + // 重複判定は `.dng` の存在チェックのみで行い,suffix=1 から順に空きを探す仕様. + final cases = <({String name, List existing, String expected})>[ + ( + name: '同秒のファイルが存在しない場合,サフィックスなしの baseName を返す', + existing: [], + expected: baseName, + ), + ( + name: '同秒の .dng が存在する場合,_1 サフィックスを付与する', + existing: ['$baseName.dng'], + expected: '${baseName}_1', + ), + ( + name: '_1.dng も存在する場合,_2 サフィックスを付与する', + existing: ['$baseName.dng', '${baseName}_1.dng'], + expected: '${baseName}_2', + ), + ( + name: '異なるタイムスタンプの .dng が存在しても影響しない', + existing: ['MiniTIAS_QM_20260404_120001.dng'], + expected: baseName, + ), + ( + // _1 が存在しないため,欠番の _1 を返す + name: '連番に欠番がある場合(_1.dng が欠落),_2 ではなく _1 を返す', + existing: ['$baseName.dng', '${baseName}_2.dng'], + expected: '${baseName}_1', + ), + ( + name: '連番が多数存在する場合(_1〜_5.dng),_6 を付与する', + existing: [ + '$baseName.dng', + '${baseName}_1.dng', + '${baseName}_2.dng', + '${baseName}_3.dng', + '${baseName}_4.dng', + '${baseName}_5.dng', ], - ); - expect(result, 'MiniTIAS_QM_20260404_120000_2'); - }); + expected: '${baseName}_6', + ), + ( + // 重複判定は .dng のみを見るため,.meta.json のみでは重複とみなさない + name: '候補 .meta.json のみが存在し .dng がない場合,サフィックスなしを返す', + existing: ['$baseName.meta.json'], + expected: baseName, + ), + ]; - test('異なるタイムスタンプの .dng が存在しても影響しない', () { - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - ['MiniTIAS_QM_20260404_120001.dng'], - ); - expect(result, 'MiniTIAS_QM_20260404_120000'); - }); + for (final c in cases) { + test(c.name, () { + final result = FileService.generateQuantitativeBaseNameSync( + timestamp, + c.existing, + ); + expect(result, c.expected); + }); + } test('返り値が MiniTIAS_QM_ プレフィックスで始まる', () { final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', + timestamp, [], ); expect(result, startsWith('MiniTIAS_QM_')); }); - - test('連番に欠番がある場合(_1.dng が欠落),_2 ではなく _1 を返す', () { - // 仕様: suffix=1 から順に探すため _1 が存在しなければ _1 を返す - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - [ - 'MiniTIAS_QM_20260404_120000.dng', - 'MiniTIAS_QM_20260404_120000_2.dng', // _1 が存在しない状態 - ], - ); - expect(result, 'MiniTIAS_QM_20260404_120000_1'); - }); - - test('連番が多数存在する場合(_1〜_5.dng),_6 を付与する', () { - final existing = [ - 'MiniTIAS_QM_20260404_120000.dng', - 'MiniTIAS_QM_20260404_120000_1.dng', - 'MiniTIAS_QM_20260404_120000_2.dng', - 'MiniTIAS_QM_20260404_120000_3.dng', - 'MiniTIAS_QM_20260404_120000_4.dng', - 'MiniTIAS_QM_20260404_120000_5.dng', - ]; - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - existing, - ); - expect(result, 'MiniTIAS_QM_20260404_120000_6'); - }); - - test('候補 .meta.json のみが存在し .dng がない場合,サフィックスなしを返す', () { - // 重複判定は .dng の存在チェックのみであるため, - // .meta.json のみ存在しても重複とみなさない - final result = FileService.generateQuantitativeBaseNameSync( - '20260404_120000', - ['MiniTIAS_QM_20260404_120000.meta.json'], - ); - expect(result, 'MiniTIAS_QM_20260404_120000'); - }); }); group('FileService.saveQuantitativeMetadata', () {