Mercurial > hg > ltpda
view testing/utp_1.1/utps/ao/utp_ao_split_times_frequ.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | |
children |
line wrap: on
line source
% UTP_AO_SPLIT a set of UTPs for the ao/split method % % M Hewitson 06-08-08 % % $Id: utp_ao_split_times_frequ.m,v 1.20 2011/11/06 18:45:44 mauro Exp $ % % <MethodDescription> % % The split method of the ao class splits an analysis object into the % specified segments. This UTP splits the AOs into frequencies segments or % into time segments. % % </MethodDescription> function results = utp_ao_split_times_frequ(varargin) % Check the inputs if nargin == 0 % Some keywords class = 'ao'; mthd = 'split'; results = []; disp('******************************************************'); disp(['**** Running UTPs for ' class '/' mthd]); disp('******************************************************'); % Test AOs [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao; % Exception list for the UTPs: [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); % Run the tests results = [results utp_01]; % getInfo call results = [results utp_02]; % Vector input results = [results utp_03]; % Matrix input results = [results utp_04]; % List input results = [results utp_05]; % Test with mixed input results = [results utp_06]; % Test history is working results = [results utp_07]; % Test the modify call works results = [results utp_08]; % Test input data shape == output data shape results = [results utp_09]; % Test output of the data results = [results utp_10]; % Test different end interval (tsdata) pli = plist('times', [4 15 10 25]); results = [results utp_11(mthd, at1, ple1, pli)]; % Test plotinfo doesn't disappear results = [results utp_12]; % Test not equal sampled data (tsdata) results = [results utp_13]; % Test 'dx' and 'dy' results = [results utp_14]; % Test different end interval (fsdata) results = [results utp_15]; % Test not equal sampled data (tsdata) and 'timeshift' option results = [results utp_16]; % Test different end interval (tsdata) disp('Done.'); disp('******************************************************'); elseif nargin == 1 % Check for UTP functions if strcmp(varargin{1}, 'isutp') results = 1; else results = 0; end else error('### Incorrect inputs') end %% UTP_01 % <TestDescription> % % Tests that the getInfo call works for this method. % % </TestDescription> function result = utp_01 % <SyntaxDescription> % % Test that the getInfo call works for no sets, all sets, and each set % individually. % % </SyntaxDescription> try % <SyntaxCode> % Call for no sets io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); % Call for all sets io(2) = eval([class '.getInfo(''' mthd ''')']); % Call for each set for kk=1:numel(io(2).sets) io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); end % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that getInfo call returned an minfo object in all cases. % 2) Check that all plists have the correct parameters. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % check we have minfo objects if isa(io, 'minfo') %%% SET 'None' idx = 1; if ~isempty(io(idx).sets), atest = false; end if ~isempty(io(idx).plists), atest = false; end %%% Check all Sets idx = 2; if ~any(strcmpi(io(idx).sets, 'Default')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By times')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By frequencies')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By samples')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By chunks')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By interval start/end')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By interval start/duration')), atest = false; end if ~any(strcmpi(io(idx).sets, 'By interval timespan')), atest = false; end if numel(io(idx).plists) ~= numel(io(idx).sets), atest = false; end %%%%%%%%%% SET 'Default' idx = 3; if io(idx).plists.nparams ~= 1, atest = false; end % Check key if ~io(idx).plists.isparam('times'), atest = false; end % Check default value if ~isEmptyDouble(io(idx).plists.find('times')), atest = false; end %%%%%%%%%% SET 'By times' idx = 4; if io(idx).plists.nparams ~= 1, atest = false; end % Check key if ~io(idx).plists.isparam('times'), atest = false; end % Check default value if ~isEmptyDouble(io(idx).plists.find('times')), atest = false; end %%%%%%%%%% SET 'By frequencies' idx = 5; if io(idx).plists.nparams ~= 1, atest = false; end % Check key if ~io(idx).plists.isparam('frequencies'), atest = false; end % Check default value if ~isEmptyDouble(io(idx).plists.find('frequencies')), atest = false; end % Check options if ~isequal(io(idx).plists.getOptionsForParam('frequencies'), {[]}), atest = false; end %%%%%%%%%% SET 'By samples' idx = 6; if io(idx).plists.nparams ~= 1, atest = false; end % Check key if ~io(idx).plists.isparam('samples'), atest = false; end % Check default value if ~isEmptyDouble(io(idx).plists.find('samples')), atest = false; end %%%%%%%%%% SET 'By chunks' idx = 7; if io(idx).plists.nparams ~= 2, atest = false; end % Check key if ~io(idx).plists.isparam('N'), atest = false; end if ~io(idx).plists.isparam('match'), atest = false; end % Check default value if ~isEmptyDouble(io(idx).plists.find('N')), atest = false; end if ~isequal(io(idx).plists.find('match'), true), atest = false; end %%%%%%%%%% SET 'By interval start/end' idx = 8; if io(idx).plists.nparams ~= 2, atest = false; end % Check key if ~io(idx).plists.isparam('start_time'), atest = false; end if ~io(idx).plists.isparam('end_time'), atest = false; end % Check default value if ~eq(io(idx).plists.find('start_time'), time(0), ple1), atest = false; end if ~eq(io(idx).plists.find('end_time'), time(0), ple1), atest = false; end %%%%%%%%%% SET 'By interval start/duration' idx = 9; if io(idx).plists.nparams ~= 2, atest = false; end % Check key if ~io(idx).plists.isparam('start_time'), atest = false; end if ~io(idx).plists.isparam('duration'), atest = false; end % Check default value if ~eq(io(idx).plists.find('start_time'), time(0), ple1), atest = false; end if ~eq(io(idx).plists.find('duration'), time(0), ple1), atest = false; end %%%%%%%%%% SET 'By interval timespan' idx = 10; if io(idx).plists.nparams ~= 1, atest = false; end % Check key if ~io(idx).plists.isparam('timespan'), atest = false; end % Check default value ts = timespan(0,0); if ~eq(io(idx).plists.find('timespan'), ts, ple1), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_01 %% UTP_02 % <TestDescription> % % Tests that the split method works with a vector of AOs as input. % % </TestDescription> function result = utp_02 % <SyntaxDescription> % % Test that the split method works for a vector of AOs as input. % % </SyntaxDescription> try % <SyntaxCode> pl_ts = plist('times', [4 15 10 25]); pl_fs = plist('frequencies', [2.2 4.2 3 6]); vec_ts = [at1, at5, at6]; vec_fs = [at1.psd, at5.psd, at6.psd]; out_ts = split(vec_ts, pl_ts); out_fs = split(vec_fs, pl_fs); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in % 'atvec' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; TOL = 1e-14; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out_ts) ~= numel(vec_ts) * numel(pl_ts.find('times'))/2, atest = false; end if numel(out_fs) ~= numel(vec_fs) * numel(pl_fs.find('frequencies'))/2, atest = false; end % Check each output for kk=1:2:numel(out_ts) %%%% Check Interval 4 .. 15 x = vec_ts((kk+1)/2).x; y = vec_ts((kk+1)/2).y; idx = find(x >= 4 & x < 15); t0off = (out_ts(kk).t0.utc_epoch_milli - vec_ts((kk+1)/2).t0.utc_epoch_milli)/1e3; ox = out_ts(kk).x + t0off; oy = out_ts(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end %%%% Check Interval 10 .. 25 x = vec_ts((kk+1)/2).x; y = vec_ts((kk+1)/2).y; idx = find(x >= 10 & x < 25); t0off = (out_ts(kk+1).t0.utc_epoch_milli - vec_ts((kk+1)/2).t0.utc_epoch_milli)/1e3; ox = out_ts(kk+1).x + t0off; oy = out_ts(kk+1).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end for kk=1:2:numel(out_fs) %%%% Check Interval 2.2 .. 4.2 x = vec_fs((kk+1)/2).x; y = vec_fs((kk+1)/2).y; idx = find(x >= 2.2 & x < 4.2); ox = out_fs(kk).x; oy = out_fs(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end %%%% Check Interval 3 .. 6 x = vec_fs((kk+1)/2).x; y = vec_fs((kk+1)/2).y; idx = find(x >= 3 & x < 6); ox = out_fs(kk+1).x; oy = out_fs(kk+1).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_02 %% UTP_03 % <TestDescription> % % Tests that the split method works with a matrix of AOs as input. % % </TestDescription> function result = utp_03 % <SyntaxDescription> % % Tests that the split method works with a matrix of AOs as input. % % </SyntaxDescription> try % <SyntaxCode> pl_ts = plist('times', [4 15]); pl_fs = plist('frequencies', [2.2 4.2]); mat_ts = [at1, at5, at6; at1, at5, at6; ]; a = at1.psd; b = at5.psd; c = at6.psd; mat_fs = [a, b, c; a, b, c]; out_ts = split(mat_ts, pl_ts); out_fs = split(mat_fs, pl_fs); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in % 'atvec' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; TOL = 1e-14; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out_ts) ~= numel(mat_ts) * numel(pl_ts.find('times'))/2, atest = false; end if numel(out_fs) ~= numel(mat_fs) * numel(pl_fs.find('frequencies'))/2, atest = false; end % Check each output for kk=1:numel(out_ts) %%%% Check Interval 4 .. 15 x = mat_ts(kk).x; y = mat_ts(kk).y; idx = find(x >= 4 & x < 15); t0off = (out_ts(kk).t0.utc_epoch_milli - mat_ts(kk).t0.utc_epoch_milli)/1e3; ox = out_ts(kk).x + t0off; oy = out_ts(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end for kk=1:numel(out_fs) %%%% Check Interval 2.2 .. 4.2 x = mat_fs(kk).x; y = mat_fs(kk).y; idx = find(x >= 2.2 & x < 4.2); ox = out_fs(kk).x; oy = out_fs(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_03 %% UTP_04 % <TestDescription> % % Tests that the split method works with a list of AOs as input. % % </TestDescription> function result = utp_04 % <SyntaxDescription> % % Tests that the split method works with a list of AOs as input. % % </SyntaxDescription> try % <SyntaxCode> pl_ts = plist('times', [4 15]); pl_fs = plist('frequencies', [2.2 4.2]); out_ts = split(at1, at5, at6, pl_ts); out_fs = split(at1.psd, at5.psd, at6.psd, pl_fs); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in % 'atvec' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; TOL = 1e-14; ints = [at1, at5, at6]; infs = [at1.psd, at5.psd, at6.psd]; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out_ts) ~= numel(ints) * numel(pl_ts.find('times'))/2, atest = false; end if numel(out_fs) ~= numel(infs) * numel(pl_fs.find('frequencies'))/2, atest = false; end % Check each output for kk=1:numel(out_ts) %%%% Check Interval 4 .. 15 x = ints(kk).x; y = ints(kk).y; idx = find(x >= 4 & x < 15); t0off = (out_ts(kk).t0.utc_epoch_milli - ints(kk).t0.utc_epoch_milli)/1e3; ox = out_ts(kk).x + t0off; oy = out_ts(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end for kk=1:numel(out_fs) %%%% Check Interval 2.2 .. 4.2 x = infs(kk).x; y = infs(kk).y; idx = find(x >= 2.2 & x < 4.2); ox = out_fs(kk).x; oy = out_fs(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_04 %% UTP_05 % <TestDescription> % % Tests that the split method works with a mix of different shaped AOs as % input. % % </TestDescription> function result = utp_05 % <SyntaxDescription> % % Tests that the split method works with a mix of different shaped AOs as % input. % % </SyntaxDescription> try % <SyntaxCode> pl_ts = plist('times', [4 15]); pl_fs = plist('frequencies', [2.2 4.2]); out_ts = split([at1, at5], at6, pl_ts); out_fs = split([at1.psd, at5.psd], at6.psd, pl_fs); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the number of elements in 'out' is the same as in % 'atvec' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; TOL = 1e-14; ints = [at1, at5, at6]; infs = [at1.psd, at5.psd, at6.psd]; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out_ts) ~= numel(ints) * numel(pl_ts.find('times'))/2, atest = false; end if numel(out_fs) ~= numel(infs) * numel(pl_fs.find('frequencies'))/2, atest = false; end % Check each output for kk=1:numel(out_ts) %%%% Check Interval 4 .. 15 x = ints(kk).x; y = ints(kk).y; idx = find(x >= 4 & x < 15); t0off = (out_ts(kk).t0.utc_epoch_milli - ints(kk).t0.utc_epoch_milli)/1e3; ox = out_ts(kk).x + t0off; oy = out_ts(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end for kk=1:numel(out_fs) %%%% Check Interval 2.2 .. 4.2 x = infs(kk).x; y = infs(kk).y; idx = find(x >= 2.2 & x < 4.2); ox = out_fs(kk).x; oy = out_fs(kk).y; if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, y(idx)), atest = false; end end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_05 %% UTP_06 % <TestDescription> % % Tests that the split method properly applies history. % % </TestDescription> function result = utp_06 % <SyntaxDescription> % % Test that the result of applying the split method can be processed back. % % </SyntaxDescription> try % <SyntaxCode> pl_ts = plist('times', [4 15 13 25.5]); pl_fs = plist('frequencies', [2.2 4.2 1 4]); out_ts = split(at1, pl_ts); out_fs = split(at2, pl_fs); mout_ts = rebuild(out_ts); mout_fs = rebuild(out_fs); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the last entry in the history of 'out' corresponds to % 'split'. % 2) Check that the re-built object is the same object as the input. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the last step in the history of 'out' if ~strcmp(out_ts(1).hist.methodInfo.mname, 'split'), atest = false; end if ~strcmp(out_ts(2).hist.methodInfo.mname, 'split'), atest = false; end if ~strcmp(out_fs(1).hist.methodInfo.mname, 'split'), atest = false; end if ~strcmp(out_fs(2).hist.methodInfo.mname, 'split'), atest = false; end % The rebuilt object must be the same as 'out' if ~eq(mout_ts, out_ts, ple2), atest = false; end if ~eq(mout_fs, out_fs, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_06 %% UTP_07 % <TestDescription> % % The split method can not modify the input AO. % % </TestDescription> function result = utp_07 % <SyntaxDescription> % % The split method can not modify the input AO. % % </SyntaxDescription> try % <SyntaxCode> pl = plist('times', [4 15]); amodi = ao(at1); aeq = ao(at1); out = aeq.split(pl); amodi.split(pl); stest = false; % </SyntaxCode> catch stest = true; end % <AlgoDescription> % % 1) Nothind to do. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_07 %% UTP_08 % <TestDescription> % % Test the shape of the output. % % </TestDescription> function result = utp_08 % <SyntaxDescription> % % Test that the split method keeps the data shape of the input object. % The input AO must be an AO with row data and an AO with column data. % % </SyntaxDescription> try % <SyntaxCode> pl_ts = plist('times', [5 7]); out1_ts = split(at5, pl_ts); out2_ts = split(at6, pl_ts); pl_fs = plist('frequencies', [1 3]); out1_fs = split(at5.psd, pl_fs); out2_fs = split(at6.psd, pl_fs); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the shape of the data doesn't change. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the shape of the output data if size(out1_ts.data.y,1) == 1, atest = false; end if size(out2_ts.data.y,2) == 1, atest = false; end if size(out1_fs.data.y,1) == 1, atest = false; end if size(out2_fs.data.y,2) == 1, atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_08 %% UTP_09 % <TestDescription> % % Check that the split method pass back the output objects to a list of % output variables or to a single variable. % % </TestDescription> function result = utp_09 % <SyntaxDescription> % % Call the method with a list of output variables and with a single % output variable. Additionaly check that the rebuild method works on % the output. % % </SyntaxDescription> try % <SyntaxCode> pl = plist('times', [2 6 10 12]); [o1, o2] = split(at5, pl); o3 = split(at5, pl); mout1 = rebuild(o1); mout2 = rebuild(o2); mout3 = rebuild(o3); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the output contains the right number of objects % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the number of outputs if numel(o1) ~=1, atest = false; end if numel(o2) ~=1, atest = false; end if numel(o3) ~=2, atest = false; end % Check the rebuilding of the object if ~eq(o1, mout1, ple2), atest = false; end if ~eq(o2, mout2, ple2), atest = false; end if ~eq(o3, mout3, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_09 %% UTP_10 % <TestDescription> % % Check that the split method interprets a negative end interval as a % indicates count from end and a zero for the and interval as the end of % the vector. % % </TestDescription> function result = utp_10 % <SyntaxDescription> % % Check this behavior for time-series data. % % </SyntaxDescription> try % <SyntaxCode> toff = 10; tt = [100 0 120 -40]; fs = .1; n = 30; x = 0:1/fs:1+(n/fs)-1/fs; aa = ao(x, randn(n,1), fs); aa.setT0('14:00:00'); aa.setXY(aa.x+toff, aa.y); % Create an offset pl = plist('times', tt); out = split(aa, pl); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Interval 100 .. 0 -> (end) x = aa.x; y = aa.y; idx = find(x >= 100 & x <= x(end)); ox = out(1).x + (out(1).t0.utc_epoch_milli/1000 - aa.t0.utc_epoch_milli/1000); oy = out(1).y; if ~isequal(ox, x(idx)), atest = false; end if ~isequal(oy, y(idx)), atest = false; end % Interval 120 .. -40 -> nsecs - 40 x = aa.x; y = aa.y; idx = find(x >= 120 & x < aa.data.nsecs - 40); ox = out(2).x + (out(2).t0.utc_epoch_milli/1000 - aa.t0.utc_epoch_milli/1000); oy = out(2).y; if ~isequal(ox, x(idx)), atest = false; end if ~isequal(oy, y(idx)), atest = false; end % Check properties if ~isequal(out(1).data.nsecs, 200+toff), atest = false; end if ~isequal(out(2).data.nsecs, 140), atest = false; end for ii = 1:2 if ~isequal(out(ii).fs, aa.fs), atest = false; end if ~eq(out(ii).t0, aa.t0), atest = false; end if ~eq(out(ii).data.xunits, aa.data.xunits), atest = false; end if ~eq(out(ii).data.yunits, aa.data.yunits), atest = false; end end % Check the rebuilding of the object if ~eq(out, mout, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_10 %% UTP_12 % <TestDescription> % % Check that the split method works with notequal sampled data. % % </TestDescription> function result = utp_12 % <SyntaxDescription> % % Check that the split method works with notequal sampled data. % % </SyntaxDescription> try % <SyntaxCode> x = sort(randn(1000,1)* 10); y = randn(1000,1); aa = ao(x, y, plist('type', 'tsdata')); aa.setT0('14:00:00'); pl = plist('times', [-5 5]); out = split(aa, pl); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> tol = 1e-14; is = -5; ie = 5; idx = find(x >= is & x < ie); if max(out.x - x(idx)) >= tol, atest = false; end if ~isequal(out.y, y(idx)), atest = false; end % Check the rebuilding of the object if ~eq(out, mout, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_12 %% UTP_13 % <TestDescription> % % Check that the split method also split 'dx' and 'dy'. % % </TestDescription> function result = utp_13 % <SyntaxDescription> % % Check that the split method also split 'dx' and 'dy' if this values % have the same length of the y-values. % % </SyntaxDescription> try % <SyntaxCode> x = sort(randn(1000,1)* 10); y = randn(1000,1); % Create default values for 'dx' and 'dy' dx = randn(1000,1); dy = randn(1000,1); ats1 = ao(x, y, plist('type', 'tsdata')); ats2 = copy(at1, 1); afs1 = copy(at2, 1); ats1.setDx(dx); ats1.setDy(dy); ats2.setDx(dx(1:ats2.len)); ats2.setDy(dy(1:ats2.len)); afs1.setDx(dx(1:afs1.len)); afs1.setDy(dy(1:afs1.len)); out1 = split(ats1, plist('times', [-5 5])); out2 = split(ats2, plist('times', [5 15])); out3 = split(afs1, plist('frequencies', [.5 2])); mout1 = rebuild(out1); mout2 = rebuild(out2); mout3 = rebuild(out3); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> idx = find(x >= -5 & x < 5); if ~isequal(dx(idx), out1.dx), atest = false; end if ~isequal(dy(idx), out1.dy), atest = false; end idx = find(ats2.x >= 5 & ats2.x < 15); ddx = dx(1:ats2.len); ddy = dy(1:ats2.len); if ~isequal(ddx(idx), out2.dx), atest = false; end if ~isequal(ddy(idx), out2.dy), atest = false; end idx = find(afs1.x >= .5 & afs1.x < 2); ddx = dx(1:afs1.len); ddy = dy(1:afs1.len); if ~isequal(ddx(idx), out3.dx), atest = false; end if ~isequal(ddy(idx), out3.dy), atest = false; end % Check the rebuilding of the object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end if ~eq(out3, mout3, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_13 %% UTP_14 % <TestDescription> % % Check that the split method interprets a negative end interval as a % indicates count from end and a zero for the and interval as the end of % the vector. % % </TestDescription> function result = utp_14 % <SyntaxDescription> % % Check this behavior for frequency-series data. % % </SyntaxDescription> try % <SyntaxCode> fs = 60; n = 30; x = 1:1/fs:1+(n-1)/fs; aa = ao(x, randn(n,1), fs); aa.setT0('14:00:00'); aa.psd; pl = plist('frequencies', [7 0 16 -4]); out = split(aa, pl); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output % 2) Check that the 'rebuild' method produces the same object as 'out'. % 3) Check that the output have the same 'fs', 'enbw', 'navs', 'xunits' % and 'yunits' % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Interval 7 .. 0 -> (end) x = aa.x; y = aa.y; idx = find(x >= 7 & x <= x(end)); ox = out(1).x + (out(1).t0.utc_epoch_milli/1000 - aa.t0.utc_epoch_milli/1000); oy = out(1).y; if ~isequal(ox, x(idx)), atest = false; end if ~isequal(oy, y(idx)), atest = false; end % Interval 16 .. -4 -> x(end) - 4 x = aa.x; y = aa.y; idx = find(x >= 16 & x < aa.x(end) - 4); ox = out(2).x; oy = out(2).y; if ~isequal(ox, x(idx)), atest = false; end if ~isequal(oy, y(idx)), atest = false; end % Check properties for ii = 1:2 if ~isequal(out(ii).data.navs, aa.data.navs), atest = false; end if ~isequal(out(ii).data.fs, aa.data.fs), atest = false; end if ~isequal(out(ii).data.enbw, aa.data.enbw), atest = false; end if ~eq(out(ii).data.xunits, aa.data.xunits), atest = false; end if ~eq(out(ii).data.yunits, aa.data.yunits), atest = false; end end % Check the rebuilding of the object if ~eq(out, mout, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_14 %% UTP_15 % <TestDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via an array of double. % Check that the split method works with 'timeshift' option. % % </TestDescription> function result = utp_15 % <SyntaxDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via an array of double. % Check that the split method works with 'timeshift' option. % % </SyntaxDescription> try % <SyntaxCode> a1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 1000, 'yunits', 'N')); in = [1:1019 1020:1999 2001:3000 3002:10000]; a1.setXY(a1.x(in) + 60, a1.y(in)); a1.setT0(time('2009-11-03 18:00:00.000')); times_v = [120 300]; pl1 = plist(... 'times', times_v, ... 'timeshift', false); pl2 = plist(... 'times', times_v, ... 'timeshift', true); out1 = split(a1, pl1); out2 = split(a1, pl2); mout1 = rebuild(out1); mout2 = rebuild(out2); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the outputs % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> TOL = 1e-14; % Check number of seconds if abs(out1.nsecs - (times_v(2) - times_v(1)))/out1.nsecs > TOL, atest = false; end if abs(out2.nsecs - (times_v(2) - times_v(1)))/out2.nsecs > TOL, atest = false; end % Check t0 if ~isequal(out1.t0, a1.t0), atest = false; end if ~isequal(out2.t0, a1.t0), atest = false; end % Check the rebuilding of the object if ~eq(out1, mout1, ple2), atest = false; end if ~eq(out2, mout2, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_15 %% UTP_15 % <TestDescription> % % Check that the split method works with time intervals which doesn' % match the sample frequency. % % </TestDescription> function result = utp_16 % <SyntaxDescription> % % Check that the split method works with time intervals which doesn' % match the sample frequency. % % </SyntaxDescription> try % <SyntaxCode> % Construct an AO a1 = ao(plist('waveform', 'sine', 'f', 0.1, 'a', 1, 'fs', 10, 'nsecs', 10)); a2 = ao(plist('waveform', 'sine', 'f', 0.1, 'a', 1, 'fs', .1, 'nsecs', 1000)); % This should just remove the first data point out1 = split(a1, plist('times', [0.05 0])); out2 = split(a2, plist('times', [5 0])); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the outputs % 2) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> if ~(all(out1.y == a1.y(2:end))), atest = false; end if ~(all(out2.y == a2.y(2:end))), atest = false; end if ~(all(((out1.x + out1.t0.utc_epoch_milli/1000.0) - (a1.x(2:end) + a1.t0.utc_epoch_milli/1000.0)) < 2*eps(out1.x))), atest = false; end if ~(all(((out2.x + out2.t0.utc_epoch_milli/1000.0) - (a2.x(2:end) + a2.t0.utc_epoch_milli/1000.0)) < 2*eps(out2.x))), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_15 end