Mercurial > hg > ltpda
view testing/utp_1.1/utps/smodel/utp_smodel_setParams.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_SMODEL_SETPARAMS a set of UTPs for the smodel/setParams method % % M Hewitson 06-08-08 % % $Id: utp_smodel_setParams.m,v 1.2 2011/05/10 04:53:37 mauro Exp $ % % <MethodDescription> % % The setParams method of the smodel class sets the 'params' property and % in some cases also the 'values' property % % </MethodDescription> function results = utp_smodel_setParams(varargin) % Check the inputs if nargin == 0 % Some keywords cl = 'smodel'; mthd = 'setParams'; disp('******************************************************'); disp(['**** Running UTPs for ' cl '/' mthd]); disp('******************************************************'); s0 = smodel(); s1 = smodel('a*x1 + b*x2 + c*x3'); s1.setParams({'a', 'b'}); s1.setName(); s2 = smodel('a*x1 + b*x2 + c*x3'); s2.setParams({'a', 'b'}, [1 2]); s2.setName(); s3 = smodel('a*x1 + b*x2 + c*x3'); s3.setParams({'a', 'b'}, [1 2]); s3.setName(); sv = [s1, s2, s1]; sm = [s1, s2, s1; s1, s2, s1]; % Exception list for the UTPs: [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); % The setter method have different possibilities to set a property args1 = {{'a', 'b'}}; % obj.setParams({'a', 'b'}) args2 = {{'a', 'b'}, [1 2]}; % obj.setParams({'a', 'b'}, [1 2]) args3 = {{'a', 'b'}, {1 2}}; % obj.setParams({'a', 'b'}, {1 2}) args4 = {'a', 3}; % obj.setParams('a', 3) args5 = {'a1', 'a4'}; % obj.setParams('a1', 'a4') args6 = {plist('params', 'a')}; args7 = {plist('params', {'a', 'b'})}; args8 = {plist('params', 'a', 'values', 1)}; args9 = {plist('params', {'a', 'b'}, 'values', [1 2])}; % Run the general tests results(1) = utp_01(); results(2) = utp_genericAnyShape(mthd, s0, args1, @algoTests); results(3) = utp_genericAnyShape(mthd, s0, args2, @algoTests); results(4) = utp_genericAnyShape(mthd, s1, args3, @algoTests); results(5) = utp_genericAnyShape(mthd, s2, args4, @algoTests); results(6) = utp_genericAnyShape(mthd, s3, args5, @algoTests); results(7) = utp_genericAnyShape(mthd, s0, args6, @algoTests); results(8) = utp_genericAnyShape(mthd, s0, args7, @algoTests); results(9) = utp_genericAnyShape(mthd, s1, args8, @algoTests); results(10) = utp_genericAnyShape(mthd, s1, args9, @algoTests); results(11) = utp_genericAnyShape(mthd, sv, args3, @algoTests); results(12) = utp_genericAnyShape(mthd, sm, args8, @algoTests); results(13) = utp_genericList(mthd, s1, s2, s3, args7, @algoTests); results(14) = utp_genericHistory(mthd, s1, args2, ple2); results(15) = utp_genericModify(mthd, s1, args5, @algoTests, ple1); results(16) = utp_genericOutput(mthd, s1, s2, args2, @algoTests, ple2); % test the outputs 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 % Check that the property have the correct value function atest = algoTests(in, out, idx, argsin) atest = true; % Check that the input and output objects are the same except the % property 'params' and the history ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', 'params', 'values'}); if ~eq(in(idx), out(idx), ple), atest = false; end if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end % Check that the parameter gets the correct value. values = {}; if isa(argsin{1}, 'plist') && argsin{1}.isparam('params') argsin = argsin{1}; % The value was set with a plist. params = cellstr(argsin.find('params')); if argsin.isparam('values') values = argsin.find('values'); end elseif numel(argsin) == 1 && iscell(argsin{1}) params = argsin{1}; elseif numel(argsin) == 2 && iscell(argsin{1}) && ( iscell(argsin{2}) || isnumeric(argsin{2})) params = argsin{1}; if iscell(argsin{2}) values = argsin{2}; else values = argsin{2}; end elseif numel(argsin) == 2 && ischar(argsin{1}) && isnumeric(argsin{2}) params = argsin(1); values = argsin(2); elseif iscellstr(argsin) params = argsin; end if isnumeric(values) values = num2cell(values); end p = in(idx).params; v = in(idx).values; if ~isempty(values) && isempty(v) v = cell(size(p)); end for ll = 1:numel(params) paramsIdx = strcmp(p, params{ll}); if any(paramsIdx) if ~isempty(values) v{paramsIdx} = values{ll}; end else % Append the alias key-value pair p = [p params(ll)]; if ~isempty(values) v = [v values(ll)]; elseif ~isempty(v) v = [v cell(1)]; end end end % Check 'params' and 'values' if ~isequal(out(idx).params, p), atest = false; end if ~isequal(out(idx).values, v), atest = false; end % Check if we have specified some values that the number of values ans % params are the same if ~isempty(values) if numel(out(idx).params) ~= numel(out(idx).values), atest = false; end end 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) = feval('smodel.getInfo', mthd, 'none'); % Call for all sets io(2) = feval('smodel.getInfo', mthd); % Call for each set for kk=1:numel(io(2).sets) io(kk+2) = feval('smodel.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 ~= 2, atest = false; end % Check key if ~io(3).plists.isparam('params'), atest = false; end if ~io(3).plists.isparam('values'), atest = false; end % Check default value if ~isEmptyCell(io(3).plists.find('params')), atest = false; end if ~isEmptyCell(io(3).plists.find('values')), atest = false; end % Check options if ~isequal(io(3).plists.getOptionsForParam('params'), {{}}), atest = false; end if ~isequal(io(3).plists.getOptionsForParam('values'), {{}}), 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 end