22%
33% SPDX-License-Identifier: BSD-3-Clause
44
5- function test_binsparse_roundtrip_dir(root_dir )
5+ function test_binsparse_roundtrip_dir(root_dir , temp_dir )
66% TEST_BINSPARSE_ROUNDTRIP_DIR - Round-trip binsparse files in a directory.
77%
88% This function scans a directory (recursively) for .h5 files, reads each
99% with binsparse_read, writes to a temporary file with binsparse_write, then
1010% reads back and checks for equivalence.
1111
1212if nargin < 1 || isempty(root_dir )
13- error(' Usage: test_binsparse_roundtrip_dir(root_dir)' );
13+ error(' Usage: test_binsparse_roundtrip_dir(root_dir, [temp_dir] )' );
1414end
1515
1616if ~isfolder(root_dir )
@@ -25,6 +25,14 @@ function test_binsparse_roundtrip_dir(root_dir)
2525 error(' binsparse_write MEX function not found. Build it first.' );
2626end
2727
28+ if nargin < 2 || isempty(temp_dir )
29+ temp_dir = ' ' ;
30+ end
31+
32+ if ~isempty(temp_dir ) && ~isfolder(temp_dir )
33+ error(' Temp directory not found: %s ' , temp_dir );
34+ end
35+
2836files = list_h5_files(root_dir );
2937if isempty(files )
3038 fprintf(' No .h5 files found under %s\n ' , root_dir );
@@ -41,7 +49,11 @@ function test_binsparse_roundtrip_dir(root_dir)
4149 try
4250 matrix = binsparse_read(file_path );
4351
44- temp_file = [tempname(), ' .bsp.h5' ];
52+ if isempty(temp_dir )
53+ temp_file = [tempname(), ' .bsp.h5' ];
54+ else
55+ temp_file = [tempname(temp_dir ), ' .bsp.h5' ];
56+ end
4557 cleanup = onCleanup(@() cleanup_temp_file(temp_file ));
4658
4759 binsparse_write(temp_file , matrix );
0 commit comments