33 TestHash < matlab .unittest .TestCase
44
55properties
6- file
6+ file = ' hello.txt'
7+ empty = ' empty.txt'
78end
89
910properties (TestParameter )
11+ Pe = {{' md5' , ' d41d8cd98f00b204e9800998ecf8427e' }, ...
12+ {' sha-256' , ' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' }}
13+
1014Ph = {{' md5' , ' 5d41402abc4b2a76b9719d911017c592' }, ...
1115 {' sha-256' , ' 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824' }}
1216backend = {' java' , ' dotnet' , ' sys' }
1721function create_file(tc )
1822tc .applyFixture(matlab .unittest .fixtures .WorkingFolderFixture());
1923
20- tc.file = fullfile(pwd(), class(tc ));
21-
2224fid = fopen(tc .file , " w" );
23-
2425tc .assumeGreaterThan(fid , 0 );
2526fprintf(fid , " hello" );
2627fclose(fid );
28+ tc .assumeTrue(isfile(tc .file ))
29+ tc .assertEqual(stdlib .file_size(tc .file ), 5 )
2730
28- if stdlib .matlabOlderThan( ' R2018a ' )
29- tc .assumeTrue(isfile( tc . file ))
30- else
31- tc .assertThat( tc .file , matlab . unittest . constraints . IsFile )
32- end
31+ fid = fopen( tc . empty , " w " );
32+ tc .assumeGreaterThan( fid , 0 );
33+ fclose( fid );
34+ tc .assumeTrue(isfile( tc .empty ) )
35+ tc .assertEqual( stdlib .file_size( tc . empty ), 0 )
3336end
3437end
3538
@@ -50,6 +53,19 @@ function test_hash_text(tc, Ph, backend)
5053end
5154
5255
56+ function test_hash_empty(tc , Pe , backend )
57+
58+ r = stdlib .file_checksum(tc .empty , Pe{1 }, backend );
59+ tc .verifyClass(r , ' char' )
60+
61+ if ismember(backend , stdlib .Backend().select(' file_checksum' ))
62+ tc .verifyEqual(r , Pe{2 })
63+ else
64+ tc .assertEmpty(r )
65+ end
66+ end
67+
68+
5369function test_has_convenience(tc , Ph )
5470switch Ph{1 }
5571 case ' md5' , tc .verifyEqual(stdlib .md5sum(tc .file ), Ph{2 })
0 commit comments