Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_join_fsdata.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_JOIN a set of UTPs for the ao/join method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_join_fsdata.m,v 1.7 2010/07/05 08:11:03 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The join method of the ao class join multiple AOs into a single AO. This | |
11 % UTP join only analysis objects with fsdata. The other data objects will | |
12 % be tested in an other UTP. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_ao_join_fsdata(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'ao'; | |
23 mthd = 'join'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 % Exception list for the UTPs: | |
31 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
32 | |
33 % Run the tests | |
34 results = [results utp_01]; % getInfo call | |
35 results = [results utp_02]; % Vector input | |
36 results = [results utp_03]; % Matrix input | |
37 results = [results utp_04]; % List input | |
38 results = [results utp_05]; % Test with mixed input | |
39 results = [results utp_06]; % Test history is working | |
40 results = [results utp_07]; % Test the modify call works | |
41 results = [results utp_08]; % Test input data shape == output data shape | |
42 | |
43 a1 = ao(1:30, randn(30,1)+2*10, plist('type', 'fsdata')); | |
44 a2 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
45 results = [results utp_11(mthd, [a1 a2], 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('zerofill'), atest = false; end | |
116 if ~io(3).plists.isparam('sameT0'), atest = false; end | |
117 if ~io(3).plists.isparam('fstol'), atest = false; end | |
118 % Check default value | |
119 if ~isequal(io(3).plists.find('zerofill'), 'no'), atest = false; end | |
120 if ~isequal(io(3).plists.find('samet0'), 'no'), atest = false; end | |
121 if ~isequal(io(3).plists.find('fstol'), 1e-6), atest = false; end | |
122 % Check options | |
123 if ~isequal(io(3).plists.getOptionsForParam('zerofill'), {'yes', 'no'}), atest = false; end | |
124 if ~isequal(io(3).plists.getOptionsForParam('samet0'), {'yes', 'no'}), atest = false; end | |
125 if ~isequal(io(3).plists.getOptionsForParam('fstol'), {1e-6}), 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 join 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 join method works for a vector of AOs as input. | |
148 % | |
149 % </SyntaxDescription> | |
150 | |
151 try | |
152 % <SyntaxCode> | |
153 a1 = ao(1:30, randn(30,1)+2*10, plist('type', 'fsdata')); | |
154 a2 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
155 a3 = ao(1.2:30.2, randn(30,1)+2*10, plist('type', 'fsdata')); | |
156 avec = [a1, a2, a3]; | |
157 out = join(avec); | |
158 mout = rebuild(out); | |
159 % </SyntaxCode> | |
160 stest = true; | |
161 catch err | |
162 disp(err.message) | |
163 stest = false; | |
164 end | |
165 | |
166 % <AlgoDescription> | |
167 % | |
168 % 1) Check that the output is exact one AO. | |
169 % 2) Check that the output have the correct data. | |
170 % 3) Check the re-built object | |
171 % | |
172 % </AlgoDescription> | |
173 | |
174 atest = true; | |
175 if stest | |
176 % <AlgoCode> | |
177 % Check we have the correct number of outputs | |
178 if numel(out) ~= 1, atest = false; end | |
179 % Compute reference data | |
180 x0 = []; | |
181 y0 = []; | |
182 for oo = 1:numel(avec) | |
183 if isempty(x0) | |
184 idxBefore = []; | |
185 idxAfter = 1:numel(avec(oo).y); | |
186 else | |
187 idxBefore = find(avec(oo).x < x0(1)); | |
188 idxAfter = find(avec(oo).x > x0(end)); | |
189 end | |
190 x0 = [avec(oo).x(idxBefore); x0; avec(oo).x(idxAfter)]; | |
191 y0 = [avec(oo).y(idxBefore); y0; avec(oo).y(idxAfter)]; | |
192 end | |
193 if ~isequal(out.x, x0), atest = false; end | |
194 if ~isequal(out.y, y0), atest = false; end | |
195 if ~eq(out, mout, ple2), atest = false; end | |
196 % </AlgoCode> | |
197 else | |
198 atest = false; | |
199 end | |
200 | |
201 % Return a result structure | |
202 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
203 end % END UTP_02 | |
204 | |
205 %% UTP_03 | |
206 | |
207 % <TestDescription> | |
208 % | |
209 % Tests that the join method works with a matrix of AOs as input. | |
210 % | |
211 % </TestDescription> | |
212 function result = utp_03 | |
213 | |
214 % <SyntaxDescription> | |
215 % | |
216 % Tests that the join method works with a matrix of AOs as input. | |
217 % | |
218 % </SyntaxDescription> | |
219 | |
220 try | |
221 % <SyntaxCode> | |
222 a1 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
223 a2 = ao(1.2:30.2, randn(30,1)+2*10, plist('type', 'fsdata')); | |
224 a3 = ao(1.3:30.3, randn(30,1)+2*10, plist('type', 'fsdata')); | |
225 a4 = ao(1.4:30.4, randn(30,1)+2*10, plist('type', 'fsdata')); | |
226 a5 = ao(1.5:30.5, randn(30,1)+2*10, plist('type', 'fsdata')); | |
227 a6 = ao(1.6:30.6, randn(30,1)+2*10, plist('type', 'fsdata')); | |
228 amat = [a1, a2, a3; a4, a5, a6]; | |
229 out = join(amat); | |
230 mout = rebuild(out); | |
231 % </SyntaxCode> | |
232 stest = true; | |
233 catch err | |
234 disp(err.message) | |
235 stest = false; | |
236 end | |
237 | |
238 % <AlgoDescription> | |
239 % | |
240 % 1) Check that the output is exact one AO. | |
241 % 2) Check that the output have the correct data. | |
242 % 3) Check the re-built object | |
243 % | |
244 % </AlgoDescription> | |
245 | |
246 atest = true; | |
247 if stest | |
248 % <AlgoCode> | |
249 % Check we have the correct number of outputs | |
250 if numel(out) ~= 1, atest = false; end | |
251 % Compute reference data | |
252 x0 = []; | |
253 y0 = []; | |
254 for oo = 1:numel(amat) | |
255 if isempty(x0) | |
256 idxBefore = []; | |
257 idxAfter = 1:numel(amat(oo).y); | |
258 else | |
259 idxBefore = find(amat(oo).x < x0(1)); | |
260 idxAfter = find(amat(oo).x > x0(end)); | |
261 end | |
262 x0 = [amat(oo).x(idxBefore); x0; amat(oo).x(idxAfter)]; | |
263 y0 = [amat(oo).y(idxBefore); y0; amat(oo).y(idxAfter)]; | |
264 end | |
265 if ~isequal(out.x, x0), atest = false; end | |
266 if ~isequal(out.y, y0), atest = false; end | |
267 if ~eq(out, mout, ple2), atest = false; end | |
268 % </AlgoCode> | |
269 else | |
270 atest = false; | |
271 end | |
272 | |
273 % Return a result structure | |
274 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
275 end % END UTP_03 | |
276 | |
277 %% UTP_04 | |
278 | |
279 % <TestDescription> | |
280 % | |
281 % Tests that the join method works with a list of AOs as input. | |
282 % | |
283 % </TestDescription> | |
284 function result = utp_04 | |
285 | |
286 % <SyntaxDescription> | |
287 % | |
288 % Tests that the join method works with a list of AOs as input. | |
289 % | |
290 % </SyntaxDescription> | |
291 | |
292 try | |
293 % <SyntaxCode> | |
294 a1 = ao(1:30, randn(30,1)+2*10, plist('type', 'fsdata')); | |
295 a2 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
296 a3 = ao(1.2:30.2, randn(30,1)+2*10, plist('type', 'fsdata')); | |
297 out = join(a1, a2, a3); | |
298 mout = rebuild(out); | |
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 output is exact one AO. | |
309 % 2) Check that the output have the correct data. | |
310 % 3) Check the re-built object | |
311 % | |
312 % </AlgoDescription> | |
313 | |
314 atest = true; | |
315 aoin = [a1, a2, a3]; | |
316 if stest | |
317 % <AlgoCode> | |
318 % Check we have the correct number of outputs | |
319 if numel(out) ~= 1, atest = false; end | |
320 % Compute reference data | |
321 x0 = []; | |
322 y0 = []; | |
323 for oo = 1:numel(aoin) | |
324 if isempty(x0) | |
325 idxBefore = []; | |
326 idxAfter = 1:numel(aoin(oo).y); | |
327 else | |
328 idxBefore = find(aoin(oo).x < x0(1)); | |
329 idxAfter = find(aoin(oo).x > x0(end)); | |
330 end | |
331 x0 = [aoin(oo).x(idxBefore); x0; aoin(oo).x(idxAfter)]; | |
332 y0 = [aoin(oo).y(idxBefore); y0; aoin(oo).y(idxAfter)]; | |
333 end | |
334 if ~isequal(out.x, x0), atest = false; end | |
335 if ~isequal(out.y, y0), atest = false; end | |
336 if ~eq(out, mout, ple2), atest = false; end | |
337 % </AlgoCode> | |
338 else | |
339 atest = false; | |
340 end | |
341 | |
342 % Return a result structure | |
343 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
344 end % END UTP_04 | |
345 | |
346 %% UTP_05 | |
347 | |
348 % <TestDescription> | |
349 % | |
350 % Tests that the join method works with a mix of different shaped AOs as | |
351 % input. | |
352 % | |
353 % </TestDescription> | |
354 function result = utp_05 | |
355 | |
356 % <SyntaxDescription> | |
357 % | |
358 % Tests that the join method works with a mix of different shaped AOs | |
359 % as input. | |
360 % | |
361 % </SyntaxDescription> | |
362 | |
363 try | |
364 % <SyntaxCode> | |
365 a1 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
366 a2 = ao(1.2:30.2, randn(30,1)+2*10, plist('type', 'fsdata')); | |
367 a3 = ao(1.3:30.3, randn(30,1)+2*10, plist('type', 'fsdata')); | |
368 a4 = ao(1.4:30.4, randn(30,1)+2*10, plist('type', 'fsdata')); | |
369 out = join(a1, a2, [a3 a4]); | |
370 mout = rebuild(out); | |
371 % </SyntaxCode> | |
372 stest = true; | |
373 catch err | |
374 disp(err.message) | |
375 stest = false; | |
376 end | |
377 | |
378 % <AlgoDescription> | |
379 % | |
380 % 1) Check that the output is exact one AO. | |
381 % 2) Check that the output have the correct data. | |
382 % 3) Check the re-built object | |
383 % | |
384 % </AlgoDescription> | |
385 | |
386 atest = true; | |
387 aoin = [a1, a2, a3, a4]; | |
388 if stest | |
389 % <AlgoCode> | |
390 % Check we have the correct number of outputs | |
391 if numel(out) ~= 1, atest = false; end | |
392 % Compute reference data | |
393 x0 = []; | |
394 y0 = []; | |
395 for oo = 1:numel(aoin) | |
396 if isempty(x0) | |
397 idxBefore = []; | |
398 idxAfter = 1:numel(aoin(oo).y); | |
399 else | |
400 idxBefore = find(aoin(oo).x < x0(1)); | |
401 idxAfter = find(aoin(oo).x > x0(end)); | |
402 end | |
403 x0 = [aoin(oo).x(idxBefore); x0; aoin(oo).x(idxAfter)]; | |
404 y0 = [aoin(oo).y(idxBefore); y0; aoin(oo).y(idxAfter)]; | |
405 end | |
406 if ~isequal(out.x, x0), atest = false; end | |
407 if ~isequal(out.y, y0), atest = false; end | |
408 if ~eq(out, mout, ple2), atest = false; end | |
409 % </AlgoCode> | |
410 else | |
411 atest = false; | |
412 end | |
413 | |
414 % Return a result structure | |
415 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
416 end % END UTP_05 | |
417 | |
418 %% UTP_06 | |
419 | |
420 % <TestDescription> | |
421 % | |
422 % Tests that the join method properly applies history. | |
423 % | |
424 % </TestDescription> | |
425 function result = utp_06 | |
426 | |
427 % <SyntaxDescription> | |
428 % | |
429 % Test that the result of applying the join method can be processed back. | |
430 % | |
431 % </SyntaxDescription> | |
432 | |
433 try | |
434 % <SyntaxCode> | |
435 a1 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
436 a2 = ao(1.2:30.2, randn(30,1)+2*10, plist('type', 'fsdata')); | |
437 | |
438 out = join(a1, a2); | |
439 mout = rebuild(out); | |
440 % </SyntaxCode> | |
441 stest = true; | |
442 catch err | |
443 disp(err.message) | |
444 stest = false; | |
445 end | |
446 | |
447 % <AlgoDescription> | |
448 % | |
449 % 1) Check that the last entry in the history of 'out' corresponds to | |
450 % 'join'. | |
451 % 2) Check that the re-built object is the same object as the input. | |
452 % | |
453 % </AlgoDescription> | |
454 | |
455 atest = true; | |
456 if stest | |
457 % <AlgoCode> | |
458 % Check the last step in the history of 'out' | |
459 if ~strcmp(out.hist.methodInfo.mname, 'join'), atest = false; end | |
460 % The rebuilt object must be the same as 'out' | |
461 if ~eq(mout, out, ple2), atest = false; end | |
462 % </AlgoCode> | |
463 else | |
464 atest = false; | |
465 end | |
466 | |
467 % Return a result structure | |
468 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
469 end % END UTP_06 | |
470 | |
471 %% UTP_07 | |
472 | |
473 % <TestDescription> | |
474 % | |
475 % Tests that the join method can modify the input AO. | |
476 % | |
477 % </TestDescription> | |
478 function result = utp_07 | |
479 | |
480 % <SyntaxDescription> | |
481 % | |
482 % Test that the join method can modify the input AO by calling with no | |
483 % output and that the method doesn't change the input of the function | |
484 % notation (with a equal sign). | |
485 % | |
486 % </SyntaxDescription> | |
487 | |
488 try | |
489 % <SyntaxCode> | |
490 % copy at1 to work with | |
491 a1 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
492 a2 = ao(1.2:30.2, randn(30,1)+2*10, plist('type', 'fsdata')); | |
493 a1.setT0('2009-02-12 14:00:00'); | |
494 a2.setT0('2009-02-12 14:00:25'); | |
495 | |
496 amodi = ao(a1); | |
497 aeq = ao(a1); | |
498 out = aeq.join(a2); | |
499 amodi.join(a2); | |
500 % </SyntaxCode> | |
501 stest = true; | |
502 catch err | |
503 disp(err.message) | |
504 stest = false; | |
505 end | |
506 | |
507 % <AlgoDescription> | |
508 % | |
509 % 1) Check that 'out' and 'aeq' are now different. | |
510 % 2) Check that 'aeq' is not changed | |
511 % 3) Check that the modified input is joined | |
512 % 4) Check that out and amodi are the same | |
513 % | |
514 % </AlgoDescription> | |
515 | |
516 atest = true; | |
517 if stest | |
518 % <AlgoCode> | |
519 % Check that 'out' and 'aeq' are now different. | |
520 if eq(out, aeq, ple2), atest = false; end | |
521 % Check that 'aeq' is not changed | |
522 if ~eq(aeq, ao(a1), ple1), atest = false; end | |
523 % Check that the modified input is joined | |
524 aoin = [a1 a2]; | |
525 x0 = []; | |
526 y0 = []; | |
527 for oo = 1:numel(aoin) | |
528 if isempty(x0) | |
529 idxBefore = []; | |
530 idxAfter = 1:numel(aoin(oo).y); | |
531 else | |
532 idxBefore = find(aoin(oo).x < x0(1)); | |
533 idxAfter = find(aoin(oo).x > x0(end)); | |
534 end | |
535 x0 = [aoin(oo).x(idxBefore); x0; aoin(oo).x(idxAfter)]; | |
536 y0 = [aoin(oo).y(idxBefore); y0; aoin(oo).y(idxAfter)]; | |
537 end | |
538 if ~isequal(amodi.x, x0), atest = false; end | |
539 if ~isequal(amodi.y, y0), atest = false; end | |
540 % Check that out and amodi are the same | |
541 if ~eq(out, amodi, ple2), atest = false; end | |
542 % </AlgoCode> | |
543 else | |
544 atest = false; | |
545 end | |
546 | |
547 % Return a result structure | |
548 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
549 end % END UTP_07 | |
550 | |
551 %% UTP_08 | |
552 | |
553 % <TestDescription> | |
554 % | |
555 % Test the shape of the output. | |
556 % | |
557 % </TestDescription> | |
558 function result = utp_08 | |
559 | |
560 % <SyntaxDescription> | |
561 % | |
562 % Test that the join method keeps the data shape of the input object. | |
563 % The input AO must be an AO with row data and an AO with column data. | |
564 % | |
565 % </SyntaxDescription> | |
566 | |
567 try | |
568 % <SyntaxCode> | |
569 a1 = ao(1.1:30.1, randn(30,1)+2*10, plist('type', 'fsdata')); | |
570 a2 = ao(1.2:30.2, randn(1,30)+2*10, plist('type', 'fsdata')); | |
571 | |
572 out1 = join(a1, a2); | |
573 out2 = join(a2, a1); | |
574 % </SyntaxCode> | |
575 stest = true; | |
576 catch err | |
577 disp(err.message) | |
578 stest = false; | |
579 end | |
580 | |
581 % <AlgoDescription> | |
582 % | |
583 % 1) Check that the shape of the data doesn't change. | |
584 % | |
585 % </AlgoDescription> | |
586 | |
587 atest = true; | |
588 if stest | |
589 % <AlgoCode> | |
590 % Check the shape of the output data | |
591 if size(out1.data.y,1 ) == 1, atest = false; end | |
592 if size(out2.data.y,2 ) == 1, atest = false; end | |
593 % </AlgoCode> | |
594 else | |
595 atest = false; | |
596 end | |
597 | |
598 % Return a result structure | |
599 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
600 end % END UTP_08 | |
601 | |
602 end |