Mercurial > hg > ltpda
view testing/utp_1.1/utps/plist/utp_plist_remove.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_PLIST_REMOVE a set of UTPs for the plist/remove method % % M Hewitson 06-08-08 % % $Id: utp_plist_remove.m,v 1.2 2009/07/22 14:02:26 ingo Exp $ % % <MethodDescription> % % The remove method of the plist class remove a parameter from the % parameter list. % % </MethodDescription> function results = utp_plist_remove(varargin) % Check the inputs if nargin == 0 % Some keywords class = 'plist'; mthd = 'remove'; results = []; disp('******************************************************'); disp(['**** Running UTPs for ' class '/' mthd]); disp('******************************************************'); % Test PLIST objects pl1 = plist('a', 1, 'b', 2, 'c', 3); pl2 = plist('b', 2, 'd', 4); pl3 = plist('c', 3, 'b', 2); plv = [pl1, pl2, pl3]; plm = [pl1, pl2; pl3 pl1]; % 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 the modify call works results = [results utp_07]; % Test with different inputs for the key/value pair results = [results utp_08]; % Test negative case. 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' 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 numel(io(2).plists) ~= numel(io(2).sets), atest = false; end %%%%%%%%%% SET 'Default' if io(3).plists.nparams ~= 1, atest = false; end % Check key if ~io(3).plists.isparam('key'), atest = false; end % Check default value if ~isEmptyChar(io(3).plists.find('key')), atest = false; end % Check options if ~isequal(io(3).plists.getOptionsForParam('key'), {''}), 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 remove method works with a vector of PLIST objects as input. % % </TestDescription> function result = utp_02 % <SyntaxDescription> % % Test that the remove method remove the 'key' from all PLIST objects % in the vector. % % </SyntaxDescription> try % <SyntaxCode> out = remove(plv, 'b'); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the shape of the output is the same as the shape of the input % 2) Check that the output PLIST doesn't contains the key. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check that the shape of the output is the same as the shape of the input if ~isa(out, 'plist') && size(out) == size(plv), atest = false; end % Check that the output doesn't have the key for ii = 1:numel(out) if ~isempty(out(ii).find('b')), atest = false; end if ~isnumeric(out(ii).find('b')), 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 remove method works with a matrix of PLIST objects as input. % % </TestDescription> function result = utp_03 % <SyntaxDescription> % % Test that the remove method remove the 'key' from all PLIST objects % in the matrix. % % </SyntaxDescription> try % <SyntaxCode> out = remove(plm, 'b'); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the shape of the output is the same as the shape of the input % 2) Check that the output PLIST doesn't contains the key. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check that the shape of the output is the same as the shape of the input if ~isa(out, 'plist') && size(out) == size(plm), atest = false; end % Check that the output doesn't have the key for ii = 1:numel(out) if ~isempty(out(ii).find('b')), atest = false; end if ~isnumeric(out(ii).find('b')), 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 remove method works with a list of PLIST objects as input. % % </TestDescription> function result = utp_04 % <SyntaxDescription> % % Test that the remove method remove the 'key' from all PLIST objects % of the input. % % </SyntaxDescription> try % <SyntaxCode> out = remove(pl1, pl2, pl3, 'b'); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the shape of the output is the same as the shape of the input % 2) Check that the output PLIST doesn't contains the key. % % </AlgoDescription> atest = true; plin = [pl1, pl2, pl3]; if stest % <AlgoCode> % Check that the shape of the output is the same as the shape of the input if ~isa(out, 'plist') && size(out) == size(plin), atest = false; end % Check that the output doesn't have the key for ii = 1:numel(out) if ~isempty(out(ii).find('b')), atest = false; end if ~isnumeric(out(ii).find('b')), 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 remove method works with a mix of different shaped PLIST % objects as input. % % </TestDescription> function result = utp_05 % <SyntaxDescription> % % Test that the remove method remove the 'key' from all PLIST objects % of the input. % % </SyntaxDescription> try % <SyntaxCode> out = remove(plm, plv, pl1, 'b'); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that the shape of the output is the same as the shape of the input % 2) Check that the output PLIST doesn't contains the key. % % </AlgoDescription> atest = true; plin = [reshape(plm, 1, []), reshape(plv, 1, []), pl1]; if stest % <AlgoCode> % Check that the shape of the output is the same as the shape of the input if ~isa(out, 'plist') && size(out) == size(plin), atest = false; end % Check that the output doesn't have the key for ii = 1:numel(out) if ~isempty(out(ii).find('b')), atest = false; end if ~isnumeric(out(ii).find('b')), 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 remove method applies the modify command % % </TestDescription> function result = utp_06 % <SyntaxDescription> % % Test that the remove method can modify the input PLIST by calling with no % output and that the method doesn't change the input of the function % notation (with a equal sign). % % </SyntaxDescription> try % <SyntaxCode> % copy at1 to work with pleq = plist(pl1); plmo = plist(pl1); % modify ain out = pleq.remove('b'); plmo.remove('b'); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check that 'out' and 'pleq' are now different. % 2) Check that 'plmo' and 'out' are the same. % 3) Check that 'out' and 'plmo' don't have the key % 4) Check that pleq doesn't have the key % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check that 'out' and 'pleq' are not the same if eq(out, pleq, ple1), atest = false; end % Check that 'out' don't have key and 'pleq' still have it if ~isempty(out.find('b')), atest = false; end if isempty(pleq.find('b')), atest = false; end % Check 'plmo' don't have the key if ~isempty(plmo.find('b')), atest = false; end % Check that 'out' and plmo are the same if ~eq(out, plmo, ple1), 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> % % Test the remove method that it removes the parameter which is defined % as an index or as a key % % </TestDescription> function result = utp_07 % <SyntaxDescription> % % Test the remove method that it removes the parameter which is defined % as an index or as a key % % </SyntaxDescription> try % <SyntaxCode> idx = 2; out1 = pl1.remove('b'); out2 = pl1.remove(idx); % </SyntaxCode> stest = true; catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Check the output. % % </AlgoDescription> atest = true; if stest % <AlgoCode> % Check the correct number of parameter if out1.nparams ~= pl1.nparams - 1, atest = false; end if out2.nparams ~= pl1.nparams - 1, atest = false; end % Check the correct number of parameter if ~isempty(out1.find('b')), atest = false; end key = pl1.params(idx).key; if ~isempty(out1.find(key)), 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> % % Test the remove method in a negative case that the key is not in the % paramter list. % % </TestDescription> function result = utp_08 % <SyntaxDescription> % % The remove method doesn't throwns an error if the key doesn't exist % in the parameter list. % % </SyntaxDescription> try % <SyntaxCode> pl1.remove('key'); stest = true; % </SyntaxCode> catch err disp(err.message) stest = false; end % <AlgoDescription> % % 1) Nothing to test. % % </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_08 end