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