Mercurial > hg > ltpda
diff testing/utp_1.1/utps/smodel/utp_smodel_setXvals.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/smodel/utp_smodel_setXvals.m Tue Dec 06 18:42:11 2011 +0100 @@ -0,0 +1,128 @@ +% UTP_SMODEL_SETXVALS a set of UTPs for the smodel/setXvals method +% +% M Hewitson 06-08-08 +% +% $Id: utp_smodel_setXvals.m,v 1.3 2011/04/11 19:45:45 ingo Exp $ +% + +% <MethodDescription> +% +% The setXvals method of the smodel class sets the Xvals property. +% +% </MethodDescription> + +function results = utp_smodel_setXvals(varargin) + + % Check the inputs + if nargin == 0 + + % Some keywords + cl = 'smodel'; + mthd = 'setXvals'; + prop = 'xvals'; + + disp('******************************************************'); + disp(['**** Running UTPs for ' cl '/' mthd]); + disp('******************************************************'); + + % Test objects + s1 = smodel('a1*x1 + a2*x2 + a3*x3'); + s1.setName(); + + s2 = smodel('a1*x1 + a2*x2'); + s2.setName(); + + s3 = smodel('a1*x1'); + 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 + val1 = 1:1e3; % obj.setXvals(val1) + val2 = ao(1:1e3,randn(1e3,1)); % obj.setXvals(val2) + val3 = plist(prop, 1:2:2e3); % obj.setXvals(plist('Xvals', 'm') + val4 = {val1, val2, val3}; % obj.setXvals(val1, val2, val3) + val5 = {{val1, val2, val3}}; % obj.setXvals({val1, val2, val3}) + val6 = {{val1, val2, val3}, val1, val2}; % obj.setXvals({val1, val2, val3}, val1, val2) + + % Run the general tests + results(1) = utp_genericSet_minfo(mthd, s1, prop, @algoTests_minfo); + results(2) = utp_genericAnyShape(mthd, sv, val1, @algoTests); + results(3) = utp_genericAnyShape(mthd, sv, val2, @algoTests); + results(4) = utp_genericAnyShape(mthd, sv, val3, @algoTests); + results(5) = utp_genericAnyShape(mthd, sv, val4, @algoTests); + results(6) = utp_genericAnyShape(mthd, sv, val5, @algoTests); + results(7) = utp_genericAnyShape(mthd, sv, val6, @algoTests); + results(8) = utp_genericAnyShape(mthd, sm, val6, @algoTests); + results(9) = utp_genericList(mthd, s1, s2, s3, val1, @algoTests); + results(10) = utp_genericList(mthd, s1, sv, s3, val3, @algoTests); + results(11) = utp_genericHistory(mthd, s1, val1, ple2); + results(12) = utp_genericModify(mthd, s1, val5, @algoTests, ple1); % test the modifier call + results(13) = utp_genericOutput(mthd, s1, s2, val6, @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 default value un the PLIST + function atest = algoTests_minfo(defVal) + atest = true; + % Check default value for the key 'Xvals' + if ~isequal(defVal, {}), atest = false; end + end + + % Check that the property have the correct value + function atest = algoTests(in, out, idx, value) + atest = true; + % Check that the input and output objects are the same except the + % property 'Xvals' and the history + ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', prop}); + if ~eq(in(idx), out(idx), ple), atest = false; end + if ~eq(in(idx).hist, out(idx).hist.inhists(1)), atest = false; end + % Check that the parameter gets the correct value. + if isa(value, 'plist') && value.nparams == 1 && value.isparam(prop) + % The value was set with a plist. + values = processValues([], value.find(prop)); + if ~isequal(out(idx).(prop), values), atest = false; end + else + values = processValues([], value); + if ~isequal(out(idx).(prop), values), atest = false; end + end + end + + function values = processValues(values, val) + switch class(val) + case 'cell' + for ii=1:numel(val); + values = processValues(values, val{ii}); + end + case 'double' + values = [values {val}]; + case 'ao' + ax = 'y'; % Special case: Only check the 'y'-axis + for ii=1:numel(val) + values = [values {val(ii).(ax)}]; + end + case 'plist' + if length(val) == 1 && isa(val, 'plist') && isparam(val, prop) + vals = find(val, prop); + values = processValues(values, vals); + end + otherwise + end + end + +end