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