Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_downsample.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_DOWNSAMPLE a set of UTPs for the ao/downsample method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_downsample.m,v 1.14 2009/09/20 16:51:33 hewitson Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The downsample method of the ao class downsamples time-series AOs. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_downsample(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'downsample'; | |
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 results = [results utp_01]; % getInfo call | |
36 results = [results utp_02]; % Vector input | |
37 results = [results utp_03]; % Matrix input | |
38 results = [results utp_04]; % List input | |
39 results = [results utp_05]; % Test with mixed input | |
40 results = [results utp_06]; % Test history is working | |
41 results = [results utp_07]; % Test the modify call works | |
42 results = [results utp_08]; % Test the data shape | |
43 results = [results utp_09]; % Test output of the data | |
44 results = [results utp_10]; % Test with plist: 'offset' and 'factor' | |
45 | |
46 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear | |
47 results = [results utp_12(mthd, at1, ple1)]; % Test errors are cleared | |
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('factor'), atest = false; end | |
118 if ~io(3).plists.isparam('offset'), atest = false; end | |
119 % Check default value | |
120 if ~isequal(io(3).plists.find('factor'), 1), atest = false; end | |
121 if ~isequal(io(3).plists.find('offset'), 0), atest = false; end | |
122 % Check options | |
123 if ~isequal(io(3).plists.getOptionsForParam('factor'), {1}), atest = false; end | |
124 if ~isequal(io(3).plists.getOptionsForParam('offset'), {0}), atest = false; end | |
125 end | |
126 % </AlgoCode> | |
127 else | |
128 atest = false; | |
129 end | |
130 | |
131 % Return a result structure | |
132 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
133 end % END UTP_01 | |
134 | |
135 %% UTP_02 | |
136 | |
137 % <TestDescription> | |
138 % | |
139 % Tests that the downsample method works with a vector of AOs as input. | |
140 % | |
141 % </TestDescription> | |
142 function result = utp_02 | |
143 | |
144 % <SyntaxDescription> | |
145 % | |
146 % Test that the downsample method works for a vector of AOs as input. | |
147 % | |
148 % </SyntaxDescription> | |
149 | |
150 try | |
151 % <SyntaxCode> | |
152 factor = 2; | |
153 avec = [at1 at5 at6]; | |
154 out = downsample(avec, plist('Factor', factor)); | |
155 % </SyntaxCode> | |
156 stest = true; | |
157 catch err | |
158 disp(err.message) | |
159 stest = false; | |
160 end | |
161 | |
162 % <AlgoDescription> | |
163 % | |
164 % 1) Check that the number of elements in 'out' is the square of the | |
165 % number in the input. | |
166 % 2) Check that each output AO contains the correct data. | |
167 % | |
168 % </AlgoDescription> | |
169 | |
170 TOL = 1e-13; | |
171 atest = true; | |
172 if stest | |
173 % <AlgoCode> | |
174 % Check we have the correct number of outputs | |
175 if numel(out) ~= numel(avec), atest = false; end | |
176 % Check the downsampling | |
177 for kk = 1:numel(avec) | |
178 samples = 1:factor:length(avec(kk).y); | |
179 if ~isequal(avec(kk).data.getY(samples), out(kk).y), atest = false; end | |
180 if any(abs(avec(kk).data.getX(samples)-out(kk).x)>TOL), atest = false; end | |
181 end | |
182 % </AlgoCode> | |
183 else | |
184 atest = false; | |
185 end | |
186 | |
187 % Return a result structure | |
188 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
189 end % END UTP_02 | |
190 | |
191 %% UTP_03 | |
192 | |
193 % <TestDescription> | |
194 % | |
195 % Tests that the downsample method works with a matrix of AOs as input. | |
196 % | |
197 % </TestDescription> | |
198 function result = utp_03 | |
199 | |
200 % <SyntaxDescription> | |
201 % | |
202 % Test that the downsample method works for a matrix of AOs as input. | |
203 % | |
204 % </SyntaxDescription> | |
205 | |
206 try | |
207 % <SyntaxCode> | |
208 factor = 3; | |
209 amat = [at1 at5 at6; at5 at6 at1]; | |
210 out = downsample(amat, plist('Factor', factor)); | |
211 % </SyntaxCode> | |
212 stest = true; | |
213 catch err | |
214 disp(err.message) | |
215 stest = false; | |
216 end | |
217 | |
218 % <AlgoDescription> | |
219 % | |
220 % 1) Check that the number of elements in 'out' is the square of the | |
221 % number in the input. | |
222 % 2) Check that each output AO contains the correct data. | |
223 % | |
224 % </AlgoDescription> | |
225 | |
226 TOL = 1e-6; | |
227 atest = true; | |
228 warning('### This UTP have very high tolerance'); | |
229 if stest | |
230 % <AlgoCode> | |
231 % Check we have the correct number of outputs | |
232 if numel(out) ~= numel(amat), atest = false; end | |
233 % Check the downsampling | |
234 for kk = 1:numel(amat) | |
235 samples = 1:factor:length(amat(kk).y); | |
236 if ~isequal(amat(kk).data.getY(samples), out(kk).y), atest = false; end | |
237 if any(abs(amat(kk).data.getX(samples)-out(kk).x)>TOL), atest = false; end | |
238 end | |
239 % </AlgoCode> | |
240 else | |
241 atest = false; | |
242 end | |
243 | |
244 % Return a result structure | |
245 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
246 end % END UTP_03 | |
247 | |
248 %% UTP_04 | |
249 | |
250 % <TestDescription> | |
251 % | |
252 % Tests that the downsample method works with a list of AOs as input. | |
253 % | |
254 % </TestDescription> | |
255 function result = utp_04 | |
256 | |
257 % <SyntaxDescription> | |
258 % | |
259 % Test that the downsample method works for a list of AOs as input. | |
260 % | |
261 % </SyntaxDescription> | |
262 | |
263 try | |
264 % <SyntaxCode> | |
265 factor = 2; | |
266 out = downsample(at1,at5,at6, plist('Factor', factor)); | |
267 % </SyntaxCode> | |
268 stest = true; | |
269 catch err | |
270 disp(err.message) | |
271 stest = false; | |
272 end | |
273 | |
274 % <AlgoDescription> | |
275 % | |
276 % 1) Check that the number of elements in 'out' is the square of the | |
277 % number in the input. | |
278 % 2) Check that each output AO contains the correct data. | |
279 % | |
280 % </AlgoDescription> | |
281 | |
282 atest = true; | |
283 aoin = [at1, at5, at6]; | |
284 TOL = 1e-14; | |
285 if stest | |
286 % <AlgoCode> | |
287 % Check we have the correct number of outputs | |
288 if numel(out) ~= 3, atest = false; end | |
289 % Check the downsampling | |
290 for kk = 1:numel(aoin) | |
291 samples = 1:factor:length(aoin(kk).y); | |
292 if ~isequal(aoin(kk).data.getY(samples), out(kk).y), atest = false; end | |
293 if any(abs(aoin(kk).data.getX(samples)-out(kk).x)>TOL), atest = false; end | |
294 end | |
295 % </AlgoCode> | |
296 else | |
297 atest = false; | |
298 end | |
299 | |
300 % Return a result structure | |
301 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
302 end % END UTP_04 | |
303 | |
304 %% UTP_05 | |
305 | |
306 % <TestDescription> | |
307 % | |
308 % Tests that the downsample method works with a mix of different shaped AOs as | |
309 % input. | |
310 % | |
311 % </TestDescription> | |
312 function result = utp_05 | |
313 | |
314 % <SyntaxDescription> | |
315 % | |
316 % Test that the downsample method works with an input of matrices and vectors | |
317 % and single AOs. | |
318 % | |
319 % </SyntaxDescription> | |
320 | |
321 try | |
322 % <SyntaxCode> | |
323 factor = 2; | |
324 out = downsample(at1,[at5 at6],at5,[at5 at1; at6 at1],at6, plist('Factor', factor)); | |
325 % </SyntaxCode> | |
326 stest = true; | |
327 catch err | |
328 disp(err.message) | |
329 stest = false; | |
330 end | |
331 | |
332 % <AlgoDescription> | |
333 % | |
334 % 1) Check that the number of elements in 'out' is the same as in | |
335 % input. | |
336 % 2) Check that each output AO contains the correct data. | |
337 % | |
338 % </AlgoDescription> | |
339 | |
340 atest = true; | |
341 aoin = [at1, reshape([at5 at6], 1, []), at5, reshape([at5 at1; at6 at1], 1, []), at6]; | |
342 TOL = 1e-14; | |
343 if stest | |
344 % <AlgoCode> | |
345 % Check we have the correct number of outputs | |
346 if numel(out) ~= 9, atest = false; end | |
347 % Check the downsampling | |
348 for kk = 1:numel(aoin) | |
349 samples = 1:factor:length(aoin(kk).y); | |
350 if ~isequal(aoin(kk).data.getY(samples), out(kk).y), atest = false; end | |
351 if any(abs(aoin(kk).data.getX(samples)-out(kk).x)>TOL), atest = false; end | |
352 end | |
353 % </AlgoCode> | |
354 else | |
355 atest = false; | |
356 end | |
357 | |
358 % Return a result structure | |
359 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
360 end % END UTP_05 | |
361 | |
362 %% UTP_06 | |
363 | |
364 % <TestDescription> | |
365 % | |
366 % Tests that the downsample method properly applies history. | |
367 % | |
368 % </TestDescription> | |
369 function result = utp_06 | |
370 | |
371 % <SyntaxDescription> | |
372 % | |
373 % Test that the result of applying the downsample method can be processed back | |
374 % to an m-file. | |
375 % | |
376 % </SyntaxDescription> | |
377 | |
378 try | |
379 % <SyntaxCode> | |
380 out = downsample(at5,plist('Factor', 2)); | |
381 mout = rebuild(out); | |
382 % </SyntaxCode> | |
383 stest = true; | |
384 catch err | |
385 disp(err.message) | |
386 stest = false; | |
387 end | |
388 | |
389 % <AlgoDescription> | |
390 % | |
391 % 1) Check that the last entry in the history of 'out' corresponds to | |
392 % 'downsample'. | |
393 % 2) Check that the re-built object is the same object as 'out'. | |
394 % | |
395 % </AlgoDescription> | |
396 | |
397 atest = true; | |
398 if stest | |
399 % <AlgoCode> | |
400 % Check the last step in the history of 'out' | |
401 if ~strcmp(out.hist.methodInfo.mname, 'downsample'), atest = false; end | |
402 % Check the re-built object | |
403 if ~eq(mout, out, ple2), atest = false; end | |
404 % </AlgoCode> | |
405 else | |
406 atest = false; | |
407 end | |
408 | |
409 % Return a result structure | |
410 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
411 end % END UTP_06 | |
412 | |
413 %% UTP_07 | |
414 | |
415 % <TestDescription> | |
416 % | |
417 % Tests that the downsample method can modify the input AO. | |
418 % | |
419 % </TestDescription> | |
420 function result = utp_07 | |
421 | |
422 % <SyntaxDescription> | |
423 % | |
424 % Test that the downsample method can modify the input AO by calling with no | |
425 % output. | |
426 % | |
427 % </SyntaxDescription> | |
428 | |
429 try | |
430 % <SyntaxCode> | |
431 % copy at1 to work with | |
432 ain = ao(at1); | |
433 % modify ain | |
434 factor = 5; | |
435 pl = plist('factor', factor); | |
436 aout = ain.downsample(pl); | |
437 ain.downsample(pl); | |
438 % </SyntaxCode> | |
439 stest = true; | |
440 catch err | |
441 disp(err.message) | |
442 stest = false; | |
443 end | |
444 | |
445 % <AlgoDescription> | |
446 % | |
447 % 1) Check that 'at1' and 'ain' are now different. | |
448 % 2) Check that 'ain' is downsample(at1). | |
449 % | |
450 % </AlgoDescription> | |
451 | |
452 atest = true; | |
453 TOL = 1e-14; | |
454 if stest | |
455 % <AlgoCode> | |
456 % Check that downsample modified the input by comparing to the copy | |
457 if eq(ao(at1), ain, ple1), atest = false; end | |
458 % Check that downsample doesn't modified the input for the function notation | |
459 if ~eq(aout, ain, ple1), atest = false; end | |
460 % Check that the modified input is the downsample of the copy | |
461 samples = 1:factor:length(at1.y); | |
462 if ~isequal(at1.data.getY(samples), ain.y), atest = false; end | |
463 if any(abs(at1.data.getX(samples)-ain.x)>TOL), atest = false; end | |
464 % </AlgoCode> | |
465 else | |
466 atest = false; | |
467 end | |
468 | |
469 % Return a result structure | |
470 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
471 end % END UTP_07 | |
472 | |
473 %% UTP_08 | |
474 | |
475 % <TestDescription> | |
476 % | |
477 % Tests that the downsample method keeps the data shape of the input object. | |
478 % | |
479 % </TestDescription> | |
480 function result = utp_08 | |
481 | |
482 % <SyntaxDescription> | |
483 % | |
484 % Test that the downsample method keeps the data shape of the input object. The | |
485 % input AO must be an AO with row data and an AO with column data. | |
486 % | |
487 % </SyntaxDescription> | |
488 | |
489 try | |
490 % <SyntaxCode> | |
491 factor = 3; | |
492 pl = plist('factor', factor); | |
493 out1 = downsample(at5, pl); | |
494 out2 = downsample(at6, pl); | |
495 % </SyntaxCode> | |
496 stest = true; | |
497 catch err | |
498 disp(err.message) | |
499 stest = false; | |
500 end | |
501 | |
502 % <AlgoDescription> | |
503 % | |
504 % 1) Check that the shpe of the data doesn't change. | |
505 % | |
506 % </AlgoDescription> | |
507 | |
508 atest = true; | |
509 if stest | |
510 % <AlgoCode> | |
511 % Check the shape of the output data | |
512 if size(out1.data.y,2) ~= 1, atest = false; end | |
513 if size(out2.data.y,1) ~= 1, atest = false; end | |
514 % </AlgoCode> | |
515 else | |
516 atest = false; | |
517 end | |
518 | |
519 % Return a result structure | |
520 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
521 end % END UTP_08 | |
522 | |
523 %% UTP_09 | |
524 | |
525 % <TestDescription> | |
526 % | |
527 % Check that the downsample method pass back the output objects to a list of | |
528 % output variables or to a single variable. | |
529 % | |
530 % </TestDescription> | |
531 function result = utp_09 | |
532 | |
533 % <SyntaxDescription> | |
534 % | |
535 % Call the method with a list of output variables and with a single output | |
536 % variable. Additionaly check that the rebuild method works on the output. | |
537 % | |
538 % </SyntaxDescription> | |
539 | |
540 try | |
541 % <SyntaxCode> | |
542 factor = 3; | |
543 pl = plist('factor', factor); | |
544 [o1, o2] = downsample(at5, at6, pl); | |
545 o3 = downsample(at5, at6, pl); | |
546 mout1 = rebuild(o1); | |
547 mout2 = rebuild(o2); | |
548 mout3 = rebuild(o3); | |
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 output contains the right number of objects | |
559 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
560 % | |
561 % </AlgoDescription> | |
562 | |
563 atest = true; | |
564 if stest | |
565 % <AlgoCode> | |
566 % Check the number of outputs | |
567 if numel(o1) ~=1, atest = false; end | |
568 if numel(o2) ~=1, atest = false; end | |
569 if numel(o3) ~=2, atest = false; end | |
570 % Check the rebuilding of the object | |
571 if ~eq(o1, mout1, ple2), atest = false; end | |
572 if ~eq(o2, mout2, ple2), atest = false; end | |
573 if ~eq(o3, mout3, ple2), atest = false; end | |
574 % </AlgoCode> | |
575 else | |
576 atest = false; | |
577 end | |
578 | |
579 % Return a result structure | |
580 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
581 end % END UTP_09 | |
582 | |
583 %% UTP_10 | |
584 | |
585 % <TestDescription> | |
586 % | |
587 % Control the method with a plist. | |
588 % | |
589 % </TestDescription> | |
590 function result = utp_10 | |
591 | |
592 % <SyntaxDescription> | |
593 % | |
594 % Test the downsample method with a factor and an offset. | |
595 % | |
596 % </SyntaxDescription> | |
597 | |
598 try | |
599 % <SyntaxCode> | |
600 factor = 3; | |
601 offset = 30; | |
602 pl = plist('factor', factor, 'offset', offset); | |
603 out = downsample(at5, pl); | |
604 mout = rebuild(out); | |
605 % </SyntaxCode> | |
606 stest = true; | |
607 catch err | |
608 disp(err.message) | |
609 stest = false; | |
610 end | |
611 | |
612 % <AlgoDescription> | |
613 % | |
614 % 1) Check that the downsample method with an offset and a factor | |
615 % 2) Check that the re-built object is the same object as 'out'. | |
616 % | |
617 % </AlgoDescription> | |
618 | |
619 atest = true; | |
620 TOL = 1e-6; | |
621 warning('### This UTP have very high tolerance'); | |
622 if stest | |
623 % <AlgoCode> | |
624 samples = offset+1:factor:length(at5.data.y); | |
625 if ~isequal(at5.data.getY(samples), out.y), atest = false; end | |
626 % Add the t0 offset to the input AO | |
627 at5_x = at5.data.getX(samples); | |
628 out_x = out.x; | |
629 at5_x = at5_x - (out.t0.utc_epoch_milli - at5.t0.utc_epoch_milli)/1e3; | |
630 if any(abs(at5_x-out_x)>TOL), atest = false; end | |
631 % Check the re-built object | |
632 if ~eq(mout, out, ple2), atest = false; end | |
633 % </AlgoCode> | |
634 else | |
635 atest = false; | |
636 end | |
637 | |
638 % Return a result structure | |
639 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
640 end % END UTP_10 | |
641 | |
642 end |