File data_analysis/unittests/pseudo_hash_test.m changed (mode: 100644) (index 4f944f6..4aa9dc1) |
... |
... |
function shared = setup |
12 |
12 |
shared.shafunction = @(filename) pseudo_hash(filename, 'bytes', shared.bytes_for_test); |
shared.shafunction = @(filename) pseudo_hash(filename, 'bytes', shared.bytes_for_test); |
13 |
13 |
|
|
14 |
14 |
shared.file = '.test.dat'; |
shared.file = '.test.dat'; |
|
15 |
|
assert_file_nonexistent(shared.file); |
15 |
16 |
fid = fopen(shared.file,'w+'); |
fid = fopen(shared.file,'w+'); |
16 |
17 |
fwrite(fid, shared.data, shared.precision); |
fwrite(fid, shared.data, shared.precision); |
17 |
18 |
fclose(fid); |
fclose(fid); |
|
... |
... |
function shared = setup |
23 |
24 |
shared.empty.file = '.test_empty.dat'; |
shared.empty.file = '.test_empty.dat'; |
24 |
25 |
assert_file_nonexistent(shared.empty.file); |
assert_file_nonexistent(shared.empty.file); |
25 |
26 |
|
|
26 |
|
% only runs if /media/schatzkammer/RAID1 is available --> might have to be modified on other machines!! |
|
27 |
|
shared.ext.folder = '/media/schatzkammer/RAID1'; |
|
28 |
|
assert(exist('/media/schatzkammer/RAID1')==7,... |
|
29 |
|
[shared.ext.folder, ' not found. Modify test accordingly!']); |
|
|
27 |
|
exist_not_empty = @(folder)(exist(folder)==7)&&(~isempty(ls(folder))); |
|
28 |
|
if exist_not_empty('/media/schatzkammer/RAID1') |
|
29 |
|
shared.ext.folder = '/media/schatzkammer/RAID1'; |
|
30 |
|
elseif exist_not_empty('~/Downloads') |
|
31 |
|
shared.ext.folder = '~/Downloads'; |
|
32 |
|
else |
|
33 |
|
error(['No suitable folder for tests involving copying files found.',... |
|
34 |
|
'Modify test accordingly!']); |
|
35 |
|
end |
30 |
36 |
shared.ext.file = fullfile(shared.ext.folder, '.test_copy.dat'); |
shared.ext.file = fullfile(shared.ext.folder, '.test_copy.dat'); |
31 |
37 |
assert_file_nonexistent(shared.ext.file); |
assert_file_nonexistent(shared.ext.file); |
32 |
38 |
copyfile(shared.file, shared.ext.file); |
copyfile(shared.file, shared.ext.file); |
|
... |
... |
function teardown(shared) |
45 |
51 |
delete(shared.minifile1); |
delete(shared.minifile1); |
46 |
52 |
delete(shared.minifile2); |
delete(shared.minifile2); |
47 |
53 |
|
|
48 |
|
function pseudo_hash_function_handle_test(shared) |
|
|
54 |
|
function function_handle_test(shared) |
49 |
55 |
assertEqual(shared.shafunction(shared.file),... |
assertEqual(shared.shafunction(shared.file),... |
50 |
56 |
pseudo_hash(shared.file, 'bytes', shared.bytes_for_test)); |
pseudo_hash(shared.file, 'bytes', shared.bytes_for_test)); |
51 |
57 |
|
|
52 |
|
function pseudo_hash_bytes_sensitive_test(shared) |
|
|
58 |
|
function bytes_sensitive_test(shared) |
53 |
59 |
assertFalse(... |
assertFalse(... |
54 |
60 |
isequal(... |
isequal(... |
55 |
61 |
shared.shafunction(shared.file),... |
shared.shafunction(shared.file),... |
56 |
62 |
pseudo_hash(shared.file, 'bytes', 1+shared.bytes_for_test))); |
pseudo_hash(shared.file, 'bytes', 1+shared.bytes_for_test))); |
57 |
63 |
|
|
58 |
|
function pseudo_hash_default_bytes_test(shared) |
|
|
64 |
|
function default_bytes_test(shared) |
59 |
65 |
assertEqual(pseudo_hash(shared.file),... |
assertEqual(pseudo_hash(shared.file),... |
60 |
66 |
pseudo_hash(shared.file, 'bytes', 1e6)); |
pseudo_hash(shared.file, 'bytes', 1e6)); |
61 |
67 |
|
|
62 |
|
function pseudo_hash_filename_filepath_test(shared) |
|
|
68 |
|
function filename_filepath_test(shared) |
63 |
69 |
assertEqual(shared.shafunction(shared.file),... |
assertEqual(shared.shafunction(shared.file),... |
64 |
70 |
shared.shafunction(GetFullPath(shared.file))); |
shared.shafunction(GetFullPath(shared.file))); |
65 |
71 |
|
|
66 |
|
function pseudo_hash_open_close_forread_test(shared) |
|
67 |
|
pseudo_hash_before = shared.shafunction(shared.file); |
|
|
72 |
|
function open_close_forread_test(shared) |
|
73 |
|
before = shared.shafunction(shared.file); |
68 |
74 |
fid = fopen(shared.file, 'r'); |
fid = fopen(shared.file, 'r'); |
69 |
75 |
fclose(fid); |
fclose(fid); |
70 |
|
pseudo_hash_after = shared.shafunction(shared.file); |
|
71 |
|
assertEqual(pseudo_hash_before, pseudo_hash_after); |
|
|
76 |
|
after = shared.shafunction(shared.file); |
|
77 |
|
assertEqual(before, after); |
72 |
78 |
|
|
73 |
|
% function pseudo_hash_open_close_forwrite_test(shared) |
|
74 |
|
% pseudo_hash_before = shared.shafunction(shared.file); |
|
|
79 |
|
% function open_close_forwrite_test(shared) |
|
80 |
|
% before = shared.shafunction(shared.file); |
75 |
81 |
% fid = fopen(shared.file, 'w'); |
% fid = fopen(shared.file, 'w'); |
76 |
82 |
% fclose(fid); |
% fclose(fid); |
77 |
|
% pseudo_hash_after = shared.shafunction(shared.file); |
|
78 |
|
% assertEqual(pseudo_hash_before, pseudo_hash_after); |
|
|
83 |
|
% after = shared.shafunction(shared.file); |
|
84 |
|
% assertEqual(before, after); |
79 |
85 |
|
|
80 |
|
function pseudo_hash_copy_test(shared) |
|
|
86 |
|
function copy_test(shared) |
81 |
87 |
assertEqual(shared.shafunction(shared.file),... |
assertEqual(shared.shafunction(shared.file),... |
82 |
88 |
shared.shafunction(shared.copy.file)); |
shared.shafunction(shared.copy.file)); |
83 |
89 |
|
|
84 |
|
function pseudo_hash_modify_begin_test(shared) |
|
|
90 |
|
function modify_begin_test(shared) |
85 |
91 |
fid = fopen(shared.copy.file, 'w'); |
fid = fopen(shared.copy.file, 'w'); |
86 |
92 |
fseek(fid, 10, 'bof'); |
fseek(fid, 10, 'bof'); |
87 |
93 |
fwrite(fid, randn(1)); |
fwrite(fid, randn(1)); |
|
... |
... |
function pseudo_hash_modify_begin_test(shared) |
90 |
96 |
isequal(shared.shafunction(shared.file),... |
isequal(shared.shafunction(shared.file),... |
91 |
97 |
shared.shafunction(shared.copy.file))); |
shared.shafunction(shared.copy.file))); |
92 |
98 |
|
|
93 |
|
function pseudo_hash_modify_end_test(shared) |
|
|
99 |
|
function modify_end_test(shared) |
94 |
100 |
assertEqual(shared.shafunction(shared.file),... |
assertEqual(shared.shafunction(shared.file),... |
95 |
101 |
shared.shafunction(shared.copy.file)); |
shared.shafunction(shared.copy.file)); |
96 |
102 |
fid = fopen(shared.copy.file, 'w'); |
fid = fopen(shared.copy.file, 'w'); |
|
... |
... |
function pseudo_hash_modify_end_test(shared) |
101 |
107 |
isequal(shared.shafunction(shared.file),... |
isequal(shared.shafunction(shared.file),... |
102 |
108 |
shared.shafunction(shared.copy.file))); |
shared.shafunction(shared.copy.file))); |
103 |
109 |
|
|
104 |
|
function pseudo_hash_modify_length_test(shared) |
|
|
110 |
|
function modify_length_test(shared) |
105 |
111 |
fid = fopen(shared.empty.file, 'w+'); |
fid = fopen(shared.empty.file, 'w+'); |
106 |
112 |
fwrite(fid, shared.data, shared.precision); |
fwrite(fid, shared.data, shared.precision); |
107 |
113 |
%write same data twice to get file with same beginning and end, but different length |
%write same data twice to get file with same beginning and end, but different length |
|
... |
... |
function pseudo_hash_modify_length_test(shared) |
113 |
119 |
delete(shared.empty.file) |
delete(shared.empty.file) |
114 |
120 |
assertFalse( isequal( hash_original, hash_doublesize)); |
assertFalse( isequal( hash_original, hash_doublesize)); |
115 |
121 |
|
|
116 |
|
function pseudo_hash_minifile_test(shared) |
|
|
122 |
|
function minifile_test(shared) |
117 |
123 |
assertFalse(... |
assertFalse(... |
118 |
124 |
isequal(... |
isequal(... |
119 |
125 |
shared.shafunction(shared.minifile1),... |
shared.shafunction(shared.minifile1),... |
120 |
126 |
shared.shafunction(shared.minifile2))); |
shared.shafunction(shared.minifile2))); |
121 |
127 |
|
|
122 |
|
function pseudo_hash_external_filesystem_test(shared) |
|
|
128 |
|
function external_filesystem_test(shared) |
123 |
129 |
assertEqual(... |
assertEqual(... |
124 |
130 |
shared.shafunction(shared.file),... |
shared.shafunction(shared.file),... |
125 |
131 |
shared.shafunction(shared.ext.file)); |
shared.shafunction(shared.ext.file)); |
|
... |
... |
function pseudo_hash_external_filesystem_test(shared) |
127 |
133 |
%% aux functions |
%% aux functions |
128 |
134 |
function assert_file_nonexistent(filename) |
function assert_file_nonexistent(filename) |
129 |
135 |
assertFalse(exist(filename)==2,... |
assertFalse(exist(filename)==2,... |
130 |
|
[GetFullPath(filename), ' already exists!']); |
|
|
136 |
|
[GetFullPath(filename), ' already exists!']); |