Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/plist/utp_plist_nparams.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_PLIST_NPARAMS a set of UTPs for the plist/nparams method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_plist_nparams.m,v 1.3 2009/07/22 14:02:26 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The nparams method of the plist class returns the number of param objects | |
11 % in the list | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_plist_nparams(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'plist'; | |
22 mthd = 'nparams'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test PLIST objects | |
30 [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist; | |
31 | |
32 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Run the tests | |
36 results = [results utp_01]; % getInfo call | |
37 results = [results utp_02]; % Vector input | |
38 results = [results utp_03]; % Matrix input | |
39 results = [results utp_04]; % List input | |
40 results = [results utp_05]; % Test with mixed input | |
41 results = [results utp_06]; % Test the modify call works | |
42 | |
43 disp('Done.'); | |
44 disp('******************************************************'); | |
45 | |
46 elseif nargin == 1 % Check for UTP functions | |
47 if strcmp(varargin{1}, 'isutp') | |
48 results = 1; | |
49 else | |
50 results = 0; | |
51 end | |
52 else | |
53 error('### Incorrect inputs') | |
54 end | |
55 | |
56 %% UTP_01 | |
57 | |
58 % <TestDescription> | |
59 % | |
60 % Tests that the getInfo call works for this method. | |
61 % | |
62 % </TestDescription> | |
63 function result = utp_01 | |
64 | |
65 | |
66 % <SyntaxDescription> | |
67 % | |
68 % Test that the getInfo call works for no sets, all sets, and each set | |
69 % individually. | |
70 % | |
71 % </SyntaxDescription> | |
72 | |
73 try | |
74 % <SyntaxCode> | |
75 % Call for no sets | |
76 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
77 % Call for all sets | |
78 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
79 % Call for each set | |
80 for kk=1:numel(io(2).sets) | |
81 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
82 end | |
83 % </SyntaxCode> | |
84 stest = true; | |
85 catch err | |
86 disp(err.message) | |
87 stest = false; | |
88 end | |
89 | |
90 % <AlgoDescription> | |
91 % | |
92 % 1) Check that getInfo call returned an minfo object in all cases. | |
93 % 2) Check that all plists have the correct parameters. | |
94 % | |
95 % </AlgoDescription> | |
96 | |
97 atest = true; | |
98 if stest | |
99 % <AlgoCode> | |
100 % check we have minfo objects | |
101 if isa(io, 'minfo') | |
102 % SET 'None' | |
103 if ~isempty(io(1).sets), atest = false; end | |
104 if ~isempty(io(1).plists), atest = false; end | |
105 % Check all Sets | |
106 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
107 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
108 % SET 'Default' | |
109 if io(3).plists.nparams ~= 0, atest = false; end | |
110 % Check key | |
111 % Check default value | |
112 % Check options | |
113 end | |
114 % </AlgoCode> | |
115 else | |
116 atest = false; | |
117 end | |
118 | |
119 % Return a result structure | |
120 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
121 end % END UTP_01 | |
122 | |
123 %% UTP_02 | |
124 | |
125 % <TestDescription> | |
126 % | |
127 % Tests that the nparams method works with a vector of PLIST objects as input. | |
128 % | |
129 % </TestDescription> | |
130 function result = utp_02 | |
131 | |
132 % <SyntaxDescription> | |
133 % | |
134 % Test that the nparams method returns the number of PARAM objects in | |
135 % the PLIST objects. | |
136 % | |
137 % </SyntaxDescription> | |
138 | |
139 try | |
140 % <SyntaxCode> | |
141 out = nparams(plv); | |
142 % </SyntaxCode> | |
143 stest = true; | |
144 catch err | |
145 disp(err.message) | |
146 stest = false; | |
147 end | |
148 | |
149 % <AlgoDescription> | |
150 % | |
151 % 1) Check that the number of outputs is the same as the number of | |
152 % input PLIST objects. | |
153 % 2) Check the output. | |
154 % | |
155 % </AlgoDescription> | |
156 | |
157 atest = true; | |
158 if stest | |
159 % <AlgoCode> | |
160 % Check we have the correct number of outputs | |
161 if numel(out) ~= numel(plv), atest = false; end | |
162 % Check the output | |
163 for ii = 1:numel(plv) | |
164 if numel(plv(ii).params) ~= out(ii), atest = false; end | |
165 end | |
166 % </AlgoCode> | |
167 else | |
168 atest = false; | |
169 end | |
170 | |
171 % Return a result structure | |
172 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
173 end % END UTP_02 | |
174 | |
175 %% UTP_03 | |
176 | |
177 % <TestDescription> | |
178 % | |
179 % Tests that the nparams method works with a vector of PLIST objects as input. | |
180 % | |
181 % </TestDescription> | |
182 function result = utp_03 | |
183 | |
184 % <SyntaxDescription> | |
185 % | |
186 % Test that the nparams method returns the number of PARAM objects in | |
187 % the PLIST objects. | |
188 % | |
189 % </SyntaxDescription> | |
190 | |
191 try | |
192 % <SyntaxCode> | |
193 out = nparams(plm); | |
194 % </SyntaxCode> | |
195 stest = true; | |
196 catch err | |
197 disp(err.message) | |
198 stest = false; | |
199 end | |
200 | |
201 % <AlgoDescription> | |
202 % | |
203 % 1) Check that the number of outputs is the same as the number of | |
204 % input PLIST objects. | |
205 % 2) Check the output. | |
206 % | |
207 % </AlgoDescription> | |
208 | |
209 atest = true; | |
210 if stest | |
211 % <AlgoCode> | |
212 % Check we have the correct number of outputs | |
213 if numel(out) ~= numel(plm), atest = false; end | |
214 % Check the output | |
215 for ii = 1:numel(plm) | |
216 if numel(plm(ii).params) ~= out(ii), atest = false; end | |
217 end | |
218 % </AlgoCode> | |
219 else | |
220 atest = false; | |
221 end | |
222 % Return a result structure | |
223 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
224 end % END UTP_03 | |
225 | |
226 %% UTP_04 | |
227 | |
228 % <TestDescription> | |
229 % | |
230 % Tests that the nparams method works with a list of PLIST objects as input. | |
231 % | |
232 % </TestDescription> | |
233 function result = utp_04 | |
234 | |
235 % <SyntaxDescription> | |
236 % | |
237 % Test that the nparams method returns the number of PARAM objects in | |
238 % the PLIST objects. | |
239 % | |
240 % </SyntaxDescription> | |
241 | |
242 try | |
243 % <SyntaxCode> | |
244 out = nparams(pl1, pl2, pl3); | |
245 % </SyntaxCode> | |
246 stest = true; | |
247 catch err | |
248 disp(err.message) | |
249 stest = false; | |
250 end | |
251 | |
252 % <AlgoDescription> | |
253 % | |
254 % 1) Check that the number of outputs is the same as the number of | |
255 % input PLIST objects. | |
256 % 2) Check the output. | |
257 % | |
258 % </AlgoDescription> | |
259 | |
260 atest = true; | |
261 plin = [pl1, pl2, pl3]; | |
262 if stest | |
263 % <AlgoCode> | |
264 % Check we have the correct number of outputs | |
265 if numel(out) ~= numel(plin), atest = false; end | |
266 % Check the output | |
267 for ii = 1:numel(plin) | |
268 if numel(plin(ii).params) ~= out(ii), atest = false; end | |
269 end | |
270 % </AlgoCode> | |
271 else | |
272 atest = false; | |
273 end | |
274 | |
275 % Return a result structure | |
276 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
277 end % END UTP_04 | |
278 | |
279 %% UTP_05 | |
280 | |
281 % <TestDescription> | |
282 % | |
283 % Tests that the nparams method works with a mix of different shaped PLIST | |
284 % objects as input. | |
285 % | |
286 % </TestDescription> | |
287 function result = utp_05 | |
288 | |
289 % <SyntaxDescription> | |
290 % | |
291 % Test that the nparams method returns the number of PARAM objects in | |
292 % the PLIST objects. | |
293 % | |
294 % </SyntaxDescription> | |
295 | |
296 try | |
297 % <SyntaxCode> | |
298 out = nparams(plm, pl1, plv); | |
299 % </SyntaxCode> | |
300 stest = true; | |
301 catch err | |
302 disp(err.message) | |
303 stest = false; | |
304 end | |
305 | |
306 % <AlgoDescription> | |
307 % | |
308 % 1) Check that the number of outputs is the same as the number of | |
309 % input PLIST objects. | |
310 % 2) Check the output. | |
311 % | |
312 % </AlgoDescription> | |
313 | |
314 atest = true; | |
315 plin = [reshape(plm, 1, []), pl1, reshape(plv, 1, [])]; | |
316 if stest | |
317 % <AlgoCode> | |
318 % Check we have the correct number of outputs | |
319 if numel(out) ~= numel(plin), atest = false; end | |
320 % Check the output | |
321 for ii = 1:numel(plin) | |
322 if numel(plin(ii).params) ~= out(ii), atest = false; end | |
323 end | |
324 | |
325 % </AlgoCode> | |
326 else | |
327 atest = false; | |
328 end | |
329 | |
330 % Return a result structure | |
331 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
332 end % END UTP_05 | |
333 | |
334 %% UTP_06 | |
335 | |
336 % <TestDescription> | |
337 % | |
338 % Tests that the nparams method applies the modify command | |
339 % | |
340 % </TestDescription> | |
341 function result = utp_06 | |
342 | |
343 % <SyntaxDescription> | |
344 % | |
345 % Test that the nparams method can used in the modifier style. | |
346 % | |
347 % </SyntaxDescription> | |
348 | |
349 try | |
350 % <SyntaxCode> | |
351 out1 = pl1.nparams(); | |
352 out2 = plv.nparams(); | |
353 % </SyntaxCode> | |
354 stest = true; | |
355 catch err | |
356 disp(err.message) | |
357 stest = false; | |
358 end | |
359 | |
360 % <AlgoDescription> | |
361 % | |
362 % 1) Check the output. | |
363 % | |
364 % </AlgoDescription> | |
365 | |
366 atest = true; | |
367 if stest | |
368 % <AlgoCode> | |
369 if out1 ~= numel(pl1.params), atest = false; end | |
370 if out2 ~= [3 6 4], atest = false; end | |
371 % </AlgoCode> | |
372 else | |
373 atest = false; | |
374 end | |
375 | |
376 % Return a result structure | |
377 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
378 end % END UTP_06 | |
379 | |
380 end |