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