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