comparison testing/utp_1.1/utps/ao/utp_ao_interpmissing.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_INTERPMISSING a set of UTPs for the ao/interpmissing method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_interpmissing.m,v 1.13 2010/06/07 16:43:06 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The interpmissing method of the ao class interpolates over any missing
11 % samples in a time-series AO.
12 % For this UTP contain the test objects different gaps. These gaps are created
13 % with the AO method select. Thus at1, at5 and at5 get gaps at the positions
14 % idx = 30 and idx = 51
15 %
16 % </MethodDescription>
17
18 function results = utp_ao_interpmissing(varargin)
19
20 % Check the inputs
21 if nargin == 0
22
23 % Some keywords
24 class = 'ao';
25 mthd = 'interpmissing';
26
27 results = [];
28 disp('******************************************************');
29 disp(['**** Running UTPs for ' class '/' mthd]);
30 disp('******************************************************');
31
32 % Test AOs
33 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
34
35 % Create gaps
36 samples = [1:30, 70:90, 150:300];
37 at1 = at1.select(plist('samples', samples));
38 at5 = at5.select(plist('samples', samples));
39 at6 = at6.select(plist('samples', samples));
40
41 % Exception list for the UTPs:
42 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
43
44 % Run the tests
45 results = [results utp_01]; % getInfo call
46 results = [results utp_02]; % Vector input
47 results = [results utp_03]; % Matrix input
48 results = [results utp_04]; % List input
49 results = [results utp_05]; % Test with mixed input
50 results = [results utp_06]; % Test history is working
51 results = [results utp_07]; % Test the modify call works
52 results = [results utp_08]; % Test input data shape == output data shape
53 results = [results utp_09]; % Test output of the data
54 results = [results utp_10]; % Test with different tolerances
55 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear
56
57 disp('Done.');
58 disp('******************************************************');
59
60 elseif nargin == 1 % Check for UTP functions
61 if strcmp(varargin{1}, 'isutp')
62 results = 1;
63 else
64 results = 0;
65 end
66 else
67 error('### Incorrect inputs')
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 %%% SET 'None'
117 if ~isempty(io(1).sets), atest = false; end
118 if ~isempty(io(1).plists), atest = false; end
119 %%% Check all Sets
120 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
121 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
122 %%%%%%%%%% SET 'Default'
123 if io(3).plists.nparams ~= 2, atest = false; end
124 % Check key
125 if ~io(3).plists.isparam('d'), atest = false; end
126 if ~io(3).plists.isparam('method'), atest = false; end
127 % Check default value
128 if ~isequal(io(3).plists.find('d'), 1.5), atest = false; end
129 if ~isequal(io(3).plists.find('method'), 'spline'), atest = false; end
130 % Check options
131 if ~isequal(io(3).plists.getOptionsForParam('d'), {1.5}), atest = false; end
132 if ~isequal(io(3).plists.getOptionsForParam('method'), {'nearest', 'linear', 'spline', 'cubic'}), atest = false; end
133 end
134 % </AlgoCode>
135 else
136 atest = false;
137 end
138
139 % Return a result structure
140 result = utp_prepare_result(atest, stest, dbstack, mfilename);
141 end % END UTP_01
142
143 %% UTP_02
144
145 % <TestDescription>
146 %
147 % Tests that the interpmissing method works with a vector of AOs as input.
148 %
149 % </TestDescription>
150 function result = utp_02
151
152 % <SyntaxDescription>
153 %
154 % Test that the interpmissing method works for a vector of AOs as input.
155 % Known gaps at the position idx = 30 and 51
156 %
157 % </SyntaxDescription>
158
159 try
160 % <SyntaxCode>
161 avec = [at1 at5 at6];
162 out = interpmissing(avec);
163 % </SyntaxCode>
164 stest = true;
165 catch err
166 disp(err.message)
167 stest = false;
168 end
169
170 % <AlgoDescription>
171 %
172 % 1) Check that the number of elements in 'out' is the square of the
173 % number in the input.
174 % 2) Check that each output AO contains the correct data.
175 %
176 % </AlgoDescription>
177
178 atest = true;
179 if stest
180 % <AlgoCode>
181 % Check we have the correct number of outputs
182 if numel(out) ~= numel(avec), atest = false; end
183 % Check each output data
184 for kk = 1:numel(avec)
185 x = avec(kk).data.getX;
186 % Gap at index position 30
187 gap1 = x(30+1) - x(30) - 1/avec(kk).fs;
188 gap1_t = ((1/avec(kk).fs : 1/avec(kk).fs : gap1) + x(30)).';
189 % Gap at index position 51
190 gap2 = x(51+1) - x(51) - 1/avec(kk).fs;
191 gap2_t = ((1/avec(kk).fs : 1/avec(kk).fs : gap2) + x(51)).';
192 % Create t
193 t = [x(1:30); gap1_t; x(31:51); gap2_t; x(52:end)];
194 % Interpolate the missing samples
195 res = interp(avec(kk), plist('vertices', t));
196 if ~isequal(out(kk).x, res.x), atest = false; end
197 if ~isequal(out(kk).y, res.y), atest = false; end
198 end
199 % </AlgoCode>
200 else
201 atest = false;
202 end
203
204 % Return a result structure
205 result = utp_prepare_result(atest, stest, dbstack, mfilename);
206 end % END UTP_02
207
208 %% UTP_03
209
210 % <TestDescription>
211 %
212 % Tests that the interpmissing method works with a matrix of AOs as input.
213 %
214 % </TestDescription>
215 function result = utp_03
216
217 % <SyntaxDescription>
218 %
219 % Test that the interpmissing method works for a matrix of AOs as input.
220 % Known gaps at the position idx = 30 and 51
221 %
222 % </SyntaxDescription>
223
224 try
225 % <SyntaxCode>
226 amat = [at1 at5 at6; at6 at5 at1];
227 out = interpmissing(amat);
228 % </SyntaxCode>
229 stest = true;
230 catch err
231 disp(err.message)
232 stest = false;
233 end
234
235 % <AlgoDescription>
236 %
237 % 1) Check that the number of elements in 'out' is the square of the
238 % number in the input.
239 % 2) Check that each output AO contains the correct data.
240 %
241 % </AlgoDescription>
242
243 atest = true;
244 if stest
245 % <AlgoCode>
246 % Check we have the correct number of outputs
247 if numel(out) ~= numel(amat), atest = false; end
248 % Check each output data
249 for kk = 1:numel(amat)
250 x = amat(kk).data.getX;
251 % Gap at index position 30
252 gap1 = x(30+1) - x(30) - 1/amat(kk).fs;
253 gap1_t = ((1/amat(kk).fs : 1/amat(kk).fs : gap1) + x(30)).';
254 % Gap at index position 51
255 gap2 = x(51+1) - x(51) - 1/amat(kk).fs;
256 gap2_t = ((1/amat(kk).fs : 1/amat(kk).fs : gap2) + x(51)).';
257 % Create t
258 t = [x(1:30); gap1_t; x(31:51); gap2_t; x(52:end)];
259 % Interpolate the missing samples
260 res = interp(amat(kk), plist('vertices', t));
261 if ~isequal(out(kk).x, res.x), atest = false; end
262 if ~isequal(out(kk).y, res.y), atest = false; end
263 end
264 % </AlgoCode>
265 else
266 atest = false;
267 end
268
269 % Return a result structure
270 result = utp_prepare_result(atest, stest, dbstack, mfilename);
271 end % END UTP_03
272
273 %% UTP_04
274
275 % <TestDescription>
276 %
277 % Tests that the interpmissing method works with a list of AOs as input.
278 %
279 % </TestDescription>
280 function result = utp_04
281
282 % <SyntaxDescription>
283 %
284 % Test that the interpmissing method works for a list of AOs as input.
285 % Known gaps at the position idx = 30 and 51
286 %
287 % </SyntaxDescription>
288
289 try
290 % <SyntaxCode>
291 out = interpmissing(at1,at5,at6);
292 % </SyntaxCode>
293 stest = true;
294 catch err
295 disp(err.message)
296 stest = false;
297 end
298
299 % <AlgoDescription>
300 %
301 % 1) Check that the number of elements in 'out' is the square of the
302 % number in the input.
303 % 2) Check that each output AO contains the correct data.
304 %
305 % </AlgoDescription>
306
307 atest = true;
308 aoin = [at1, at5, at6];
309 if stest
310 % <AlgoCode>
311 % Check we have the correct number of outputs
312 if numel(out) ~= 3, atest = false; end
313 % Check each output data
314 for kk = 1:numel(aoin)
315 x = aoin(kk).data.getX;
316 % Gap at index position 30
317 gap1 = x(30+1) - x(30) - 1/aoin(kk).fs;
318 gap1_t = ((1/aoin(kk).fs : 1/aoin(kk).fs : gap1) + x(30)).';
319 % Gap at index position 51
320 gap2 = x(51+1) - x(51) - 1/aoin(kk).fs;
321 gap2_t = ((1/aoin(kk).fs : 1/aoin(kk).fs : gap2) + x(51)).';
322 % Create t
323 t = [x(1:30); gap1_t; x(31:51); gap2_t; x(52:end)];
324 % Interpolate the missing samples
325 res = interp(aoin(kk), plist('vertices', t));
326 if ~isequal(out(kk).x, res.x), atest = false; end
327 if ~isequal(out(kk).y, res.y), atest = false; end
328 end
329 % </AlgoCode>
330 else
331 atest = false;
332 end
333
334 % Return a result structure
335 result = utp_prepare_result(atest, stest, dbstack, mfilename);
336 end % END UTP_04
337
338 %% UTP_05
339
340 % <TestDescription>
341 %
342 % Tests that the interpmissing method works with a mix of different shaped AOs as
343 % input.
344 %
345 % </TestDescription>
346 function result = utp_05
347
348 % <SyntaxDescription>
349 %
350 % Test that the interpmissing method works with an input of matrices and vectors
351 % and single AOs. Known gaps at the position idx = 30 and 51
352 %
353 % </SyntaxDescription>
354
355 try
356 % <SyntaxCode>
357 out = interpmissing(at1,[at5 at6],at5,[at5 at1; at6 at1],at6);
358 % </SyntaxCode>
359 stest = true;
360 catch err
361 disp(err.message)
362 stest = false;
363 end
364
365 % <AlgoDescription>
366 %
367 % 1) Check that the number of elements in 'out' is the same as in
368 % input.
369 % 2) Check that each output AO contains the correct data.
370 %
371 % </AlgoDescription>
372
373 atest = true;
374 aoin = [at1, reshape([at5 at6], 1, []), at5, reshape([at5 at1; at6 at1], 1, []), at6];
375 if stest
376 % <AlgoCode>
377 % Check we have the correct number of outputs
378 if numel(out) ~= 9, atest = false; end
379 % Check each output data
380 for kk = 1:numel(aoin)
381 x = aoin(kk).data.getX;
382 % Gap at index position 30
383 gap1 = x(30+1) - x(30) - 1/aoin(kk).fs;
384 gap1_t = ((1/aoin(kk).fs : 1/aoin(kk).fs : gap1) + x(30)).';
385 % Gap at index position 51
386 gap2 = x(51+1) - x(51) - 1/aoin(kk).fs;
387 gap2_t = ((1/aoin(kk).fs : 1/aoin(kk).fs : gap2) + x(51)).';
388 % Create t
389 t = [x(1:30); gap1_t; x(31:51); gap2_t; x(52:end)];
390 % Interpolate the missing samples
391 res = interp(aoin(kk), plist('vertices', t));
392 if ~isequal(out(kk).x, res.x), atest = false; end
393 if ~isequal(out(kk).y, res.y), atest = false; end
394 end
395 % </AlgoCode>
396 else
397 atest = false;
398 end
399
400 % Return a result structure
401 result = utp_prepare_result(atest, stest, dbstack, mfilename);
402 end % END UTP_05
403
404 %% UTP_06
405
406 % <TestDescription>
407 %
408 % Tests that the interpmissing method properly applies history.
409 %
410 % </TestDescription>
411 function result = utp_06
412
413 % <SyntaxDescription>
414 %
415 % Test that the result of applying the interpmissing method can be processed back
416 % to an m-file.
417 %
418 % </SyntaxDescription>
419
420 try
421 % <SyntaxCode>
422 % remove some samples
423 ac = ao(at5);
424 out = interpmissing(ac);
425 mout = rebuild(out);
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 the last entry in the history of 'out' corresponds to
436 % 'interpmissing'.
437 % 2) Check that the re-built object is the same as 'out'.
438 %
439 % </AlgoDescription>
440
441 atest = true;
442 if stest
443 % <AlgoCode>
444 % Check the last step in the history of 'out'
445 if ~strcmp(out.hist.methodInfo.mname, 'interpmissing'), atest = false; end
446 % Check the re-built object
447 if ~eq(mout, out, ple2), atest = false; end
448 % </AlgoCode>
449 else
450 atest = false;
451 end
452
453 % Return a result structure
454 result = utp_prepare_result(atest, stest, dbstack, mfilename);
455 end % END UTP_06
456
457 %% UTP_07
458
459 % <TestDescription>
460 %
461 % Tests that the interpmissing method can modify the input AO.
462 %
463 % </TestDescription>
464 function result = utp_07
465
466 % <SyntaxDescription>
467 %
468 % Test that the interpmissing method can modify the input AO by calling with no
469 % output and that the method doesn't change the input of the function
470 % notation (with a equal sign).
471 % Known gaps at the position idx = 30 and 51
472 %
473 % </SyntaxDescription>
474
475 try
476 % <SyntaxCode>
477 % copy at1 to work with
478 ain = ao(at1);
479 % modify ain
480 aout = ain.interpmissing();
481 ain.interpmissing();
482 % </SyntaxCode>
483 stest = true;
484 catch err
485 disp(err.message)
486 stest = false;
487 end
488
489 % <AlgoDescription>
490 %
491 % 1) Check that 'at1' and 'ain' are now different.
492 % 2) Check that 'ain' is interpmissing(at1).
493 %
494 % </AlgoDescription>
495
496 atest = true;
497 if stest
498 % <AlgoCode>
499 % Check that interpmissing modified the input by comparing to the copy
500 if eq(ao(at1), ain, ple1), atest = false; end
501 % Check that interpmissing doesn't modified the input for the function notation
502 if ~eq(aout, ain, ple1), atest = false; end
503 % Check that the modified input is the interpmissing value of the copy
504 x = at1.data.getX;
505 % Gap at index position 30
506 gap1 = x(30+1) - x(30) - 1/at1.fs;
507 gap1_t = ((1/at1.fs : 1/at1.fs : gap1) + x(30)).';
508 % Gap at index position 51
509 gap2 = x(51+1) - x(51) - 1/at1.fs;
510 gap2_t = ((1/at1.fs : 1/at1.fs : gap2) + x(51)).';
511 % Create t
512 t = [x(1:30); gap1_t; x(31:51); gap2_t; x(52:end)];
513 % Interpolate the missing samples
514 res = interp(at1, plist('vertices', t));
515 if ~isequal(ain.x, res.x), atest = false; end
516 if ~isequal(ain.y, res.y), atest = false; end
517 % </AlgoCode>
518 else
519 atest = false;
520 end
521
522 % Return a result structure
523 result = utp_prepare_result(atest, stest, dbstack, mfilename);
524 end % END UTP_07
525
526 %% UTP_08
527
528 % <TestDescription>
529 %
530 % Control the method with a plist.
531 %
532 % </TestDescription>
533 function result = utp_08
534
535 % <SyntaxDescription>
536 %
537 % Test that the interpmissing method keeps the data shape of the input object. The
538 % input AO must be an AO with row data and an AO with column data.
539 %
540 % </SyntaxDescription>
541
542 try
543 % <SyntaxCode>
544 out1 = interpmissing(at5);
545 out2 = interpmissing(at6);
546 % </SyntaxCode>
547 stest = true;
548 catch err
549 disp(err.message)
550 stest = false;
551 end
552
553 % <AlgoDescription>
554 %
555 % 1) Check that the shpe of the data doesn't change.
556 %
557 % </AlgoDescription>
558
559 atest = true;
560 if stest
561 % <AlgoCode>
562 % Check the shape of the output data
563 if size(out1.data.y,2) ~= 1, atest = false; end
564 if size(out2.data.y,1) ~= 1, atest = false; end
565 % </AlgoCode>
566 else
567 atest = false;
568 end
569
570 % Return a result structure
571 result = utp_prepare_result(atest, stest, dbstack, mfilename);
572 end % END UTP_08
573
574 %% UTP_09
575
576 % <TestDescription>
577 %
578 % Check that the interpmissing method pass back the output objects to a list of
579 % output variables or to a single variable.
580 %
581 % </TestDescription>
582 function result = utp_09
583
584 % <SyntaxDescription>
585 %
586 % Call the method with a list of output variables and with a single output
587 % variable. Additionaly check that the rebuild method works on the output.
588 %
589 % </SyntaxDescription>
590
591 try
592 % <SyntaxCode>
593 [o1, o2] = interpmissing(at5, at6);
594 o3 = interpmissing(at5, at6);
595 mout1 = rebuild(o1);
596 mout2 = rebuild(o2);
597 mout3 = rebuild(o3);
598 % </SyntaxCode>
599 stest = true;
600 catch err
601 disp(err.message)
602 stest = false;
603 end
604
605 % <AlgoDescription>
606 %
607 % 1) Check that the output contains the right number of objects
608 % 2) Check that the 'rebuild' method produces the same object as 'out'.
609 %
610 % </AlgoDescription>
611
612 atest = true;
613 if stest
614 % <AlgoCode>
615 % Check the number of outputs
616 if numel(o1) ~=1, atest = false; end
617 if numel(o2) ~=1, atest = false; end
618 if numel(o3) ~=2, atest = false; end
619 % Check the rebuilding of the object
620 if ~eq(o1, mout1, ple2), atest = false; end
621 if ~eq(o2, mout2, ple2), atest = false; end
622 if ~eq(o3, mout3, ple2), atest = false; end
623 % </AlgoCode>
624 else
625 atest = false;
626 end
627
628 % Return a result structure
629 result = utp_prepare_result(atest, stest, dbstack, mfilename);
630 end % END UTP_09
631
632 %% UTP_10
633
634 % <TestDescription>
635 %
636 % Tests that the interpmissing method can change the tolerance for finding
637 % missing samples.
638 %
639 % </TestDescription>
640 function result = utp_10
641
642 % <SyntaxDescription>
643 %
644 % Test that the interpmissing method works with a plist which changes the
645 % tolerance. Known gaps at the position idx = 30 and 51 with the width of 40
646 % and 60
647 %
648 % </SyntaxDescription>
649
650 try
651 % <SyntaxCode>
652 pl1 = plist('d', 41); % This tolerance supress the first gap
653 pl2 = plist('d', 61); % This tolerance supress all gaps
654 out1 = interpmissing(at1, pl1);
655 out2 = interpmissing(at1, pl2);
656 mout1 = rebuild(out1);
657 mout2 = rebuild(out2);
658 % </SyntaxCode>
659 stest = true;
660 catch err
661 disp(err.message)
662 stest = false;
663 end
664
665 % <AlgoDescription>
666 %
667 % 1) Check that the number of elements in 'out' is the same as in
668 % input.
669 % 2) Check that each output AO contains the correct data.
670 % 3) Check that the re-built object is the same as 'out'.
671 %
672 % </AlgoDescription>
673
674 atest = true;
675 if stest
676 % <AlgoCode>
677 % Check each output data
678 x = at1.data.getX;
679 % Gap at index position 51
680 gap2 = x(51+1) - x(51) - 1/at1.fs;
681 gap2_t = ((1/at1.fs : 1/at1.fs : gap2) + x(51)).';
682 % Create t
683 t = [x(1:51); gap2_t; x(52:end)];
684 % Interpolate the missing samples
685 res = interp(at1, plist('vertices', t));
686 % Depending to the tolerance have at1 only one gap
687 if ~isequal(out1.x, res.x), atest = false; end
688 if ~isequal(out1.y, res.y), atest = false; end
689 % Depending to the tolerance have no gaps
690 if ~isequal(out2.x, at1.x), atest = false; end
691 if ~isequal(out2.y, at1.y), atest = false; end
692 % Check the re-built object
693 if ~eq(mout1, out1, ple2), atest = false; end
694 if ~eq(mout2, out2, ple2), atest = false; end
695 % </AlgoCode>
696 else
697 atest = false;
698 end
699
700 % Return a result structure
701 result = utp_prepare_result(atest, stest, dbstack, mfilename);
702 end % END UTP_10
703
704 end