Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_resample.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_RESAMPLE a set of UTPs for the ao/resample method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_resample.m,v 1.11 2009/08/07 11:27:09 hewitson Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The resample method of the ao class resamples time-series AOs. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_resample(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'resample'; | |
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 input data shape == output data shape | |
43 results = [results utp_09]; % Test output of the data | |
44 results = [results utp_11(mthd, at1, ple1, plist('fsout', at1.fs*2))]; % Test plotinfo doesn't disappear | |
45 | |
46 disp('Done.'); | |
47 disp('******************************************************'); | |
48 | |
49 elseif nargin == 1 % Check for UTP functions | |
50 if strcmp(varargin{1}, 'isutp') | |
51 results = 1; | |
52 else | |
53 results = 0; | |
54 end | |
55 else | |
56 error('### Incorrect inputs') | |
57 end | |
58 | |
59 %% UTP_01 | |
60 | |
61 % <TestDescription> | |
62 % | |
63 % Tests that the getInfo call works for this method. | |
64 % | |
65 % </TestDescription> | |
66 function result = utp_01 | |
67 | |
68 | |
69 % <SyntaxDescription> | |
70 % | |
71 % Test that the getInfo call works for no sets, all sets, and each set | |
72 % individually. | |
73 % | |
74 % </SyntaxDescription> | |
75 | |
76 try | |
77 % <SyntaxCode> | |
78 % Call for no sets | |
79 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
80 % Call for all sets | |
81 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
82 % Call for each set | |
83 for kk=1:numel(io(2).sets) | |
84 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
85 end | |
86 % </SyntaxCode> | |
87 stest = true; | |
88 catch err | |
89 disp(err.message) | |
90 stest = false; | |
91 end | |
92 | |
93 % <AlgoDescription> | |
94 % | |
95 % 1) Check that getInfo call returned an minfo object in all cases. | |
96 % 2) Check that all plists have the correct parameters. | |
97 % | |
98 % </AlgoDescription> | |
99 | |
100 atest = true; | |
101 if stest | |
102 % <AlgoCode> | |
103 % check we have minfo objects | |
104 if isa(io, 'minfo') | |
105 %%% SET 'None' | |
106 if ~isempty(io(1).sets), atest = false; end | |
107 if ~isempty(io(1).plists), atest = false; end | |
108 %%% Check all Sets | |
109 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
110 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
111 %%%%%%%%%% SET 'Default' | |
112 if io(3).plists.nparams ~= 2, atest = false; end | |
113 % Check key | |
114 if ~io(3).plists.isparam('fsout'), atest = false; end | |
115 if ~io(3).plists.isparam('filter'), atest = false; end | |
116 % Check default value | |
117 if ~isEmptyDouble(io(3).plists.find('fsout')), atest = false; end | |
118 if ~isEmptyChar(io(3).plists.find('filter')), atest = false; end | |
119 % Check options | |
120 if ~isequal(io(3).plists.getOptionsForParam('fsout'), {[]}), atest = false; end | |
121 if ~isequal(io(3).plists.getOptionsForParam('filter'), {''}), atest = false; end | |
122 end | |
123 % </AlgoCode> | |
124 else | |
125 atest = false; | |
126 end | |
127 | |
128 % Return a result structure | |
129 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
130 end % END UTP_01 | |
131 | |
132 %% UTP_02 | |
133 | |
134 % <TestDescription> | |
135 % | |
136 % Tests that the resample method works with a vector of AOs as input. | |
137 % | |
138 % </TestDescription> | |
139 function result = utp_02 | |
140 | |
141 % <SyntaxDescription> | |
142 % | |
143 % Test that the resample method works for a vector of AOs as input. | |
144 % | |
145 % </SyntaxDescription> | |
146 | |
147 try | |
148 % <SyntaxCode> | |
149 avec = [at1 at5 at6]; | |
150 out = resample(avec, plist('FSOUT', 5)); | |
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 % </AlgoCode> | |
172 else | |
173 atest = false; | |
174 end | |
175 | |
176 % Return a result structure | |
177 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
178 end % END UTP_02 | |
179 | |
180 %% UTP_03 | |
181 | |
182 % <TestDescription> | |
183 % | |
184 % Tests that the resample method works with a matrix of AOs as input. | |
185 % | |
186 % </TestDescription> | |
187 function result = utp_03 | |
188 | |
189 % <SyntaxDescription> | |
190 % | |
191 % Test that the resample method works for a matrix of AOs as input. | |
192 % | |
193 % </SyntaxDescription> | |
194 | |
195 try | |
196 % <SyntaxCode> | |
197 amat = [at1 at5 at6; at5 at6 at1]; | |
198 out = resample(amat, plist('FSOUT', 5)); | |
199 % </SyntaxCode> | |
200 stest = true; | |
201 catch err | |
202 disp(err.message) | |
203 stest = false; | |
204 end | |
205 | |
206 % <AlgoDescription> | |
207 % | |
208 % 1) Check that the number of elements in 'out' is the square of the | |
209 % number in the input. | |
210 % 2) Check that each output AO contains the correct data. | |
211 % | |
212 % </AlgoDescription> | |
213 | |
214 atest = true; | |
215 if stest | |
216 % <AlgoCode> | |
217 % Check we have the correct number of outputs | |
218 if numel(out) ~= numel(amat), atest = false; end | |
219 % </AlgoCode> | |
220 else | |
221 atest = false; | |
222 end | |
223 | |
224 % Return a result structure | |
225 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
226 end % END UTP_03 | |
227 | |
228 %% UTP_04 | |
229 | |
230 % <TestDescription> | |
231 % | |
232 % Tests that the resample method works with a list of AOs as input. | |
233 % | |
234 % </TestDescription> | |
235 function result = utp_04 | |
236 | |
237 % <SyntaxDescription> | |
238 % | |
239 % Test that the resample method works for a list of AOs as input. | |
240 % | |
241 % </SyntaxDescription> | |
242 | |
243 try | |
244 % <SyntaxCode> | |
245 out = resample(at1,at5,at6, plist('FSOUT', 5)); | |
246 % </SyntaxCode> | |
247 stest = true; | |
248 catch err | |
249 disp(err.message) | |
250 stest = false; | |
251 end | |
252 | |
253 % <AlgoDescription> | |
254 % | |
255 % 1) Check that the number of elements in 'out' is the square of the | |
256 % number in the input. | |
257 % 2) Check that each output AO contains the correct data. | |
258 % | |
259 % </AlgoDescription> | |
260 | |
261 atest = true; | |
262 if stest | |
263 % <AlgoCode> | |
264 % Check we have the correct number of outputs | |
265 if numel(out) ~= 3, atest = false; end | |
266 % </AlgoCode> | |
267 else | |
268 atest = false; | |
269 end | |
270 | |
271 % Return a result structure | |
272 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
273 end % END UTP_04 | |
274 | |
275 %% UTP_05 | |
276 | |
277 % <TestDescription> | |
278 % | |
279 % Tests that the resample method works with a mix of different shaped AOs as | |
280 % input. | |
281 % | |
282 % </TestDescription> | |
283 function result = utp_05 | |
284 | |
285 % <SyntaxDescription> | |
286 % | |
287 % Test that the resample method works with an input of matrices and vectors | |
288 % and single AOs. | |
289 % | |
290 % </SyntaxDescription> | |
291 | |
292 try | |
293 % <SyntaxCode> | |
294 out = resample(at1,[at5 at6],at5,[at5 at1; at6 at1],at6, plist('FSOUT', 5)); | |
295 % </SyntaxCode> | |
296 stest = true; | |
297 catch err | |
298 disp(err.message) | |
299 stest = false; | |
300 end | |
301 | |
302 % <AlgoDescription> | |
303 % | |
304 % 1) Check that the number of elements in 'out' is the same as in | |
305 % input. | |
306 % 2) Check that each output AO contains the correct data. | |
307 % </AlgoDescription> | |
308 | |
309 atest = true; | |
310 if stest | |
311 % <AlgoCode> | |
312 % Check we have the correct number of outputs | |
313 if numel(out) ~= 9, atest = false; end | |
314 % </AlgoCode> | |
315 else | |
316 atest = false; | |
317 end | |
318 | |
319 % Return a result structure | |
320 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
321 end % END UTP_05 | |
322 | |
323 %% UTP_06 | |
324 | |
325 % <TestDescription> | |
326 % | |
327 % Tests that the resample method properly applies history. | |
328 % | |
329 % </TestDescription> | |
330 function result = utp_06 | |
331 | |
332 % <SyntaxDescription> | |
333 % | |
334 % Test that the result of applying the resample method can be processed back | |
335 % to an m-file. | |
336 % | |
337 % </SyntaxDescription> | |
338 | |
339 try | |
340 % <SyntaxCode> | |
341 out = resample(at5, plist('FSOUT', 5)); | |
342 mout = rebuild(out); | |
343 % </SyntaxCode> | |
344 stest = true; | |
345 catch err | |
346 disp(err.message) | |
347 stest = false; | |
348 end | |
349 | |
350 % <AlgoDescription> | |
351 % | |
352 % 1) Check that the last entry in the history of 'out' corresponds to | |
353 % 'resample'. | |
354 % 2) Check that the re-built object is the same object as 'out'. | |
355 % | |
356 % </AlgoDescription> | |
357 | |
358 atest = true; | |
359 if stest | |
360 % <AlgoCode> | |
361 % Check the last step in the history of 'out' | |
362 if ~strcmp(out.hist.methodInfo.mname, 'resample'), atest = false; end | |
363 % Check the re-built object | |
364 if ~eq(mout, out, ple2), atest = false; end | |
365 % </AlgoCode> | |
366 else | |
367 atest = false; | |
368 end | |
369 | |
370 % Return a result structure | |
371 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
372 end % END UTP_06 | |
373 | |
374 %% UTP_07 | |
375 | |
376 % <TestDescription> | |
377 % | |
378 % Tests that the resample method can modify the input AO. | |
379 % | |
380 % </TestDescription> | |
381 function result = utp_07 | |
382 | |
383 % <SyntaxDescription> | |
384 % | |
385 % Test that the resample method can modify the input AO by calling with no | |
386 % output and that the method doesn't change the input of the function | |
387 % notation (with a equal sign). | |
388 % | |
389 % </SyntaxDescription> | |
390 | |
391 try | |
392 % <SyntaxCode> | |
393 pl = plist('fsout', 3); | |
394 % copy at1 to work with | |
395 ain = ao(at1); | |
396 % modify ain | |
397 aout = ain.resample(pl); | |
398 ain.resample(pl); | |
399 % </SyntaxCode> | |
400 stest = true; | |
401 catch err | |
402 disp(err.message) | |
403 stest = false; | |
404 end | |
405 | |
406 % <AlgoDescription> | |
407 % | |
408 % 1) Check that 'at1' and 'ain' are now different. | |
409 % 2) Check that 'ain' is resample(at1). | |
410 % | |
411 % </AlgoDescription> | |
412 | |
413 atest = true; | |
414 if stest | |
415 % <AlgoCode> | |
416 % Check that resample modified the input by comparing to the copy | |
417 if eq(ao(at1), ain, ple1), atest = false; end | |
418 % Check that resample doesn't modified the input for the function notation | |
419 if ~eq(aout, ain, ple1), atest = false; end | |
420 % </AlgoCode> | |
421 else | |
422 atest = false; | |
423 end | |
424 | |
425 % Return a result structure | |
426 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
427 end % END UTP_07 | |
428 | |
429 %% UTP_08 | |
430 | |
431 % <TestDescription> | |
432 % | |
433 % Control the method with a plist. | |
434 % | |
435 % </TestDescription> | |
436 function result = utp_08 | |
437 | |
438 % <SyntaxDescription> | |
439 % | |
440 % Test that the resample method keeps the data shape of the input object. The | |
441 % input AO must be an AO with row data and an AO with column data. | |
442 % | |
443 % </SyntaxDescription> | |
444 | |
445 try | |
446 pl = plist('fsout', 3); | |
447 % <SyntaxCode> | |
448 out1 = resample(at5, pl); | |
449 out2 = resample(at6, 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 the shpe of the data doesn't change. | |
460 % | |
461 % </AlgoDescription> | |
462 | |
463 atest = true; | |
464 if stest | |
465 % <AlgoCode> | |
466 % Check the shape of the output data | |
467 if size(out1.data.y) ~= size(at5.data.y), atest = false; end | |
468 if size(out2.data.y) ~= size(at6.data.y), atest = false; end | |
469 % </AlgoCode> | |
470 else | |
471 atest = false; | |
472 end | |
473 | |
474 % Return a result structure | |
475 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
476 end % END UTP_08 | |
477 | |
478 %% UTP_09 | |
479 | |
480 % <TestDescription> | |
481 % | |
482 % Check that the resample method pass back the output objects to a list of | |
483 % output variables or to a single variable. | |
484 % | |
485 % </TestDescription> | |
486 function result = utp_09 | |
487 | |
488 % <SyntaxDescription> | |
489 % | |
490 % Call the method with a list of output variables and with a single output | |
491 % variable. Additionaly check that the rebuild method works on the output. | |
492 % | |
493 % </SyntaxDescription> | |
494 | |
495 try | |
496 % <SyntaxCode> | |
497 pl = plist('fsout', 3); | |
498 [o1, o2] = resample(at5, at6, pl); | |
499 o3 = resample(at5, at6, pl); | |
500 mout1 = rebuild(o1); | |
501 mout2 = rebuild(o2); | |
502 mout3 = rebuild(o3); | |
503 % </SyntaxCode> | |
504 stest = true; | |
505 catch err | |
506 disp(err.message) | |
507 stest = false; | |
508 end | |
509 | |
510 % <AlgoDescription> | |
511 % | |
512 % 1) Check that the output contains the right number of objects | |
513 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
514 % | |
515 % </AlgoDescription> | |
516 | |
517 atest = true; | |
518 if stest | |
519 % <AlgoCode> | |
520 % Check the number of outputs | |
521 if numel(o1) ~=1, atest = false; end | |
522 if numel(o2) ~=1, atest = false; end | |
523 if numel(o3) ~=2, atest = false; end | |
524 % Check the rebuilding of the object | |
525 if ~eq(o1, mout1, ple2), atest = false; end | |
526 if ~eq(o2, mout2, ple2), atest = false; end | |
527 if ~eq(o3, mout3, ple2), atest = false; end | |
528 % </AlgoCode> | |
529 else | |
530 atest = false; | |
531 end | |
532 | |
533 % Return a result structure | |
534 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
535 end % END UTP_09 | |
536 | |
537 end |