comparison testing/utp_1.1/utps/smodel/utp_smodel_setParameters.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
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % UTP_SMODEL_SETPARAMETERS a set of UTPs for the smodel/setParameters method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_smodel_setParameters.m,v 1.1 2011/04/17 15:47:57 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The setParameters method of the smodel class sets the 'params' and
11 % 'values' properties.
12 %
13 % </MethodDescription>
14
15 function results = utp_smodel_setParameters(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 cl = 'smodel';
22 mthd = 'setParameters';
23
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' cl '/' mthd]);
26 disp('******************************************************');
27
28 % Test objects
29 s1 = smodel('a*x1 + b*x2 + c*x3');
30 s1.setParams('a', 'b', 'c');
31 s1.setName();
32
33 s2 = smodel('a*x1 + c*x2');
34 s1.setParams('c');
35 s2.setName();
36
37 s3 = smodel('a*x1');
38 s1.setParams('a');
39 s3.setName();
40
41 sv = [s1, s2, s1];
42 sm = [s1, s2, s1; s1, s2, s1];
43
44 % Exception list for the UTPs:
45 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
46
47 % The setter method have different possibilities to set a property
48 args1 = {{'a', 'b'}};
49 args2 = {'a', 'b', 'c'};
50 args3 = {{'a', 'b'}, [1 2]};
51 args4 = {{'a', 'b'}, {1 2}};
52 args5 = {'b', 1};
53 args6 = {'a', 1, 'b', 2, 'c', 3};
54 args7 = {plist('params', 'a')};
55 args8 = {plist('params', {'a', 'b'})};
56 args9 = {plist('params', {'c', 'b'}, 'values', [1 2])};
57 args10 = {plist('params', {'a', 'e'}, 'values', {1 2})};
58
59 % Run the general tests
60 results(1) = utp_01();
61 results(2) = utp_genericAnyShape(mthd, s1, args1, @algoTests);
62 results(3) = utp_genericAnyShape(mthd, s1, args2, @algoTests);
63 results(4) = utp_genericAnyShape(mthd, s1, args3, @algoTests);
64 results(5) = utp_genericAnyShape(mthd, s1, args4, @algoTests);
65 results(6) = utp_genericAnyShape(mthd, s1, args5, @algoTests);
66 results(7) = utp_genericAnyShape(mthd, s1, args6, @algoTests);
67 results(8) = utp_genericAnyShape(mthd, s1, args7, @algoTests);
68 results(9) = utp_genericAnyShape(mthd, s1, args8, @algoTests);
69 results(10) = utp_genericAnyShape(mthd, s1, args9, @algoTests);
70 results(11) = utp_genericAnyShape(mthd, s1, args10,@algoTests);
71 results(12) = utp_genericAnyShape(mthd, sv, args5, @algoTests);
72 results(13) = utp_genericAnyShape(mthd,sm, args10,@algoTests);
73 results(14) = utp_genericList(mthd, s1, s2, s3, args4, @algoTests);
74 results(15) = utp_genericHistory(mthd, s1, args5, ple2);
75 results(10) = utp_genericModify(mthd, s1, args5, @algoTests, ple1);
76 results(11) = utp_genericOutput(mthd, s1, s2, args2, @algoTests, ple2); % test the outputs
77
78 disp('Done.');
79 disp('******************************************************');
80
81 elseif nargin == 1 % Check for UTP functions
82 if strcmp(varargin{1}, 'isutp')
83 results = 1;
84 else
85 results = 0;
86 end
87 else
88 error('### Incorrect inputs')
89 end
90
91 % Check that the property have the correct value
92 function atest = algoTests(in, out, idx, argsin)
93 atest = true;
94 % Check that the input and output objects are the same except the
95 % properties 'params', 'values' and the history
96 ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', 'params', 'values'});
97 if ~eq(in(idx), out(idx), ple), atest = false; end
98 if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end
99 % Check that the parameter gets the correct value.
100 values = {};
101 if isa(argsin{1}, 'plist') && argsin{1}.isparam('params')
102 argsin = argsin{1};
103 % The value was set with a plist.
104 names = cellstr(argsin.find('params'));
105 if argsin.isparam('values')
106 values = argsin.find('values');
107 if isnumeric(values)
108 values = num2cell(values);
109 end
110 end
111 else
112 if numel(argsin) == 1 && iscell(argsin{1})
113 names = argsin{1};
114 elseif ~isempty(argsin) && iscellstr(argsin)
115 names = argsin;
116 elseif numel(argsin) == 2 && iscell(argsin{1}) && isnumeric(argsin{2})
117 names = argsin{1};
118 values = num2cell(argsin{2});
119 elseif numel(argsin) == 2 && iscell(argsin{1}) && iscell(argsin{2})
120 names = argsin{1};
121 values = argsin{2};
122 else
123 nArgsin = numel(argsin);
124 names = argsin(1:2:nArgsin);
125 values = argsin(2:2:nArgsin);
126 end
127 end
128
129 % Check 'params' and 'values'
130 if ~isequal(out(idx).params, names), atest = false; end
131 if ~isequal(out(idx).values, values), atest = false; end
132
133 % Check the numbe of values
134 if ~isempty(out(idx).values)
135 if numel(out(idx).values) ~= numel(out(idx).params), atest = false; end
136 end
137 end
138
139 %% UTP_01
140
141 % <TestDescription>
142 %
143 % Tests that the getInfo call works for this method.
144 %
145 % </TestDescription>
146 function result = utp_01
147
148
149 % <SyntaxDescription>
150 %
151 % Test that the getInfo call works for no sets, all sets, and each set
152 % individually.
153 %
154 % </SyntaxDescription>
155
156 try
157 % <SyntaxCode>
158 % Call for no sets
159 io(1) = feval('smodel.getInfo', mthd, 'none');
160 % Call for all sets
161 io(2) = feval('smodel.getInfo', mthd);
162 % Call for each set
163 for kk=1:numel(io(2).sets)
164 io(kk+2) = feval('smodel.getInfo', mthd, io(2).sets{kk});
165 end
166 % </SyntaxCode>
167 stest = true;
168 catch err
169 disp(err.message)
170 stest = false;
171 end
172
173 % <AlgoDescription>
174 %
175 % 1) Check that getInfo call returned an minfo object in all cases.
176 % 2) Check that all plists have the correct parameters.
177 %
178 % </AlgoDescription>
179
180 atest = true;
181 if stest
182 % <AlgoCode>
183 % check we have minfo objects
184 if isa(io, 'minfo')
185 % SET 'None'
186 if ~isempty(io(1).sets), atest = false; end
187 if ~isempty(io(1).plists), atest = false; end
188 % Check all Sets
189 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
190 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
191 % SET 'Default'
192 if io(3).plists.nparams ~= 2, atest = false; end
193 % Check key
194 if ~io(3).plists.isparam('params'), atest = false; end
195 if ~io(3).plists.isparam('values'), atest = false; end
196 % Check default value
197 if ~isEmptyCell(io(3).plists.find('params')), atest = false; end
198 if ~isEmptyCell(io(3).plists.find('values')), atest = false; end
199 % Check options
200 if ~isequal(io(3).plists.getOptionsForParam('params'), {{}}), atest = false; end
201 if ~isequal(io(3).plists.getOptionsForParam('values'), {{}}), atest = false; end
202 end
203 % </AlgoCode>
204 else
205 atest = false;
206 end
207
208 % Return a result structure
209 result = utp_prepare_result(atest, stest, dbstack, mfilename);
210 end % END UTP_01
211
212 end