Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_unwrap.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_UNWRAP a set of UTPs for the ao/unwrap method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_unwrap.m,v 1.8 2011/04/17 11:12:03 hewitson Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The unwrap method of the ao class unwraps radian phases P by changing | |
11 % absolute jumps greater than or equal to pi to their 2*pi complement. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_unwrap(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'unwrap'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Create an test AO with a phase jump | |
30 w = [0:.2:3,3.5:1:10]; | |
31 p = [ 0 | |
32 -1.5728 | |
33 -1.5747 | |
34 -1.5772 | |
35 -1.5790 | |
36 -1.5816 | |
37 -1.5852 | |
38 -1.5877 | |
39 -1.5922 | |
40 -1.5976 | |
41 -1.6044 | |
42 -1.6129 | |
43 -1.6269 | |
44 -1.6512 | |
45 -1.6998 | |
46 -1.8621 | |
47 1.7252 | |
48 1.6124 | |
49 1.5930 | |
50 1.5916 | |
51 1.5708 | |
52 1.5708 | |
53 1.5708 ]; | |
54 a1 = ao(w,p, plist('type', 'tsdata')); | |
55 a2 = ao(w,p, plist('type', 'fsdata')); | |
56 a3 = ao(w,p, plist('type', 'xydata')); | |
57 a4 = ao(p); | |
58 avec = [a1, a2, a3]; | |
59 amat = [a1, a2, a3; a4, a3, a1]; | |
60 | |
61 % Exception list for the UTPs: | |
62 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
63 | |
64 % Run the tests | |
65 results = [results utp_01]; % getInfo call | |
66 results = [results utp_02]; % Vector input | |
67 results = [results utp_03]; % Matrix input | |
68 results = [results utp_04]; % List input | |
69 results = [results utp_05]; % Test with mixed input | |
70 results = [results utp_06]; % Test history is working | |
71 results = [results utp_07]; % Test the modify call works | |
72 results = [results utp_08]; % Test with additional plist with the key 'axis' | |
73 results = [results utp_09]; % Test input data shape == output data shape | |
74 results = [results utp_10]; % Test output of the data | |
75 results = [results utp_11(mthd, a1, ple1)]; % Test plotinfo doesn't disappear | |
76 | |
77 disp('Done.'); | |
78 disp('******************************************************'); | |
79 | |
80 elseif nargin == 1 % Check for UTP functions | |
81 if strcmp(varargin{1}, 'isutp') | |
82 results = 1; | |
83 else | |
84 results = 0; | |
85 end | |
86 else | |
87 error('### Incorrect inputs') | |
88 end | |
89 | |
90 %% UTP_01 | |
91 | |
92 % <TestDescription> | |
93 % | |
94 % Tests that the getInfo call works for this method. | |
95 % | |
96 % </TestDescription> | |
97 function result = utp_01 | |
98 | |
99 | |
100 % <SyntaxDescription> | |
101 % | |
102 % Test that the getInfo call works for no sets, all sets, and each set | |
103 % individually. | |
104 % | |
105 % </SyntaxDescription> | |
106 | |
107 try | |
108 % <SyntaxCode> | |
109 % Call for no sets | |
110 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
111 % Call for all sets | |
112 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
113 % Call for each set | |
114 for kk=1:numel(io(2).sets) | |
115 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
116 end | |
117 % </SyntaxCode> | |
118 stest = true; | |
119 catch err | |
120 disp(err.message) | |
121 stest = false; | |
122 end | |
123 | |
124 % <AlgoDescription> | |
125 % | |
126 % 1) Check that getInfo call returned an minfo object in all cases. | |
127 % 2) Check that all plists have the correct parameters. | |
128 % | |
129 % </AlgoDescription> | |
130 | |
131 atest = true; | |
132 if stest | |
133 % <AlgoCode> | |
134 % check we have minfo objects | |
135 if isa(io, 'minfo') | |
136 atest = check_axis_sets(io); | |
137 end | |
138 % </AlgoCode> | |
139 else | |
140 atest = false; | |
141 end | |
142 | |
143 % Return a result structure | |
144 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
145 end % END UTP_01 | |
146 | |
147 %% UTP_02 | |
148 | |
149 % <TestDescription> | |
150 % | |
151 % Tests that the unwrap method works with a vector of AOs as input. | |
152 % | |
153 % </TestDescription> | |
154 function result = utp_02 | |
155 | |
156 % <SyntaxDescription> | |
157 % | |
158 % Test that the unwrap method works for a vector of AOs as input. | |
159 % | |
160 % </SyntaxDescription> | |
161 | |
162 try | |
163 % <SyntaxCode> | |
164 out = unwrap(avec); | |
165 % </SyntaxCode> | |
166 stest = true; | |
167 catch err | |
168 disp(err.message) | |
169 stest = false; | |
170 end | |
171 | |
172 % <AlgoDescription> | |
173 % | |
174 % 1) Check that the number of elements in 'out' is the same as in 'avec' | |
175 % 2) Check that each ouput corrects the phase angles | |
176 % | |
177 % </AlgoDescription> | |
178 | |
179 atest = true; | |
180 if stest | |
181 % <AlgoCode> | |
182 % Check we have the correct number of outputs | |
183 if ~isequal(size(out), size(avec)), atest = false; end | |
184 % Check that each ouput corrects the phase angles | |
185 for kk=1:numel(out) | |
186 if ~isequal(unwrap(avec(kk).y), out(kk).y), atest = false; end | |
187 end | |
188 % </AlgoCode> | |
189 else | |
190 atest = false; | |
191 end | |
192 | |
193 % Return a result structure | |
194 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
195 end % END UTP_02 | |
196 | |
197 %% UTP_03 | |
198 | |
199 % <TestDescription> | |
200 % | |
201 % Tests that the unwrap method works with a matrix of AOs as input. | |
202 % | |
203 % </TestDescription> | |
204 function result = utp_03 | |
205 | |
206 % <SyntaxDescription> | |
207 % | |
208 % Tests that the unwrap method works with a matrix of AOs as input. | |
209 % | |
210 % </SyntaxDescription> | |
211 | |
212 try | |
213 % <SyntaxCode> | |
214 out = unwrap(amat); | |
215 % </SyntaxCode> | |
216 stest = true; | |
217 catch err | |
218 disp(err.message) | |
219 stest = false; | |
220 end | |
221 | |
222 % <AlgoDescription> | |
223 % | |
224 % 1) Check that the number of elements in 'out' is the same as in 'amat' | |
225 % 2) Check that each ouput corrects the phase angles | |
226 % | |
227 % </AlgoDescription> | |
228 | |
229 atest = true; | |
230 if stest | |
231 % <AlgoCode> | |
232 % Check we have the correct number of outputs | |
233 if ~isequal(size(out), size(amat)), atest = false; end | |
234 % Check that each ouput corrects the phase angles | |
235 for kk=1:numel(out) | |
236 if ~isequal(unwrap(amat(kk).y), out(kk).y), atest = false; end | |
237 end | |
238 % </AlgoCode> | |
239 else | |
240 atest = false; | |
241 end | |
242 | |
243 % Return a result structure | |
244 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
245 end % END UTP_03 | |
246 | |
247 %% UTP_04 | |
248 | |
249 % <TestDescription> | |
250 % | |
251 % Tests that the unwrap method works with a list of AOs as input. | |
252 % | |
253 % </TestDescription> | |
254 function result = utp_04 | |
255 | |
256 % <SyntaxDescription> | |
257 % | |
258 % Tests that the unwrap method works with a list of AOs as input. | |
259 % | |
260 % </SyntaxDescription> | |
261 | |
262 try | |
263 % <SyntaxCode> | |
264 out = unwrap(a1, a2, a3, a4); | |
265 % </SyntaxCode> | |
266 stest = true; | |
267 catch err | |
268 disp(err.message) | |
269 stest = false; | |
270 end | |
271 | |
272 % <AlgoDescription> | |
273 % | |
274 % 1) Check that the number of elements in 'out' is the same as in the | |
275 % input | |
276 % 2) Check that each ouput corrects the phase angles | |
277 % | |
278 % </AlgoDescription> | |
279 | |
280 atest = true; | |
281 aoin = [a1, a2, a3, a4]; | |
282 if stest | |
283 % <AlgoCode> | |
284 % Check we have the correct number of outputs | |
285 if ~isequal(size(out), size(aoin)), atest = false; end | |
286 % Check that each ouput corrects the phase angles | |
287 for kk=1:numel(out) | |
288 if ~isequal(unwrap(aoin(kk).y), out(kk).y), atest = false; end | |
289 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 unwrap method works with a mix of different shaped AOs | |
304 % as input. | |
305 % | |
306 % </TestDescription> | |
307 function result = utp_05 | |
308 | |
309 % <SyntaxDescription> | |
310 % | |
311 % Tests that the unwrap method works with a mix of different shaped AOs | |
312 % as input. | |
313 % | |
314 % </SyntaxDescription> | |
315 | |
316 try | |
317 % <SyntaxCode> | |
318 out = unwrap(a1, avec, amat, a4); | |
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 the | |
329 % input | |
330 % 2) Check that each ouput corrects the phase angles | |
331 % | |
332 % </AlgoDescription> | |
333 | |
334 atest = true; | |
335 aoin = [a1, reshape(avec, 1, []), reshape(amat, 1, []), a4]; | |
336 if stest | |
337 % <AlgoCode> | |
338 % Check we have the correct number of outputs | |
339 if ~isequal(size(out), size(aoin)), atest = false; end | |
340 % Check that each ouput corrects the phase angles | |
341 for kk=1:numel(out) | |
342 if ~isequal(unwrap(aoin(kk).y), out(kk).y), atest = false; end | |
343 end | |
344 % </AlgoCode> | |
345 else | |
346 atest = false; | |
347 end | |
348 | |
349 % Return a result structure | |
350 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
351 end % END UTP_05 | |
352 | |
353 %% UTP_06 | |
354 | |
355 % <TestDescription> | |
356 % | |
357 % Tests that the unwrap method properly applies history. | |
358 % | |
359 % </TestDescription> | |
360 function result = utp_06 | |
361 | |
362 % <SyntaxDescription> | |
363 % | |
364 % Test that the result of applying the unwrap method can be processed back. | |
365 % | |
366 % </SyntaxDescription> | |
367 | |
368 try | |
369 % <SyntaxCode> | |
370 out = unwrap(a1); | |
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 % 'unwrap'. | |
383 % 2) Check that the re-built object is the same object as the input. | |
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, 'unwrap'), atest = false; end | |
392 % The rebuilt object must be the same as 'out' | |
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 unwrap method can modify the input AO. | |
408 % | |
409 % </TestDescription> | |
410 function result = utp_07 | |
411 | |
412 % <SyntaxDescription> | |
413 % | |
414 % Test that the unwrap method can modify the input AO by calling with | |
415 % no output and that the method doesn't change the input of the | |
416 % function notation (with a equal sign). | |
417 % | |
418 % </SyntaxDescription> | |
419 | |
420 try | |
421 % <SyntaxCode> | |
422 amodi = ao(a3); | |
423 aeq = ao(a3); | |
424 out = aeq.unwrap(); | |
425 amodi.unwrap(); | |
426 % </SyntaxCode> | |
427 stest = true; | |
428 catch err | |
429 disp(err.message) | |
430 stest = false; | |
431 end | |
432 | |
433 % <AlgoDescription> | |
434 % | |
435 % 1) Check that 'out' and 'aeq' are now different. | |
436 % 2) Check that 'aeq' is not changed | |
437 % 3) Check that the modified input is the unwraped value of the copy | |
438 % 4) Check that out and amodi are the same | |
439 % | |
440 % </AlgoDescription> | |
441 | |
442 atest = true; | |
443 if stest | |
444 % <AlgoCode> | |
445 % Check that 'out' and 'aeq' are now different. | |
446 if eq(out, aeq, ple2), atest = false; end | |
447 % Check that 'aeq' is not changed | |
448 if ~eq(aeq, ao(a3), ple1), atest = false; end | |
449 % Check that the modified input is the unwraped value of the copy | |
450 if ~isequal(unwrap(a3.y), amodi.y), atest = false; end | |
451 % Check that out and amodi are the same | |
452 if ~eq(out, amodi, ple2), atest = false; end | |
453 % </AlgoCode> | |
454 else | |
455 atest = false; | |
456 end | |
457 | |
458 % Return a result structure | |
459 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
460 end % END UTP_07 | |
461 | |
462 %% UTP_08 | |
463 | |
464 % <TestDescription> | |
465 % | |
466 % Test that the unwrap method uses the plist to get the axis. | |
467 % | |
468 % </TestDescription> | |
469 function result = utp_08 | |
470 | |
471 % <SyntaxDescription> | |
472 % | |
473 % Test that the unwrap method uses the plist to get the axis. | |
474 % | |
475 % </SyntaxDescription> | |
476 | |
477 try | |
478 % <SyntaxCode> | |
479 plx = plist('axis', 'X'); | |
480 ply = plist('axis', 'Y'); | |
481 plxy = plist('axis', 'XY'); | |
482 out1 = unwrap(a3, plx); | |
483 out2 = unwrap(a3, ply); | |
484 out3 = unwrap(a3, plxy); | |
485 mout1 = rebuild(out1); | |
486 mout2 = rebuild(out2); | |
487 mout3 = rebuild(out3); | |
488 % </SyntaxCode> | |
489 stest = true; | |
490 catch err | |
491 disp(err.message) | |
492 stest = false; | |
493 end | |
494 | |
495 % <AlgoDescription> | |
496 % | |
497 % 1) Check that the unwrap method applies to the x-axis | |
498 % 2) Check that the unwrap method applies to the y-axis | |
499 % 3) Check that the unwrap method applies to both axes | |
500 % 4) Check that the re-built object is the same as in 'out[1..3]'. | |
501 % | |
502 % </AlgoDescription> | |
503 | |
504 atest = true; | |
505 if stest | |
506 % <AlgoCode> | |
507 % Check each output against the unwrapped value of the input | |
508 if ~isequal(unwrap(a3.data.getX), out1.data.getX), atest = false; end | |
509 if ~isequal(a3.data.getY, out1.data.getY), atest = false; end | |
510 if ~isequal(a3.data.getX, out2.data.getX), atest = false; end | |
511 if ~isequal(unwrap(a3.data.getY), out2.data.getY), atest = false; end | |
512 if ~isequal(unwrap(a3.data.getX), out3.data.getX), atest = false; end | |
513 if ~isequal(unwrap(a3.data.getY), out3.data.getY), atest = false; end | |
514 % Check the re-built objects | |
515 if ~eq(mout1, out1, ple2), atest = false; end | |
516 if ~eq(mout2, out2, ple2), atest = false; end | |
517 if ~eq(mout3, out3, ple2), atest = false; end | |
518 % </AlgoCode> | |
519 else | |
520 atest = false; | |
521 end | |
522 | |
523 % Return a result structure | |
524 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
525 end % END UTP_08 | |
526 | |
527 %% UTP_09 | |
528 | |
529 % <TestDescription> | |
530 % | |
531 % Test the shape of the output. | |
532 % | |
533 % </TestDescription> | |
534 function result = utp_09 | |
535 | |
536 % <SyntaxDescription> | |
537 % | |
538 % Test that the unwrap method keeps the data shape of the input object. | |
539 % The input AO must be an AO with row data and an AO with column data. | |
540 % | |
541 % </SyntaxDescription> | |
542 | |
543 try | |
544 % <SyntaxCode> | |
545 a_col = ao(a3); | |
546 a_row = a_col.'; | |
547 out1 = unwrap(a_col); | |
548 out2 = unwrap(a_row); | |
549 % </SyntaxCode> | |
550 stest = true; | |
551 catch err | |
552 disp(err.message) | |
553 stest = false; | |
554 end | |
555 | |
556 % <AlgoDescription> | |
557 % | |
558 % 1) Check that the shape of the data doesn't change. | |
559 % | |
560 % </AlgoDescription> | |
561 | |
562 atest = true; | |
563 if stest | |
564 % <AlgoCode> | |
565 % Check the shape of the output data | |
566 if size(out1.data.y,1) == 1, atest = false; end | |
567 if size(out2.data.y,2) == 1, atest = false; end | |
568 % </AlgoCode> | |
569 else | |
570 atest = false; | |
571 end | |
572 | |
573 % Return a result structure | |
574 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
575 end % END UTP_09 | |
576 | |
577 %% UTP_10 | |
578 | |
579 % <TestDescription> | |
580 % | |
581 % Check that the unwrap method pass back the output objects to a list of | |
582 % output variables or to a single variable. | |
583 % | |
584 % </TestDescription> | |
585 function result = utp_10 | |
586 | |
587 % <SyntaxDescription> | |
588 % | |
589 % Call the method with a list of output variables and with a single output | |
590 % variable. Additionaly check that the rebuild method works on the output. | |
591 % | |
592 % </SyntaxDescription> | |
593 | |
594 try | |
595 % <SyntaxCode> | |
596 [o1, o2] = unwrap(a1, a3); | |
597 o3 = unwrap(a1, a3); | |
598 mout1 = rebuild(o1); | |
599 mout2 = rebuild(o2); | |
600 mout3 = rebuild(o3); | |
601 % </SyntaxCode> | |
602 stest = true; | |
603 catch err | |
604 disp(err.message) | |
605 stest = false; | |
606 end | |
607 | |
608 % <AlgoDescription> | |
609 % | |
610 % 1) Check that the output contains the right number of objects | |
611 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
612 % | |
613 % </AlgoDescription> | |
614 | |
615 atest = true; | |
616 if stest | |
617 % <AlgoCode> | |
618 % Check the number of outputs | |
619 if numel(o1) ~=1, atest = false; end | |
620 if numel(o2) ~=1, atest = false; end | |
621 if numel(o3) ~=2, atest = false; end | |
622 % Check the rebuilding of the object | |
623 if ~eq(o1, mout1, ple2), atest = false; end | |
624 if ~eq(o2, mout2, ple2), atest = false; end | |
625 if ~eq(o3, mout3, ple2), atest = false; end | |
626 % </AlgoCode> | |
627 else | |
628 atest = false; | |
629 end | |
630 | |
631 % Return a result structure | |
632 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
633 end % END UTP_10 | |
634 | |
635 end |