Mercurial > hg > ltpda
comparison 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 |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_PLIST_REMOVE a set of UTPs for the plist/remove method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_plist_remove.m,v 1.2 2009/07/22 14:02:26 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The remove method of the plist class remove a parameter from the | |
11 % parameter list. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_plist_remove(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'plist'; | |
22 mthd = 'remove'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test PLIST objects | |
30 pl1 = plist('a', 1, 'b', 2, 'c', 3); | |
31 pl2 = plist('b', 2, 'd', 4); | |
32 pl3 = plist('c', 3, 'b', 2); | |
33 plv = [pl1, pl2, pl3]; | |
34 plm = [pl1, pl2; pl3 pl1]; | |
35 | |
36 % Exception list for the UTPs: | |
37 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
38 | |
39 % Run the tests | |
40 results = [results utp_01]; % getInfo call | |
41 results = [results utp_02]; % Vector input | |
42 results = [results utp_03]; % Matrix input | |
43 results = [results utp_04]; % List input | |
44 results = [results utp_05]; % Test with mixed input | |
45 results = [results utp_06]; % Test the modify call works | |
46 results = [results utp_07]; % Test with different inputs for the key/value pair | |
47 results = [results utp_08]; % Test negative case. | |
48 | |
49 disp('Done.'); | |
50 disp('******************************************************'); | |
51 | |
52 elseif nargin == 1 % Check for UTP functions | |
53 if strcmp(varargin{1}, 'isutp') | |
54 results = 1; | |
55 else | |
56 results = 0; | |
57 end | |
58 else | |
59 error('### Incorrect inputs') | |
60 end | |
61 | |
62 %% UTP_01 | |
63 | |
64 % <TestDescription> | |
65 % | |
66 % Tests that the getInfo call works for this method. | |
67 % | |
68 % </TestDescription> | |
69 function result = utp_01 | |
70 | |
71 | |
72 % <SyntaxDescription> | |
73 % | |
74 % Test that the getInfo call works for no sets, all sets, and each set | |
75 % individually. | |
76 % | |
77 % </SyntaxDescription> | |
78 | |
79 try | |
80 % <SyntaxCode> | |
81 % Call for no sets | |
82 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
83 % Call for all sets | |
84 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
85 % Call for each set | |
86 for kk=1:numel(io(2).sets) | |
87 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
88 end | |
89 % </SyntaxCode> | |
90 stest = true; | |
91 catch err | |
92 disp(err.message) | |
93 stest = false; | |
94 end | |
95 | |
96 % <AlgoDescription> | |
97 % | |
98 % 1) Check that getInfo call returned an minfo object in all cases. | |
99 % 2) Check that all plists have the correct parameters. | |
100 % | |
101 % </AlgoDescription> | |
102 | |
103 atest = true; | |
104 if stest | |
105 % <AlgoCode> | |
106 % check we have minfo objects | |
107 if isa(io, 'minfo') | |
108 %%% SET 'None' | |
109 if ~isempty(io(1).sets), atest = false; end | |
110 if ~isempty(io(1).plists), atest = false; end | |
111 %%% Check all Sets | |
112 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
113 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
114 %%%%%%%%%% SET 'Default' | |
115 if io(3).plists.nparams ~= 1, atest = false; end | |
116 % Check key | |
117 if ~io(3).plists.isparam('key'), atest = false; end | |
118 % Check default value | |
119 if ~isEmptyChar(io(3).plists.find('key')), atest = false; end | |
120 % Check options | |
121 if ~isequal(io(3).plists.getOptionsForParam('key'), {''}), atest = false; end | |
122 end | |
123 % </AlgoCode> | |
124 else | |
125 atest = false; | |
126 end | |
127 | |
128 % Return a result structure | |
129 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
130 end % END UTP_01 | |
131 | |
132 %% UTP_02 | |
133 | |
134 % <TestDescription> | |
135 % | |
136 % Tests that the remove method works with a vector of PLIST objects as input. | |
137 % | |
138 % </TestDescription> | |
139 function result = utp_02 | |
140 | |
141 % <SyntaxDescription> | |
142 % | |
143 % Test that the remove method remove the 'key' from all PLIST objects | |
144 % in the vector. | |
145 % | |
146 % </SyntaxDescription> | |
147 | |
148 try | |
149 % <SyntaxCode> | |
150 out = remove(plv, 'b'); | |
151 % </SyntaxCode> | |
152 stest = true; | |
153 catch err | |
154 disp(err.message) | |
155 stest = false; | |
156 end | |
157 | |
158 % <AlgoDescription> | |
159 % | |
160 % 1) Check that the shape of the output is the same as the shape of the input | |
161 % 2) Check that the output PLIST doesn't contains the key. | |
162 % | |
163 % </AlgoDescription> | |
164 | |
165 atest = true; | |
166 if stest | |
167 % <AlgoCode> | |
168 % Check that the shape of the output is the same as the shape of the input | |
169 if ~isa(out, 'plist') && size(out) == size(plv), atest = false; end | |
170 % Check that the output doesn't have the key | |
171 for ii = 1:numel(out) | |
172 if ~isempty(out(ii).find('b')), atest = false; end | |
173 if ~isnumeric(out(ii).find('b')), atest = false; end | |
174 end | |
175 % </AlgoCode> | |
176 else | |
177 atest = false; | |
178 end | |
179 | |
180 % Return a result structure | |
181 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
182 end % END UTP_02 | |
183 | |
184 %% UTP_03 | |
185 | |
186 % <TestDescription> | |
187 % | |
188 % Tests that the remove method works with a matrix of PLIST objects as input. | |
189 % | |
190 % </TestDescription> | |
191 function result = utp_03 | |
192 | |
193 % <SyntaxDescription> | |
194 % | |
195 % Test that the remove method remove the 'key' from all PLIST objects | |
196 % in the matrix. | |
197 % | |
198 % </SyntaxDescription> | |
199 | |
200 try | |
201 % <SyntaxCode> | |
202 out = remove(plm, 'b'); | |
203 % </SyntaxCode> | |
204 stest = true; | |
205 catch err | |
206 disp(err.message) | |
207 stest = false; | |
208 end | |
209 | |
210 % <AlgoDescription> | |
211 % | |
212 % 1) Check that the shape of the output is the same as the shape of the input | |
213 % 2) Check that the output PLIST doesn't contains the key. | |
214 % | |
215 % </AlgoDescription> | |
216 | |
217 atest = true; | |
218 if stest | |
219 % <AlgoCode> | |
220 % Check that the shape of the output is the same as the shape of the input | |
221 if ~isa(out, 'plist') && size(out) == size(plm), atest = false; end | |
222 % Check that the output doesn't have the key | |
223 for ii = 1:numel(out) | |
224 if ~isempty(out(ii).find('b')), atest = false; end | |
225 if ~isnumeric(out(ii).find('b')), atest = false; end | |
226 end | |
227 % </AlgoCode> | |
228 else | |
229 atest = false; | |
230 end | |
231 | |
232 % Return a result structure | |
233 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
234 end % END UTP_03 | |
235 | |
236 %% UTP_04 | |
237 | |
238 % <TestDescription> | |
239 % | |
240 % Tests that the remove method works with a list of PLIST objects as input. | |
241 % | |
242 % </TestDescription> | |
243 function result = utp_04 | |
244 | |
245 % <SyntaxDescription> | |
246 % | |
247 % Test that the remove method remove the 'key' from all PLIST objects | |
248 % of the input. | |
249 % | |
250 % </SyntaxDescription> | |
251 | |
252 try | |
253 % <SyntaxCode> | |
254 out = remove(pl1, pl2, pl3, 'b'); | |
255 % </SyntaxCode> | |
256 stest = true; | |
257 catch err | |
258 disp(err.message) | |
259 stest = false; | |
260 end | |
261 | |
262 % <AlgoDescription> | |
263 % | |
264 % 1) Check that the shape of the output is the same as the shape of the input | |
265 % 2) Check that the output PLIST doesn't contains the key. | |
266 % | |
267 % </AlgoDescription> | |
268 | |
269 atest = true; | |
270 plin = [pl1, pl2, pl3]; | |
271 if stest | |
272 % <AlgoCode> | |
273 % Check that the shape of the output is the same as the shape of the input | |
274 if ~isa(out, 'plist') && size(out) == size(plin), atest = false; end | |
275 % Check that the output doesn't have the key | |
276 for ii = 1:numel(out) | |
277 if ~isempty(out(ii).find('b')), atest = false; end | |
278 if ~isnumeric(out(ii).find('b')), atest = false; end | |
279 end | |
280 % </AlgoCode> | |
281 else | |
282 atest = false; | |
283 end | |
284 | |
285 % Return a result structure | |
286 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
287 end % END UTP_04 | |
288 | |
289 %% UTP_05 | |
290 | |
291 % <TestDescription> | |
292 % | |
293 % Tests that the remove method works with a mix of different shaped PLIST | |
294 % objects as input. | |
295 % | |
296 % </TestDescription> | |
297 function result = utp_05 | |
298 | |
299 % <SyntaxDescription> | |
300 % | |
301 % Test that the remove method remove the 'key' from all PLIST objects | |
302 % of the input. | |
303 % | |
304 % </SyntaxDescription> | |
305 | |
306 try | |
307 % <SyntaxCode> | |
308 out = remove(plm, plv, pl1, 'b'); | |
309 % </SyntaxCode> | |
310 stest = true; | |
311 catch err | |
312 disp(err.message) | |
313 stest = false; | |
314 end | |
315 | |
316 % <AlgoDescription> | |
317 % | |
318 % 1) Check that the shape of the output is the same as the shape of the input | |
319 % 2) Check that the output PLIST doesn't contains the key. | |
320 % | |
321 % </AlgoDescription> | |
322 | |
323 atest = true; | |
324 plin = [reshape(plm, 1, []), reshape(plv, 1, []), pl1]; | |
325 if stest | |
326 % <AlgoCode> | |
327 % Check that the shape of the output is the same as the shape of the input | |
328 if ~isa(out, 'plist') && size(out) == size(plin), atest = false; end | |
329 % Check that the output doesn't have the key | |
330 for ii = 1:numel(out) | |
331 if ~isempty(out(ii).find('b')), atest = false; end | |
332 if ~isnumeric(out(ii).find('b')), atest = false; end | |
333 end | |
334 % </AlgoCode> | |
335 else | |
336 atest = false; | |
337 end | |
338 | |
339 % Return a result structure | |
340 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
341 end % END UTP_05 | |
342 | |
343 %% UTP_06 | |
344 | |
345 % <TestDescription> | |
346 % | |
347 % Tests that the remove method applies the modify command | |
348 % | |
349 % </TestDescription> | |
350 function result = utp_06 | |
351 | |
352 % <SyntaxDescription> | |
353 % | |
354 % Test that the remove method can modify the input PLIST by calling with no | |
355 % output and that the method doesn't change the input of the function | |
356 % notation (with a equal sign). | |
357 % | |
358 % </SyntaxDescription> | |
359 | |
360 try | |
361 % <SyntaxCode> | |
362 % copy at1 to work with | |
363 pleq = plist(pl1); | |
364 plmo = plist(pl1); | |
365 % modify ain | |
366 out = pleq.remove('b'); | |
367 plmo.remove('b'); | |
368 % </SyntaxCode> | |
369 stest = true; | |
370 catch err | |
371 disp(err.message) | |
372 stest = false; | |
373 end | |
374 | |
375 % <AlgoDescription> | |
376 % | |
377 % 1) Check that 'out' and 'pleq' are now different. | |
378 % 2) Check that 'plmo' and 'out' are the same. | |
379 % 3) Check that 'out' and 'plmo' don't have the key | |
380 % 4) Check that pleq doesn't have the key | |
381 % | |
382 % </AlgoDescription> | |
383 | |
384 atest = true; | |
385 if stest | |
386 % <AlgoCode> | |
387 % Check that 'out' and 'pleq' are not the same | |
388 if eq(out, pleq, ple1), atest = false; end | |
389 % Check that 'out' don't have key and 'pleq' still have it | |
390 if ~isempty(out.find('b')), atest = false; end | |
391 if isempty(pleq.find('b')), atest = false; end | |
392 % Check 'plmo' don't have the key | |
393 if ~isempty(plmo.find('b')), atest = false; end | |
394 % Check that 'out' and plmo are the same | |
395 if ~eq(out, plmo, ple1), atest = false; end | |
396 % </AlgoCode> | |
397 else | |
398 atest = false; | |
399 end | |
400 | |
401 % Return a result structure | |
402 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
403 end % END UTP_06 | |
404 | |
405 %% UTP_07 | |
406 | |
407 % <TestDescription> | |
408 % | |
409 % Test the remove method that it removes the parameter which is defined | |
410 % as an index or as a key | |
411 % | |
412 % </TestDescription> | |
413 function result = utp_07 | |
414 | |
415 % <SyntaxDescription> | |
416 % | |
417 % Test the remove method that it removes the parameter which is defined | |
418 % as an index or as a key | |
419 % | |
420 % </SyntaxDescription> | |
421 | |
422 try | |
423 % <SyntaxCode> | |
424 idx = 2; | |
425 out1 = pl1.remove('b'); | |
426 out2 = pl1.remove(idx); | |
427 % </SyntaxCode> | |
428 stest = true; | |
429 catch err | |
430 disp(err.message) | |
431 stest = false; | |
432 end | |
433 | |
434 % <AlgoDescription> | |
435 % | |
436 % 1) Check the output. | |
437 % | |
438 % </AlgoDescription> | |
439 | |
440 atest = true; | |
441 if stest | |
442 % <AlgoCode> | |
443 % Check the correct number of parameter | |
444 if out1.nparams ~= pl1.nparams - 1, atest = false; end | |
445 if out2.nparams ~= pl1.nparams - 1, atest = false; end | |
446 % Check the correct number of parameter | |
447 if ~isempty(out1.find('b')), atest = false; end | |
448 key = pl1.params(idx).key; | |
449 if ~isempty(out1.find(key)), atest = false; end | |
450 % </AlgoCode> | |
451 else | |
452 atest = false; | |
453 end | |
454 | |
455 % Return a result structure | |
456 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
457 end % END UTP_07 | |
458 | |
459 %% UTP_08 | |
460 | |
461 % <TestDescription> | |
462 % | |
463 % Test the remove method in a negative case that the key is not in the | |
464 % paramter list. | |
465 % | |
466 % </TestDescription> | |
467 function result = utp_08 | |
468 | |
469 % <SyntaxDescription> | |
470 % | |
471 % The remove method doesn't throwns an error if the key doesn't exist | |
472 % in the parameter list. | |
473 % | |
474 % </SyntaxDescription> | |
475 | |
476 try | |
477 % <SyntaxCode> | |
478 pl1.remove('key'); | |
479 stest = true; | |
480 % </SyntaxCode> | |
481 catch err | |
482 disp(err.message) | |
483 stest = false; | |
484 end | |
485 | |
486 % <AlgoDescription> | |
487 % | |
488 % 1) Nothing to test. | |
489 % | |
490 % </AlgoDescription> | |
491 | |
492 atest = true; | |
493 if stest | |
494 % <AlgoCode> | |
495 % </AlgoCode> | |
496 else | |
497 atest = false; | |
498 end | |
499 | |
500 % Return a result structure | |
501 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
502 end % END UTP_08 | |
503 | |
504 end |