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