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