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