Mercurial > hg > ltpda
view testing/utp_1.1/utps/ao/utp_ao_split_interval.m @ 52:daf4eab1a51e database-connection-manager tip
Fix. Default password should be [] not an empty string
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 07 Dec 2011 17:29:47 +0100 |
parents | 409a22968d5e |
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_interval.m,v 1.9 2011/09/29 12:09:56 ingo Exp $ % % <MethodDescription> % % The split method of the ao class splits an analysis object into the % specified segments. This UTP splits the AOs into sample segments. % % </MethodDescription> function results = utp_ao_split_interval(varargin) % Check the inputs if nargin == 0 % Some keywords class = 'ao'; mthd = 'split'; results = []; disp('******************************************************'); disp(['**** Running UTPs for ' class '/' mthd]); disp('******************************************************'); % 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 with AO which can collapse the x-axis n = 300; fs = 3; x = 0:(1/fs):(n/fs)-1/fs; a1 = ao(x, randn(n,1), fs); a1.setT0(a1.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pli = plist('start_time', st, 'end_time', et); results = [results utp_11(mthd, a1, ple1, pli)]; % Test plotinfo doesn't disappear results = [results utp_12]; % Test key-words: start_time + duration results = [results utp_13]; % Test key-words: timespan results = [results utp_14]; % Test key-words: start_time + end_time results = [results utp_15]; % Test not equal sampled data (tsdata) and 'timeshift' option results = [results utp_16]; % Test not equal sampled data (tsdata) and 'timeshift' option results = [results utp_17]; % Test not equal sampled data (tsdata) and 'timeshift' option 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 % Check options if ~isequal(io(idx).plists.getOptionsForParam('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 % Check options if ~isequal(io(idx).plists.getOptionsForParam('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 % Check options if ~isequal(io(idx).plists.getOptionsForParam('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 % Check options if ~isequal(io(idx).plists.getOptionsForParam('N'), {[]}), atest = false; end if ~isequal(io(idx).plists.getOptionsForParam('match'), {true, false}), 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 % Check options %%%%%%%%%% 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 % Check options %%%%%%%%%% 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 % Check options 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> n1 = 300; fs1 = 3; x1 = 0:(1/fs1):(n1/fs1)-1/fs1; a1 = ao(x1, randn(n1,1), fs1); n2 = 100; fs2 = 1; x2 = 0:(1/fs2):(n2/fs2)-1/fs2; a2 = ao(x2, randn(n2,1), fs2); n3 = 100; fs3 = .3; x3 = 0:(1/fs3):(n3/fs3)-1/fs3; a3 = ao(x3, randn(n3,1), fs3); a1.setT0(a1.t0 + time('14:00:00')); a2.setT0(a2.t0 + time('14:00:00')); a3.setT0(a3.t0 + time('14:00:00')); avec = [a1, a2, a3]; st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); out = split(avec, pl); % </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 % 'avec' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out) ~= numel(avec), atest = false; end % Check each output for kk=1:2:numel(out) %%%% Check Interval '14:00:25' .. '14:01:15' x = avec(kk).x + avec(kk).t0.double; y = avec(kk).y; % Comput start/end time ts = time(st).double; te = time(et).double; idx = find(x >= ts & x < te); % Normalize out data ox = out(kk).x + out(kk).t0.double; oy = out(kk).y; % Check data if ~isequal(ox, x(idx)), 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> n1 = 300; fs1 = 3; x1 = 0:(1/fs1):(n1/fs1)-1/fs1; a1 = ao(x1, randn(n1,1), fs1); n2 = 100; fs2 = 1; x2 = 0:(1/fs2):(n2/fs2)-1/fs2; a2 = ao(x2, randn(n2,1), fs2); n3 = 100; fs3 = .3; x3 = 0:(1/fs3):(n3/fs3)-1/fs3; a3 = ao(x3, randn(n3,1), fs3); a1.setT0(a1.t0 + time('14:00:00')); a2.setT0(a2.t0 + time('14:00:00')); a3.setT0(a3.t0 + time('14:00:00')); amat = [a1, a2, a3; a3, a1, a2]; st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); out = split(amat, pl); % </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 % 'amat' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out) ~= numel(amat), atest = false; end % Check each output for kk=1:2:numel(out) %%%% Check Interval '14:00:25' .. '14:01:15' x = amat(kk).x + amat(kk).t0.double; y = amat(kk).y; % Comput start/end time ts = time(st).double; te = time(et).double; idx = find(x >= ts & x < te); % Normalize out data ox = out(kk).x + out(kk).t0.double; oy = out(kk).y; % Check data if ~isequal(ox, x(idx)), 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> n1 = 300; fs1 = 3; x1 = 0:(1/fs1):(n1/fs1)-1/fs1; a1 = ao(x1, randn(n1,1), fs1); n2 = 100; fs2 = 1; x2 = 0:(1/fs2):(n2/fs2)-1/fs2; a2 = ao(x2, randn(n2,1), fs2); n3 = 100; fs3 = .3; x3 = 0:(1/fs3):(n3/fs3)-1/fs3; a3 = ao(x3, randn(n3,1), fs3); a1.setT0(a1.t0 + time('14:00:00')); a2.setT0(a2.t0 + time('14:00:00')); a3.setT0(a3.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); out = split(a1, a2, a3, pl); % </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 % 'amat' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; aoin = [a1, a2, a3]; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out) ~= numel(aoin), atest = false; end % Check each output for kk=1:2:numel(out) %%%% Check Interval '14:00:25' .. '14:01:15' x = aoin(kk).x + aoin(kk).t0.double; y = aoin(kk).y; % Comput start/end time ts = time(st).double; te = time(et).double; idx = find(x >= ts & x < te); % Normalize out data ox = out(kk).x + out(kk).t0.double; oy = out(kk).y; % Check data if ~isequal(ox, x(idx)), 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> n1 = 300; fs1 = 3; x1 = 0:(1/fs1):(n1/fs1)-1/fs1; a1 = ao(x1, randn(n1,1), fs1); n2 = 100; fs2 = 1; x2 = 0:(1/fs2):(n2/fs2)-1/fs2; a2 = ao(x2, randn(n2,1), fs2); n3 = 100; fs3 = .3; x3 = 5000:(1/fs3):5000+((n3/fs3)-1/fs3); a3 = ao(x3, randn(n3,1), fs3); a1.setT0(a1.t0 + time('14:00:00')); a2.setT0(a2.t0 + time('14:00:00')); a3.setT0(a3.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); out = split(a1, [a2;a1], a3, pl); % </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 % 'amat' times numbers of intervals % 2) Check that each output AO contains the correct data. % % </AlgoDescription> atest = true; aoin = [a1, a2, a1, a3]; if stest % <AlgoCode> % Check we have the correct number of outputs if numel(out) ~= numel(aoin), atest = false; end % Check each output for kk=1:2:numel(out) %%%% Check Interval '14:00:25' .. '14:01:15' x = aoin(kk).x + aoin(kk).t0.double; y = aoin(kk).y; % Comput start/end time ts = time(st).double; te = time(et).double; idx = find(x >= ts & x < te); % Normalize out data ox = out(kk).x + out(kk).t0.double; oy = out(kk).y; % Check data if ~isequal(ox, x(idx)), 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> n1 = 100; fs1 = .3; x1 = 5000:1/fs1:5000+((n1/fs1)-1/fs1); a1 = ao(x1, randn(n1,1), fs1); a1.setT0(a1.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); out = split(a1, pl); mout = rebuild(out); % </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.hist.methodInfo.mname, 'split'), atest = false; end % The rebuilt object must be the same as 'out' if ~eq(mout, out, 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> a1 = ao(5000:5099, randn(100,1), 1); a1.setT0(a1.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); 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> a1 = ao(5000:5099, randn(100,1), 1); a2 = ao(5000:5099, randn(100,1).', 1); a1.setT0(a1.t0 + time('14:00:00')); a2.setT0(a1.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); out1 = split(a1, pl); out2 = split(a2, pl); % </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.data.y,1) == 1, atest = false; end if size(out2.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> a1 = ao(5000:5099, randn(100,1), 1); a2 = ao(5000:5099, randn(100,1).', 1); a1.setT0(a1.t0 + time('14:00:00')); a2.setT0(a1.t0 + time('14:00:00')); st = '14:00:25'; et = '14:01:15'; pl = plist('start_time', st, 'end_time', et); [o1, o2] = split(a1, a2, pl); o3 = split(a1, a2, 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 can handle AO which have a collaped x-axis. % % </TestDescription> function result = utp_10 % <SyntaxDescription> % % Check that the split method can handle AO which have a collaped x-axis. % % </SyntaxDescription> try % <SyntaxCode> plao = plist('fs', 30, 'nsecs', 30, 'waveform', 'sine wave', 'f', 1.23, 'phi', 30); a1 = ao(plao); a1.setT0(a1.t0 + time('14:00:00')); st = '14:00:07'; et = '14:00:17'; pl = plist('start_time', st, 'end_time', et); out = split(a1, pl); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the number of outputs % 2) Check the output % 3) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the number of outputs if numel(out) ~= 1, atest = false; end % Check the output x = a1.x + a1.t0.double; y = a1.y; % Comput start/end time ts = time(st).double; te = time(et).double; idx = find(x >= ts & x < te); % Normalize out data ox = out.x + out.t0.double; oy = out.y; % Check data if ~isequal(ox, x(idx)), atest = false; end if ~isequal(oy, 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_10 %% UTP_12 % <TestDescription> % % Check that the split method uses the key-words: start_time and duration % % </TestDescription> function result = utp_12 % <SyntaxDescription> % % Check that the split method uses the key-words: start_time and % duration % % </SyntaxDescription> try % <SyntaxCode> a1 = ao(5000:5099, randn(100,1), 1); a1.setT0(a1.t0 + time('14:00:00')); st = format(time('14:01:00')+5000, 'HH:MM:SS'); du = '00:00:10'; plc = plist('start_time', st, 'duration', du); plo = plist('start_time', time(st), 'duration', time(du)); outc = split(a1, plc); outo = split(a1, plo); moutc = rebuild(outc); mouto = rebuild(outo); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the number of outputs % 2) Check the output % 3) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; TOL = 1e-11; if stest % <AlgoCode> % Check the number of outputs if numel(outc) ~= 1, atest = false; end if numel(outo) ~= 1, atest = false; end % Check the output x = a1.x + a1.t0.double; y = a1.y; % Comput start/end time ts = time(st).double; te = ts + time(du).double; idx = find(x >= ts & x < te); % Normalize out data oxc = outc.x + outc.t0.double; oyc = outc.y; oxo = outo.x + outo.t0.double; oyo = outo.y; % Check data if any(abs(oxc - x(idx)) > TOL), atest = false; end if ~isequal(oyc, y(idx)), atest = false; end if any(abs(oxo - x(idx)) > TOL), atest = false; end if ~isequal(oyo, y(idx)), atest = false; end % Check the rebuilding of the object if ~eq(outc, moutc, ple2), atest = false; end if ~eq(outo, mouto, 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 uses the key-words: timespan % % </TestDescription> function result = utp_13 % <SyntaxDescription> % % Check that the split method uses the key-words: timespan % % </SyntaxDescription> try % <SyntaxCode> a1 = ao(5000:5099, randn(100,1), 1); a1.setT0(a1.t0 + time('14:00:00')); ts = timespan(time('14:00:20')+5e3, time('14:00:50')+5e3); pl = plist('timespan', ts); out = split(a1, pl); mout = rebuild(out); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the number of outputs % 2) Check the output % 3) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; TOL = 1e-11; if stest % <AlgoCode> % Check the number of outputs if numel(out) ~= 1, atest = false; end % Check the output x = a1.x + a1.t0.double; y = a1.y; % Comput start/end time ts = double(time('14:00:20')+5e3); te = double(time('14:00:50')+5e3); idx = find(x >= ts & x < te); % Normalize out data ox = out.x + out.t0.double; oy = out.y; % Check data if any(abs(ox - x(idx)) > TOL), atest = false; end if ~isequal(oy, 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_13 %% UTP_14 % <TestDescription> % % Check that the split method uses the key-words: start_time and end_time % % </TestDescription> function result = utp_14 % <SyntaxDescription> % % Check that the split method uses the key-words: start_time and end_time % % </SyntaxDescription> try % <SyntaxCode> a1 = ao(plist('xvals', '0:199', 'yvals', 'randn(200,1)', 'fs', 1, 't0', '14:00:00 2009-02-17')); st = '14:01:40 2009-02-17'; et = '14:03:20 17-02-2009'; plc = plist('start_time', st, 'end_time', et); plo = plist('start_time', time(st), 'end_time', time(et)); outc = split(a1, plc); outo = split(a1, plo); moutc = rebuild(outc); mouto = rebuild(outo); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the number of outputs % 2) Check the output % 3) Check that the 'rebuild' method produces the same object as 'out'. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the number of outputs if numel(outc) ~= 1, atest = false; end if numel(outo) ~= 1, atest = false; end % Check the output x = a1.x + a1.t0.double; y = a1.y; % Comput start/end time ts = time(st).double; te = time(et).double; idx = find(x >= ts & x < te); % Normalize out data oxc = outc.x + outc.t0.double; oyc = outc.y; oxo = outo.x + outo.t0.double; oyo = outo.y; % Check data if ~isequal(oxc, x(idx)), atest = false; end if ~isequal(oyc, y(idx)), atest = false; end if ~isequal(oxo, x(idx)), atest = false; end if ~isequal(oyo, y(idx)), atest = false; end % Check the rebuilding of the object if ~eq(outc, moutc, ple2), atest = false; end if ~eq(outo, mouto, 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 two time objects. % % </TestDescription> function result = utp_15 % <SyntaxDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via two time objects. % % </SyntaxDescription> try % <SyntaxCode> x = [1:1018 1020:1999 2001:3000 3002:6500 6502:7000 7002:10000]; y = randn(1e4,1); y = y(x); % Use the x values as an index a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 't0', '2009-11-03 18:00:00.000', 'yunits', 'N')); start_time = time('2009-11-03 18:10:00.000'); end_time = time('2009-11-03 18:20:00.000'); pl1 = plist(... 'start_time', start_time, ... 'end_time', end_time); out1 = split(a1, pl1); mout1 = rebuild(out1); % </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> % Check number of seconds dt = double(end_time - start_time); if out1.nsecs ~= dt, atest = false; end % Check t0 dt0 = double(out1.t0 - a1.t0); if dt0 ~= 0, atest = false; end % Check the rebuilding of the object if ~eq(out1, mout1, 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_16 % <TestDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via two time strings. % % </TestDescription> function result = utp_16 % <SyntaxDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via two time strings. % % </SyntaxDescription> try % <SyntaxCode> x = [1:1018 1020:1999 2001:3000 3002:6500 6502:7000 7002:10000]; y = randn(1e5, 1); y = y(x); % Use the x values as an index a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 't0', '2009-11-03 18:00:00.000', 'yunits', 'N')); start_time = '2009-11-03 18:10:00.000'; end_time = '2009-11-03 18:20:00.000'; pl1 = plist(... 'start_time', start_time, ... 'end_time', end_time); out1 = split(a1, pl1); mout1 = rebuild(out1); % </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> % Check number of seconds dt = double(time(end_time) - time(start_time)); if out1.nsecs ~= dt, atest = false; end % Check t0 dt0 = double(out1.t0 - a1.t0); if dt0 ~= 0, atest = false; end % Check the rebuilding of the object if ~eq(out1, mout1, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_16 %% UTP_17 % <TestDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via one timespan object. % % </TestDescription> function result = utp_17 % <SyntaxDescription> % % Check that the split method works with notequal sampled data. % Check that the interval can be passed via one timespan object. % % </SyntaxDescription> try % <SyntaxCode> x = [1:1018 1020:1999 2001:3000 3002:6500 6502:7000 7002:10000]; y = randn(1e5, 1); y = y(x); % Use the x values as an index a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 't0', '2009-11-03 18:00:00.000', 'yunits', 'N')); start_time = '2009-11-03 18:10:00.000'; end_time = '2009-11-03 18:15:00.000'; time_range = timespan(start_time, end_time); pl1 = plist(... 'timespan', time_range); out1 = split(a1, pl1); mout1 = rebuild(out1); % </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> % Check number of seconds dt = double(time_range.endT - time_range.startT); if out1.nsecs ~= dt, atest = false; end % Check t0 dt0 = double(out1.t0 - a1.t0); if dt0 ~= 0, atest = false; end % Check the rebuilding of the object if ~eq(out1, mout1, ple2), atest = false; end % </AlgoCode> else atest = false; end % Return a result structure result = utp_prepare_result(atest, stest, dbstack, mfilename); end % END UTP_17 end