Mercurial > hg > ltpda
diff testing/utp_1.1/utps/timespan/utp_timespan_timespan.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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testing/utp_1.1/utps/timespan/utp_timespan_timespan.m Tue Dec 06 18:42:11 2011 +0100 @@ -0,0 +1,1269 @@ +% UTP_TIMESPAN_TIMESPAN a set of UTPs for the timespan/timespan method +% +% M Hewitson 06-08-08 +% +% $Id: utp_timespan_timespan.m,v 1.31 2011/09/29 13:46:19 ingo Exp $ +% + +% <MethodDescription> +% +% The timespan method of the timespan class constructs TIMESPAN objects. +% +% </MethodDescription> + +function results = utp_timespan_timespan(varargin) + + % Check the inputs + if nargin == 0 + + % Some keywords + class = 'timespan'; + mthd = 'timespan'; + + results = []; + disp('******************************************************'); + disp(['**** Running UTPs for ' class '/' mthd]); + disp('******************************************************'); + + % Test objects + [ts1, ts2, ts3, ts4, ts5, ts6, tsv, tsm] = get_test_objects_timespan; + + % Exception list for the UTPs: + [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); + + % get preferences + prefs = getappdata(0, 'LTPDApreferences'); + oldTimezone = char(prefs.getTimePrefs.getTimeTimezone); + oldTimeformat = char(prefs.getTimePrefs.getTimestringFormat); + + % set timezone to UTC for all tests + prefs.getTimePrefs.setTimeTimezone('UTC'); + + try + % Run the tests + results = [results utp_00]; + 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 with empty constructor + results = [results utp_07]; % Test history is working with copy constructor + results = [results utp_08]; % Test history is working with MAT file constructor + results = [results utp_09]; % Test history is working with XML file constructor + results = [results utp_10]; % Test history is working with struct constructor + results = [results utp_11]; % Test history is working with plist(filename) constructor + results = [results utp_12]; % Test history is working with plist(hostname) constructor + results = [results utp_13]; % Test history is working with plist(startT+endT) constructor + results = [results utp_15]; % Test history is working with start + end time constructor + results = [results utp_16]; % Test history is working with conn+Id constructor + results = [results utp_17]; % Test history is working with start + end time + format constructor + catch ex + end + + % restore preferences + prefs.getTimePrefs.setTimeTimezone(oldTimezone); + prefs.getTimePrefs.setTimestringFormat(oldTimeformat); + + disp('Done.'); + disp('******************************************************'); + + elseif nargin == 1 % Check for UTP functions + if strcmp(varargin{1}, 'isutp') + results = 1; + elseif strcmpi(varargin{1}, 'needs repository') + results = 2; + else + results = 0; + end + else + error('### Incorrect inputs') + end + + %% UTP_00 + + % <TestDescription> + % + % Tests that the timespan constructor does what is supposed to do. + % + % </TestDescription> + function result = utp_00 + + stest = false; + try + % <SyntaxCode> + ts(1) = timespan(1, 2); + ts(end+1) = timespan('00:00:01', '00:00:02'); + ts(end+1) = timespan(time(1), time(2)); + ts(end+1) = timespan(plist('startT', 1, 'endT', 2)); + ts(end+1) = timespan(plist('startT', '00:00:01', 'endT', '00:00:02')); + ts(end+1) = timespan(plist('startT', time(1), 'endT', time(2))); + ts(end+1) = timespan(plist('startT', '00:00:01', 'endT', '00:00:02')); + ts(end+1) = timespan(plist('startT', '01:00:01', 'endT', '01:00:02', 'timezone', 'CET')); + % </SyntaxCode> + stest = true; + end + + atest = true; + try + % do not run algorithm tests if sintax tests failed + assert(stest); + + % <AlgoCode> + % check that all the start and end time has been interpreted correctly + tstart = [ts.startT]; + assert(all([tstart.utc_epoch_milli] == 1000)); + tend = [ts.endT]; + assert(all([tend.utc_epoch_milli] == 2000)); + % </AlgoCode> + catch + atest = false; + end + + % return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + 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' + if ~isempty(io(1).sets), atest = false; end + if ~isempty(io(1).plists), atest = false; end + %%% Check all Sets + if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From XML File')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From MAT File')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From Repository')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From Timespan Definition')), atest = false; end + if ~any(strcmpi(io(2).sets, 'From Built-in Model')), atest = false; end + if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end + %%%%%%%%%% SET 'Default' + pn = 3; + if io(pn).plists.nparams ~= 3, atest = false; end + % Check key + if ~io(pn).plists.isparam('name'), atest = false; end + if ~io(pn).plists.isparam('description'), atest = false; end + if ~io(pn).plists.isparam('plotinfo'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end + %%%%%%%%%% SET 'From MAT File' + pn = 4; + if io(pn).plists.nparams ~= 4, atest = false; end + % Check key + if ~io(pn).plists.isparam('name'), atest = false; end + if ~io(pn).plists.isparam('description'), atest = false; end + if ~io(pn).plists.isparam('plotinfo'), atest = false; end + if ~io(pn).plists.isparam('filename'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end + %%%%%%%%%% SET 'From XML File' + pn = 5; + if io(pn).plists.nparams ~= 4, atest = false; end + % Check key + if ~io(pn).plists.isparam('name'), atest = false; end + if ~io(pn).plists.isparam('description'), atest = false; end + if ~io(pn).plists.isparam('plotinfo'), atest = false; end + if ~io(pn).plists.isparam('filename'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end + %%%%%%%%%% SET 'From Repository' + pn = 6; + if io(pn).plists.nparams ~= 10, atest = false; end + % Check key + if ~io(pn).plists.isparam('name'), atest = false; end + if ~io(pn).plists.isparam('description'), atest = false; end + if ~io(pn).plists.isparam('plotinfo'), atest = false; end + if ~io(pn).plists.isparam('hostname'), atest = false; end + if ~io(pn).plists.isparam('id'), atest = false; end + if ~io(pn).plists.isparam('cid'), atest = false; end + if ~io(pn).plists.isparam('database'), atest = false; end + if ~io(pn).plists.isparam('binary'), atest = false; end + if ~io(pn).plists.isparam('username'), atest = false; end + if ~io(pn).plists.isparam('password'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('id')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('cid')), atest = false; end + if ~isequal(io(pn).plists.find('binary'), 'yes'), atest = false; end + %%%%%%%%%% SET 'From Built-in Model' + pn = 7; + if io(pn).plists.nparams ~= 4, atest = false; end + % Check key + if ~io(pn).plists.isparam('name'), atest = false; end + if ~io(pn).plists.isparam('description'), atest = false; end + if ~io(pn).plists.isparam('plotinfo'), atest = false; end + if ~io(pn).plists.isparam('built-in'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('built-in')), atest = false; end + %%%%%%%%%% SET 'From Timespan Definition' + pn = 8; + if io(pn).plists.nparams ~= 7, atest = false; end + % Check key + if ~io(pn).plists.isparam('name'), atest = false; end + if ~io(pn).plists.isparam('description'), atest = false; end + if ~io(pn).plists.isparam('plotinfo'), atest = false; end + if ~io(pn).plists.isparam('startt'), atest = false; end + if ~io(pn).plists.isparam('endt'), atest = false; end + if ~io(pn).plists.isparam('timezone'), atest = false; end + if ~io(pn).plists.isparam('timeformat'), atest = false; end + % Check default value + if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end + if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end + if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end + if ~strcmp(io(pn).plists.find('startt'), ''), atest = false; end + if ~strcmp(io(pn).plists.find('endt'), ''), atest = false; end + if ~isequal(io(pn).plists.find('timezone'), 'UTC'), atest = false; end + if ~isequal(io(pn).plists.find('timeformat'), ''), 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 timespan method works with a vector of TIMESPAN objects as input. + % + % </TestDescription> + function result = utp_02 + + % <SyntaxDescription> + % + % Test that the timespan method works with a vector of TIMESPAN objects as input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = timespan(tsv); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the shape of the output TIMESPANs is the same as the input shape. + % 2) Check that each output TIMESPAN is a copy of the input TIMESPAN. + % 3) Check that the copy have an additional history step. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check we have the correct shape + if size(out) ~= size(tsv), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same except the history + if ~eq(tsv(ii), out(ii), ple3), atest = false; end + % Check the history + if ~eq(tsv(ii).hist, out(ii).hist.inhists), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(tsv(ii), out(ii), ple3), 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 timespan method works with a matrix of TIMESPAN objects as input. + % + % </TestDescription> + function result = utp_03 + + % <SyntaxDescription> + % + % Test that the timespan method works with a matrix of TIMESPAN objects as input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = timespan(tsm); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the shape of the output TIMESPANs is the same as the input shape. + % 2) Check that each output TIMESPAN is a copy of the input TIMESPAN. + % 3) Check that the copy have an additional history step. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check we have the correct number of outputs + if size(out) ~= size(tsm), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same except the history + if ~eq(tsm(ii), out(ii), ple3), atest = false; end + % Check the history + if ~eq(tsm(ii).hist, out(ii).hist.inhists), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(tsm(ii), out(ii), ple3), 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 timespan method works with a list of TIMESPAN objects as input. + % + % </TestDescription> + function result = utp_04 + + % <SyntaxDescription> + % + % Test that the timespan method works with a list of TIMESPAN objects as input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = timespan(ts5, ts4, ts3); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the number of elements in 'out' is the same of the + % number in the input. + % 2) Check that each output TIMESPAN is a copy of the input TIMESPAN. + % 3) Check that the copy have an additional history step. + % + % </AlgoDescription> + + atest = true; + tsin = [ts5, ts4, ts3]; + if stest + % <AlgoCode> + % Check we have the correct number of outputs + if numel(out) ~= 3, atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same except the history + if ~eq(tsin(ii), out(ii), ple3), atest = false; end + % Check the history + if ~eq(tsin(ii).hist, out(ii).hist.inhists), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(tsin(ii), out(ii), ple3), 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 timespan method works with a mix of different shaped TIMESPANs as + % input. + % + % </TestDescription> + function result = utp_05 + + % <SyntaxDescription> + % + % Test that the timespan method works with a mix of different shaped TIMESPANs as + % input. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = timespan(ts5,tsv,ts2,tsm,ts4); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the number of elements in 'out' is the same of the + % number in the input. + % 2) Check that each output TIMESPAN is a copy of the input TIMESPAN. + % 3) Check that the copy have an additional history step. + % + % </AlgoDescription> + + atest = true; + tsin = [ts5, reshape(tsv, 1, []), ts2, reshape(tsm, 1, []), ts4]; + if stest + % <AlgoCode> + % Check we have the correct number of outputs + if numel(out) ~= 3+numel(tsv)+numel(tsm), atest = false; end + + % Check that the output is a copy. + for ii = 1:numel(out) + % Check that the output is the same except the history + if ~eq(tsin(ii), out(ii), ple3), atest = false; end + % Check the history + if ~eq(tsin(ii).hist, out(ii).hist.inhists), atest = false; end + % Change the output to make sure that it is a 'real' copy + out(ii).setDescription('my desc'); + if eq(tsin(ii), out(ii), ple3), 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 timespan method properly applies history. + % + % </TestDescription> + function result = utp_06 + + % <SyntaxDescription> + % + % Test that the result of applying the timespan method can be processed back. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out = timespan(ts4); + 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 + % 'timespan'. + % 2) Check that the method rebuild produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + if ~strcmp(out.hist.methodInfo.mname, 'timespan'), atest = false; end + % Check the rebuilt object + 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> + % + % Tests that the timespan method properly applies history to the copy constructor. + % + % </TestDescription> + function result = utp_07 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the 'rebuild' method. + % Test the constructor with a different number of inputs. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out1 = timespan(ts5); + out2 = timespan(ts5, ts4); + out3 = timespan(ts5, ts4, ts3); + out1.setName('my name'); + out2(1).setName('my name'); + out2(2).setName('my name'); + out3(1).setName('my name'); + out3(2).setName('my name'); + out3(3).setName('my name'); + mout = rebuild(out1); + % </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 + % 'timespan'. + % 2) Check that the original objects are not changed by the setter function + % 3) Check that the method rebuild produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + % It is the method 'setName' because we set it in above + if ~strcmp(out1.hist.methodInfo.mname, 'setName'), atest = false; end + % Check next to the last step in the history of 'out' + if ~strcmp(out1.hist.inhists.methodInfo.mname, 'timespan'), atest = false; end + % Check the originals + if strcmp(ts5, 'my name'), atest = false; end + if strcmp(ts4, 'my name'), atest = false; end + if strcmp(ts3, 'my name'), atest = false; end + % Check the rebuilt object + if ~eq(mout, out1, ple2), atest = false; end + % </AlgoCode> + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_07 + + %% UTP_08 + + % <TestDescription> + % + % Tests that the timespan method properly applies history to the read + % MAT-file constructor. + % + % </TestDescription> + function result = utp_08 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the 'rebuild' method. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + filename = 'test_ts.mat'; + ts = timespan(ts4); + save(ts, filename); + + out = timespan(filename); + mout = rebuild(out); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + if ~eq(out, ts, ple1), atest = false; end + % Check the rebuilt object + if ~eq(mout, out, ple2), atest = false; end + % </AlgoCode> + delete(filename); + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_08 + + + %% UTP_09 + + % <TestDescription> + % + % Tests that the timespan method properly applies history to the read + % XML-file constructor. + % + % </TestDescription> + function result = utp_09 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the 'rebuild' method. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + filename = 'test_ts.xml'; + amat = timespan(tsm); + save(amat, filename); + + out = timespan(filename); + mout = rebuild(out); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + rethrow(err); + end + + % <AlgoDescription> + % + % 1) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the algorithm + for kk = 1:numel(out) + if ~eq(out(kk), amat(kk), ple1), atest = false; end + end + + % Check the rebuilt object + for kk = 1:numel(out) + if ~eq(mout(kk), out(kk), ple2), atest = false; end + end + % </AlgoCode> + delete(filename); + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_09 + + %% UTP_10 + + % <TestDescription> + % + % Tests that the timespan method properly applies history to the struct constructor. + % + % </TestDescription> + function result = utp_10 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the 'rebuild' method. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + % silence warnings about converting objects to struct + w = warning('off', 'MATLAB:structOnObject'); + + sts5 = struct(ts5); + sts5.startT = struct(ts5.startT); + sts5.endT = struct(ts5.endT); + sts5.hist = struct(ts5.hist); + + out1 = timespan(struct(ts5)); + out2 = timespan(sts5); + mout1 = rebuild(out1); + mout2 = rebuild(out2); + + % restore warnings + warning(w); + % </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 'timespan'. + % 2) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check that the output is a TIMESPAN object + if ~isa(out1,'timespan'), atest = false; end + if ~isa(out2,'timespan'), atest = false; end + % Check the last step in the history of 'out' + if ~strcmp(out1.hist.methodInfo.mname, 'setName'), atest = false; end + if ~strcmp(out2.hist.methodInfo.mname, 'setName'), atest = false; end + % Check the rebuilt object + if ~eq(mout1, out1, ple2), atest = false; end + if ~eq(mout2, out2, 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_11 + + % <TestDescription> + % + % Tests that the timespan method properly applies history to the + % plist(filename) constructor. + % + % </TestDescription> + function result = utp_11 + + % <SyntaxDescription> + % + % Test that the output can be processed back to an m-file. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + filename1 = 'test_ts.xml'; + filename2 = 'test_ts.mat'; + + f1 = timespan(ts5); + f2 = timespan(ts4); + + save(f1, filename1); + save(f2, filename2); + + out1 = timespan(plist('filename', filename1)); + out2 = timespan(plist('filename', filename2)); + + mout1 = out1.rebuild; + mout2 = out2.rebuild; + + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the save method doesn't change the input object + % 2) Check that the last two entries in the history of 'out' corresponds to + % 'timespan' and 'save' + % 3) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the input object + if ~eq(f1, timespan(ts5), ple1), atest = false; end + if ~eq(f2, timespan(ts4), ple1) , atest = false; end + % The load doesn't have two additionally history steps (save + load) + if ~eq(out1, f1, ple1), atest = false; end + if ~eq(out2, f2, ple1), atest = false; end + % Rebuild object and check the result + if ~eq(mout1, out1, ple2), atest = false; end + if ~eq(mout2, out2, ple2), atest = false; end + % </AlgoCode> + % delete test file + delete(filename1) + delete(filename2) + else + atest = false; + end + + % Return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end % END UTP_11 + + %% UTP_12 + + % <TestDescription> + % + % Tests that the TIMESPAN method properly applies history to the + % plist(conn) constructor. + % + % </TestDescription> + function result = utp_12 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the rebuild method. + % + % </SyntaxDescription> + + conn = utpGetConnection + try + % <SyntaxCode> + + sinfo.conn = conn; + sinfo.experiment_title = 'utp_timespan_timespan_12: submit timespan vector'; + sinfo.experiment_description = 'utp_timespan_timespan_12: &description'; + sinfo.analysis_description = '<utp_timespan_timespan_12>'; + sinfo.quantity = 'none'; + sinfo.keywords = 'none'; + sinfo.reference_ids = ''; + sinfo.additional_comments = 'none'; + sinfo.additional_authors = 'no one'; + + plForAutoTest = plist('no dialog', true, 'use selector', false); + ids = submit(tsv, sinfo, plForAutoTest); + + out = timespan(plist('hostname', utpGetHostname, 'database', utpGetDatabase, 'conn', conn, 'id', ids)); + % </SyntaxCode> + utpCloseConnection(conn); + stest = true; + catch err + disp(err.message) + % Close connection + utpCloseConnection(conn); + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the last entry in the history of 'out' corresponds to + % 'timespan'. + % 2) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + for kk = 1:numel(out) + if ~strcmp(out(kk).hist.methodInfo.mname, 'timespan'), atest = false; end + end + % Check data values + if ~eq(out, tsv, ple3), atest = false; end + % Rebuild object and check the result + mout = rebuild(out); + if ~eq(mout, out, ple3), 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> + % + % Tests that the TIMESPAN method properly applies history to the + % plist(type) constructor. + % + % </TestDescription> + function result = utp_13 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the rebuild method. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + tf = 'HH:MM:SS.FFF'; + tz = 'GMT-04'; + pl1 = plist('startT', time(1), 'endT', 2); + pl2 = plist('startT', '00:01:00.000', 'endT', '00:02:00.000', 'timezone', tz); + pl3 = plist('startT', '00:00:00.000', 'endT', 2, 'timeformat', tf); + + out1 = timespan(pl1); + out2 = timespan(pl2); + out3 = timespan(pl3); + + mout1 = rebuild(out1); + mout2 = rebuild(out2); + mout3 = rebuild(out3); + % </SyntaxCode> + stest = true; + catch err + disp(err.message) + stest = false; + % rethrow(err) + end + + % <AlgoDescription> + % + % 1) Check that the last entry in the history of 'out' corresponds to + % 'timespan'. + % 2) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + if ~strcmp(out1.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out2.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out3.hist.methodInfo.mname, 'timespan'), atest = false; end + % Check first plist + if ~eq(out1.startT, time(1)), atest = false; end + if ~eq(out1.endT, time(2)), atest = false; end + % Check second plist + if ~eq(out2.startT, time(plist('time', '00:01:00', 'timezone', tz))), atest = false; end + if ~eq(out2.endT, time(plist('time', '00:02:00', 'timezone', tz))), atest = false; end + % Check third plist + if ~eq(out3.startT, time(0)), atest = false; end + if ~eq(out3.endT, time(2)), atest = false; end + % Rebuild object and check the result + if ~eq(mout1, out1, ple1), atest = false; end + if ~eq(mout2, out2, ple1), atest = false; end + if ~eq(mout3, out3, ple1), 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_15 + + % <TestDescription> + % + % Tests that the TIMESPAN method properly applies history to + % the start + end time constructor. + % + % </TestDescription> + function result = utp_15 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the rebuild method. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + out1 = timespan('14:00:00', '14:00:05'); + out2 = timespan('00:00:01', time(4)); + out3 = timespan(time(1234), time(2345)); + out4 = timespan(time(1.234), '00:00:05'); + + mout1 = rebuild(out1); + mout2 = rebuild(out2); + mout3 = rebuild(out3); + mout4 = rebuild(out4); + % </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 + % 'timespan'. + % 2) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + if ~strcmp(out1.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out2.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out3.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out4.hist.methodInfo.mname, 'timespan'), atest = false; end + % Check values + if ~eq(out1.startT, time('14:00:00')), atest = false; end + if ~eq(out1.endT, time('14:00:05')), atest = false; end + if ~eq(out2.startT, time('00:00:01')), atest = false; end + if ~eq(out2.endT, time(4)), atest = false; end + if ~eq(out3.startT, time(1234)), atest = false; end + if ~eq(out3.endT, time(2345)), atest = false; end + if ~eq(out4.startT, time(1.234)), atest = false; end + if ~eq(out4.endT, time('00:00:05')), atest = false; end + % Rebuild object and check the result + if ~eq(mout1, out1, ple1), atest = false; end + if ~eq(mout2, out2, ple1), atest = false; end + if ~eq(mout3, out3, ple1), atest = false; end + if ~eq(mout4, out4, ple1), 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> + % + % Tests that the TIMESPAN method properly applies history to the conn+Id constructor. + % + % </TestDescription> + function result = utp_16 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the rebuild method. + % + % </SyntaxDescription> + + conn = utpGetConnection + try + % <SyntaxCode> + + sinfo.conn = conn; + sinfo.experiment_title = 'utp_timespan_timespan_16: submit timespan'; + sinfo.experiment_description = 'utp_timespan_timespan_16: description'; + sinfo.analysis_description = 'utp_timespan_timespan_16'; + sinfo.quantity = 'none'; + sinfo.keywords = 'none'; + sinfo.reference_ids = ''; + sinfo.additional_comments = 'none'; + sinfo.additional_authors = 'no one'; + + plForAutoTest = plist('no dialog', true, 'use selector', false); + [ids] = submit(ts4, sinfo, plForAutoTest); + + out = timespan(conn, ids); + % </SyntaxCode> + utpCloseConnection(conn); + stest = true; + catch err + disp(err.message) + % Close connection + utpCloseConnection(conn); + stest = false; + end + + % <AlgoDescription> + % + % 1) Check that the last entry in the history of 'out' corresponds to + % 'timespan'. + % 2) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + if ~strcmp(out.hist.methodInfo.mname, 'timespan'), atest = false; end + % Check data values + if ~eq(out,ts4, ple3), atest = false; end + % Check the history except the additional 'submit' + 'retrieve' steps + if ~eq(out.hist.inhists, ts4.hist), atest = false; end + % Rebuild object and check the result + mout = rebuild(out); + if ~eq(mout, out, ple3), 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> + % + % Tests that the TIMESPAN method properly applies history to + % the start + end time + format constructor. + % + % </TestDescription> + function result = utp_17 + + % <SyntaxDescription> + % + % Test that the output can be processed back with the rebuild method. + % + % </SyntaxDescription> + + try + % <SyntaxCode> + f1 = 'HH:MM:SS'; + f2 = 'HH:MM:SS'; + f4 = 'HH:MM:SS'; + out1 = timespan('14:00:00', '14:00:05', f1); + out2 = timespan('00:00:01', time(4), f2); + out3 = timespan(time(1.234), time(2.345)); + out4 = timespan(time(1.234), '00:00:05', f4); + + mout1 = rebuild(out1); + mout2 = rebuild(out2); + mout3 = rebuild(out3); + mout4 = rebuild(out4); + % </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 + % 'timespan'. + % 2) Check that the 'rebuild' method produces the same object as 'out'. + % + % </AlgoDescription> + + atest = true; + if stest + % <AlgoCode> + % Check the last step in the history of 'out' + if ~strcmp(out1.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out2.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out3.hist.methodInfo.mname, 'timespan'), atest = false; end + if ~strcmp(out4.hist.methodInfo.mname, 'timespan'), atest = false; end + % Check first object + if ~eq(out1.startT, time('14:00:00', f1)), atest = false; end + if ~eq(out1.endT, time('14:00:05', f1)), atest = false; end + % Check second object + if ~eq(out2.startT, time('00:00:01', f2)), atest = false; end + if ~eq(out2.endT, time(4.000)), atest = false; end + % Check third object + if ~eq(out3.startT, time(1.234)), atest = false; end + if ~eq(out3.endT, time(2.345)), atest = false; end + % Check fourth object + if ~eq(out4.startT, time(1.234)), atest = false; end + if ~eq(out4.endT, time('00:00:05', f4)), atest = false; end + % Rebuild object and check the result + if ~eq(mout1, out1, ple1), atest = false; end + if ~eq(mout2, out2, ple1), atest = false; end + if ~eq(mout3, out3, ple1), atest = false; end + if ~eq(mout4, out4, ple1), 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