Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_setDescription.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_AO_SETDESCRIPTION a set of UTPs for the ao/setDescription method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_setDescription.m,v 1.12 2011/04/19 18:14:00 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The setDescription method of the ao class sets the description property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_setDescription(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'setDescription'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test AOs | |
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]); | |
30 | |
31 % Exception list for the UTPs: | |
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
33 | |
34 % Run the tests | |
35 results = [results utp_01]; % getInfo call | |
36 results = [results utp_02]; % Vector input | |
37 results = [results utp_03]; % Matrix input | |
38 results = [results utp_04]; % List input | |
39 results = [results utp_05]; % Test with mixed input | |
40 results = [results utp_06]; % Test history is working | |
41 results = [results utp_07]; % Test the modify call works | |
42 results = [results utp_08]; % Set the property with a plist | |
43 results = [results utp_09]; % Test output of the data | |
44 results = [results utp_11(mthd, at1, ple1, plist('DESCRIPTION', 'foo'))]; % Test plotinfo doesn't disappear | |
45 | |
46 disp('Done.'); | |
47 disp('******************************************************'); | |
48 | |
49 elseif nargin == 1 % Check for UTP functions | |
50 if strcmp(varargin{1}, 'isutp') | |
51 results = 1; | |
52 else | |
53 results = 0; | |
54 end | |
55 else | |
56 error('### Incorrect inputs') | |
57 end | |
58 | |
59 %% UTP_01 | |
60 | |
61 % <TestDescription> | |
62 % | |
63 % Tests that the getInfo call works for this method. | |
64 % | |
65 % </TestDescription> | |
66 function result = utp_01 | |
67 | |
68 | |
69 % <SyntaxDescription> | |
70 % | |
71 % Test that the getInfo call works for no sets, all sets, and each set | |
72 % individually. | |
73 % | |
74 % </SyntaxDescription> | |
75 | |
76 try | |
77 % <SyntaxCode> | |
78 % Call for no sets | |
79 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
80 % Call for all sets | |
81 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
82 % Call for each set | |
83 for kk=1:numel(io(2).sets) | |
84 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
85 end | |
86 % </SyntaxCode> | |
87 stest = true; | |
88 catch err | |
89 disp(err.message) | |
90 stest = false; | |
91 end | |
92 | |
93 % <AlgoDescription> | |
94 % | |
95 % 1) Check that getInfo call returned an minfo object in all cases. | |
96 % 2) Check that all plists have the correct parameters. | |
97 % | |
98 % </AlgoDescription> | |
99 | |
100 atest = true; | |
101 if stest | |
102 % <AlgoCode> | |
103 % check we have minfo objects | |
104 if isa(io, 'minfo') | |
105 %%% SET 'None' | |
106 if ~isempty(io(1).sets), atest = false; end | |
107 if ~isempty(io(1).plists), atest = false; end | |
108 %%% Check all Sets | |
109 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
110 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
111 %%%%%%%%%% SET 'Default' | |
112 if io(3).plists.nparams ~= 1, atest = false; end | |
113 % Check key | |
114 if ~io(3).plists.isparam('description'), atest = false; end | |
115 % Check default value | |
116 if ~isEmptyChar(io(3).plists.find('description')), atest = false; end | |
117 % Check options | |
118 if ~isequal(io(3).plists.getOptionsForParam('description'), {''}), atest = false; end | |
119 end | |
120 % </AlgoCode> | |
121 else | |
122 atest = false; | |
123 end | |
124 | |
125 % Return a result structure | |
126 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
127 end % END UTP_01 | |
128 | |
129 %% UTP_02 | |
130 | |
131 % <TestDescription> | |
132 % | |
133 % Tests that the setDescription method works with a vector of AOs as input. | |
134 % | |
135 % </TestDescription> | |
136 function result = utp_02 | |
137 | |
138 % <SyntaxDescription> | |
139 % | |
140 % Test that the setDescription method works for a vector of AOs as input. | |
141 % | |
142 % </SyntaxDescription> | |
143 | |
144 try | |
145 % <SyntaxCode> | |
146 out = setDescription(atvec, 'my description'); | |
147 % </SyntaxCode> | |
148 stest = true; | |
149 catch err | |
150 disp(err.message) | |
151 stest = false; | |
152 end | |
153 | |
154 % <AlgoDescription> | |
155 % | |
156 % 1) Check that the number of elements in 'out' is the same as in 'atvec' | |
157 % 2) Check that each output AO contains the correct data. | |
158 % | |
159 % </AlgoDescription> | |
160 | |
161 atest = true; | |
162 if stest | |
163 % <AlgoCode> | |
164 % Check we have the correct number of outputs | |
165 if ~isequal(size(out), size(atvec)), atest = false; end | |
166 % Check description field of each output | |
167 for kk=1:numel(out) | |
168 if ~strcmp(out(kk).description, 'my description') | |
169 atest = false; | |
170 break; | |
171 end | |
172 end | |
173 % </AlgoCode> | |
174 else | |
175 atest = false; | |
176 end | |
177 | |
178 % Return a result structure | |
179 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
180 end % END UTP_02 | |
181 | |
182 %% UTP_03 | |
183 | |
184 % <TestDescription> | |
185 % | |
186 % Tests that the setDescription method works with a matrix of AOs as input. | |
187 % | |
188 % </TestDescription> | |
189 function result = utp_03 | |
190 | |
191 % <SyntaxDescription> | |
192 % | |
193 % Test that the setDescription method works for a matrix of AOs as input. | |
194 % | |
195 % </SyntaxDescription> | |
196 | |
197 try | |
198 % <SyntaxCode> | |
199 out = setDescription(atmat, 'my description'); | |
200 % </SyntaxCode> | |
201 stest = true; | |
202 catch err | |
203 disp(err.message) | |
204 stest = false; | |
205 end | |
206 | |
207 % <AlgoDescription> | |
208 % | |
209 % 1) Check that the number of elements in 'out' is the same as in 'atmat' | |
210 % 2) Check that each output AO contains the correct data. | |
211 % | |
212 % </AlgoDescription> | |
213 | |
214 atest = true; | |
215 if stest | |
216 % <AlgoCode> | |
217 % Check we have the correct number of outputs | |
218 if ~isequal(size(out), size(atmat)), atest = false; end | |
219 % Check description field of each output | |
220 for kk=1:numel(out) | |
221 if ~strcmp(out(kk).description, 'my description') | |
222 atest = false; | |
223 break; | |
224 end | |
225 end | |
226 % </AlgoCode> | |
227 else | |
228 atest = false; | |
229 end | |
230 | |
231 % Return a result structure | |
232 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
233 end % END UTP_03 | |
234 | |
235 %% UTP_04 | |
236 | |
237 % <TestDescription> | |
238 % | |
239 % Tests that the setDescription method works with a list of AOs as input. | |
240 % | |
241 % </TestDescription> | |
242 function result = utp_04 | |
243 | |
244 % <SyntaxDescription> | |
245 % | |
246 % Test that the setDescription method works for a list of AOs as input. | |
247 % | |
248 % </SyntaxDescription> | |
249 | |
250 try | |
251 % <SyntaxCode> | |
252 out = setDescription(at1,at2,at3, 'my description'); | |
253 % </SyntaxCode> | |
254 stest = true; | |
255 catch err | |
256 disp(err.message) | |
257 stest = false; | |
258 end | |
259 | |
260 % <AlgoDescription> | |
261 % | |
262 % 1) Check that the number of elements in 'out' is the same as in | |
263 % input. | |
264 % 2) Check that each output AO contains the correct data. | |
265 % | |
266 % </AlgoDescription> | |
267 | |
268 atest = true; | |
269 if stest | |
270 % <AlgoCode> | |
271 % Check we have the correct number of outputs | |
272 if numel(out) ~= 3, atest = false; end | |
273 % Check each output against the input | |
274 if ~strcmp(out(1).description, 'my description'), atest = false; end | |
275 if ~strcmp(out(2).description, 'my description'), atest = false; end | |
276 if ~strcmp(out(3).description, 'my description'), atest = false; end | |
277 % </AlgoCode> | |
278 else | |
279 atest = false; | |
280 end | |
281 | |
282 % Return a result structure | |
283 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
284 end % END UTP_04 | |
285 | |
286 %% UTP_05 | |
287 | |
288 % <TestDescription> | |
289 % | |
290 % Tests that the setDescription method works with a mix of different shaped AOs as | |
291 % input. | |
292 % | |
293 % </TestDescription> | |
294 function result = utp_05 | |
295 | |
296 % <SyntaxDescription> | |
297 % | |
298 % Test that the setDescription method works with an input of matrices and vectors | |
299 % and single AOs. | |
300 % | |
301 % </SyntaxDescription> | |
302 | |
303 try | |
304 % <SyntaxCode> | |
305 out = setDescription(at1,atvec,at2,atmat,at3, 'my description'); | |
306 % </SyntaxCode> | |
307 stest = true; | |
308 catch err | |
309 disp(err.message) | |
310 stest = false; | |
311 end | |
312 | |
313 % <AlgoDescription> | |
314 % | |
315 % 1) Check that the number of elements in 'out' is the same as in | |
316 % input. | |
317 % 2) Check that each output AO contains the correct data. | |
318 % | |
319 % </AlgoDescription> | |
320 | |
321 atest = true; | |
322 if stest | |
323 % <AlgoCode> | |
324 % Check we have the correct number of outputs | |
325 if numel(out) ~= (3+numel(atmat)+numel(atvec)), atest = false; end | |
326 for kk=1:numel(out) | |
327 if ~strcmp(out(kk).description, 'my description') | |
328 atest = false; | |
329 break; | |
330 end | |
331 end | |
332 % </AlgoCode> | |
333 else | |
334 atest = false; | |
335 end | |
336 | |
337 % Return a result structure | |
338 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
339 end % END UTP_05 | |
340 | |
341 %% UTP_06 | |
342 | |
343 % <TestDescription> | |
344 % | |
345 % Tests that the setDescription method properly applies history and that the | |
346 % option 'internal' suppresses the history. | |
347 % | |
348 % </TestDescription> | |
349 function result = utp_06 | |
350 | |
351 % <SyntaxDescription> | |
352 % | |
353 % Test that the result of applying the setDescription method can be processed back | |
354 % to an m-file. | |
355 % | |
356 % </SyntaxDescription> | |
357 | |
358 try | |
359 % <SyntaxCode> | |
360 out1 = setDescription(at1, 'my description'); | |
361 out2 = testCallerIsMethod(@setDescription, at1, 'my description'); | |
362 mout1 = rebuild(out1); | |
363 mout2 = rebuild(out2); | |
364 % </SyntaxCode> | |
365 stest = true; | |
366 catch err | |
367 disp(err.message) | |
368 stest = false; | |
369 end | |
370 | |
371 % <AlgoDescription> | |
372 % | |
373 % 1) Check that the last entry in the history of 'out1' corresponds to | |
374 % 'setDescription'. | |
375 % 1) Check that the last entry in the history of 'out2' NOT corresponds to | |
376 % 'setDescription'. | |
377 % 2) Check that the re-built object is the same object as 'out'. | |
378 % | |
379 % </AlgoDescription> | |
380 | |
381 atest = true; | |
382 if stest | |
383 % <AlgoCode> | |
384 % Check the last step in the history of 'out1' | |
385 if ~strcmp(out1.hist.methodInfo.mname, 'setDescription'), atest = false; end | |
386 % Check the last step in the history of 'out2' | |
387 if strcmp(out2.hist.methodInfo.mname, 'setDescription'), atest = false; end | |
388 % Check the re-built object | |
389 if ~eq(mout1, out1, ple2), atest = false; end | |
390 e = ple2.find('EXCEPTIONS'); | |
391 ple = plist('EXCEPTIONS', [e {'description'}]); | |
392 if ~eq(mout2, out2, ple), atest = false; end | |
393 % </AlgoCode> | |
394 else | |
395 atest = false; | |
396 end | |
397 | |
398 % Return a result structure | |
399 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
400 end % END UTP_06 | |
401 | |
402 %% UTP_07 | |
403 | |
404 % <TestDescription> | |
405 % | |
406 % Tests that the setDescription method can modify the input AO. | |
407 % | |
408 % </TestDescription> | |
409 function result = utp_07 | |
410 | |
411 % <SyntaxDescription> | |
412 % | |
413 % Test that the setDescription method can modify the input AO by calling with no | |
414 % output. | |
415 % | |
416 % </SyntaxDescription> | |
417 | |
418 try | |
419 % <SyntaxCode> | |
420 % copy at1 to work with | |
421 ain = ao(at1); | |
422 % modify ain | |
423 aout = ain.setDescription('my description'); | |
424 ain.setDescription('my description'); | |
425 % </SyntaxCode> | |
426 stest = true; | |
427 catch err | |
428 disp(err.message) | |
429 stest = false; | |
430 end | |
431 | |
432 % <AlgoDescription> | |
433 % | |
434 % 1) Check that 'at1' and 'ain' are now different. | |
435 % 2) Check that 'ain' has the correct description field | |
436 % | |
437 % </AlgoDescription> | |
438 | |
439 atest = true; | |
440 if stest | |
441 % <AlgoCode> | |
442 % Check that setDescription modified the input by comparing to the copy | |
443 if eq(ao(at1), ain, ple1), atest = false; end | |
444 % Check that setDescription doesn't modified the input for the function notation | |
445 if ~eq(aout, ain, ple1), atest = false; end | |
446 % Check that the modified object contains the changed value | |
447 if ~strcmp(ain.description, 'my description'), atest = false; end | |
448 % </AlgoCode> | |
449 else | |
450 atest = false; | |
451 end | |
452 | |
453 % Return a result structure | |
454 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
455 end % END UTP_07 | |
456 | |
457 %% UTP_08 | |
458 | |
459 % <TestDescription> | |
460 % | |
461 % Tests that the setDescription method can set the property with a plist. | |
462 % | |
463 % </TestDescription> | |
464 function result = utp_08 | |
465 | |
466 % <SyntaxDescription> | |
467 % | |
468 % Test that the setDescription method can modify the property 'description' | |
469 % with a value in a plist. | |
470 % | |
471 % </SyntaxDescription> | |
472 | |
473 try | |
474 % <SyntaxCode> | |
475 pl = plist('description', 'my description'); | |
476 out = at1.setDescription(pl); | |
477 mout = rebuild(out); | |
478 % </SyntaxCode> | |
479 stest = true; | |
480 catch err | |
481 disp(err.message) | |
482 stest = false; | |
483 end | |
484 | |
485 % <AlgoDescription> | |
486 % | |
487 % 1) Check that 'ain' has the correct description field | |
488 % 2) Check that the re-built object is the same object as 'out'. | |
489 % | |
490 % </AlgoDescription> | |
491 | |
492 atest = true; | |
493 if stest | |
494 % <AlgoCode> | |
495 % Check the field 'description' | |
496 if ~strcmp(out.description, 'my description'), atest = false; end | |
497 % Check the re-built object | |
498 if ~eq(mout, out, ple2), atest = false; end | |
499 % </AlgoCode> | |
500 else | |
501 atest = false; | |
502 end | |
503 | |
504 % Return a result structure | |
505 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
506 end % END UTP_08 | |
507 | |
508 %% UTP_09 | |
509 | |
510 % <TestDescription> | |
511 % | |
512 % Check that the setDescription method pass back the output objects to a list of | |
513 % output variables or to a single variable. | |
514 % | |
515 % </TestDescription> | |
516 function result = utp_09 | |
517 | |
518 % <SyntaxDescription> | |
519 % | |
520 % Call the method with a list of output variables and with a single output | |
521 % variable. Additionaly check that the rebuild method works on the output. | |
522 % | |
523 % </SyntaxDescription> | |
524 | |
525 try | |
526 % <SyntaxCode> | |
527 [o1, o2] = setDescription(at5, at6, 'new'); | |
528 o3 = setDescription(at5, at6, 'new'); | |
529 mout1 = rebuild(o1); | |
530 mout2 = rebuild(o2); | |
531 mout3 = rebuild(o3); | |
532 % </SyntaxCode> | |
533 stest = true; | |
534 catch err | |
535 disp(err.message) | |
536 stest = false; | |
537 end | |
538 | |
539 % <AlgoDescription> | |
540 % | |
541 % 1) Check that the output contains the right number of objects | |
542 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
543 % | |
544 % </AlgoDescription> | |
545 | |
546 atest = true; | |
547 if stest | |
548 % <AlgoCode> | |
549 % Check the number of outputs | |
550 if numel(o1) ~=1, atest = false; end | |
551 if numel(o2) ~=1, atest = false; end | |
552 if numel(o3) ~=2, atest = false; end | |
553 % Check the rebuilding of the object | |
554 if ~eq(o1, mout1, ple2), atest = false; end | |
555 if ~eq(o2, mout2, ple2), atest = false; end | |
556 if ~eq(o3, mout3, ple2), atest = false; end | |
557 % </AlgoCode> | |
558 else | |
559 atest = false; | |
560 end | |
561 | |
562 % Return a result structure | |
563 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
564 end % END UTP_09 | |
565 | |
566 end |