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