Skip to content

Commit

Permalink
Re #356 working serializable class, modified IX_aperture and unit tes…
Browse files Browse the repository at this point in the history
…ts for it and its previous versions
  • Loading branch information
abuts committed Oct 18, 2021
1 parent f0c3b0b commit 0d2763f
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 204 deletions.
33 changes: 33 additions & 0 deletions _test/test_instrument_classes/check_matfile_IO.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function [ok,mess] = check_matfile_IO (ver_str, save_variables, filepath,varargin)
% Save to or read from mat file
% input
% ver_str -- the name of the version string e.g. ver0 for old
% version ver1 for version 1 etc
% save_variables -- if true, saves sample variables, if false load
% them from disk
% filepath -- the location of source test files on hdd.
% If the routine writes to disk, it writes
% test files into temporarty directory
% varargin -- variables to save/load on hdd
mess = '';
ok = true;
for i=1:numel(varargin)
class_name = class(varargin{i});
arg_name = inputname(i+3);
flname = [ver_str,'_',class_name,'_',arg_name,'.mat'];
if save_variables
eval([arg_name,' = varargin{i};']);
try
save(fullfile(tmp_dir,flname),arg_name);
catch
mess=['*** ERROR: Problem writing ',arg_name,' to ',flname];
ok = false;
end
else
tmp = load(fullfile(filepath,'saved_class_versions_as_mat_files',flname),arg_name);
if ~isequal(varargin{i},tmp.(arg_name))
ok = false;
mess=['*** ERROR: Argument ''',arg_name,''' read from ',flname,' does not match original'];
end
end
end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 55 additions & 2 deletions _test/test_instrument_classes/test_IX_aperture.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
error('HERBERT:test_IX_apperture:invalid_argument',...
'the test can be called only with one or two parameters')
elseif numel(is)==1
filename = 'test_IX_aperture_data.mat';
filename = 'test_IX_aperture_output.mat';
else
filename = varargin{~is};
end
Expand All @@ -28,7 +28,7 @@
params= {'test_IX_aperture'};
end
self@TestCaseWithSave(params{:});
self.home_folder = test_files_folder;
self.home_folder = test_files_folder;
%does nothing unless the constructor called with '-save' key
self.save()
end
Expand Down Expand Up @@ -69,6 +69,59 @@ function test_pdf (~)
assertEqualToTol(stdev.^2, [0.1^2;0.06^2]/12, 'reltol', 1e-3);
end

function test_apperture_array_prev_versions(obj)
% 2x2 array example
ap_arr = [IX_aperture('Ap0', 11, 0.2, 0.25), IX_aperture('Ap1', 121, 0.22, 0.225);...
IX_aperture('Ap3', 311, 0.23, 0.325), IX_aperture('Ap4', 114, 0.24, 0.245)];
sample_file_location = obj.home_folder;
if obj.save_output % prepare test data for the future.
% move test data to data folder manually
% run test_IX_apperture with -save option to obtain reference
% files when changed to new class version

save_variables=true;
ver = ap_arr.classVersion();
verstr = ['ver',num2str(ver)];
[ok,mess] = check_matfile_IO(verstr, save_variables, sample_file_location ,ap_arr);
assertTrue(ok,mess)
else
save_variables=false;
verstr = 'ver0';
[ok,mess] = check_matfile_IO(verstr, save_variables,sample_file_location ,ap_arr);
assertTrue(ok,mess)

verstr= 'ver1';
[ok,mess] = check_matfile_IO(verstr, save_variables, sample_file_location ,ap_arr);
assertTrue(ok,mess)
end

end
%
function test_single_apperture_load_prev_versions(obj)
% Scalar example
ap = IX_aperture ('Ap0', 11, 0.2, 0.25);
sample_files_location = obj.home_folder;
if obj.save_output
% run test_IX_apperture with -save option to obtain reference
% files when changed to new class version
save_variables=true;
ver = ap.classVersion();
verstr = ['ver',num2str(ver)];
[ok,mess] = check_matfile_IO(verstr, save_variables, sample_files_location ,ap);
assertTrue(ok,mess)

else
save_variables=false;
verstr = 'ver0';
[ok,mess] = check_matfile_IO(verstr, save_variables,sample_files_location ,ap);
assertTrue(ok,mess)

verstr= 'ver1';
[ok,mess] = check_matfile_IO(verstr, save_variables, sample_files_location ,ap);
assertTrue(ok,mess)
end
end

%--------------------------------------------------------------------------
end
end
Expand Down
Binary file modified _test/test_instrument_classes/test_IX_aperture_output.mat
Binary file not shown.
Loading

0 comments on commit 0d2763f

Please sign in to comment.