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