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