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