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