Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_join_tsdata.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_tsdata.m,v 1.12 2011/11/06 06:46:21 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 tsdata. The other data objects will | |
12 % be tested in an other UTP. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_ao_join_tsdata(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 with additional plist with the key 'axis' | |
42 results = [results utp_09]; % Test input data shape == output data shape | |
43 results = [results utp_10]; % Test the x-values | |
44 | |
45 a1 = ao(0:29, randn(30,1), 1); | |
46 a2 = ao(0:29, randn(30,1), 1); | |
47 a1.setT0('2009-02-12 14:00:00'); | |
48 a2.setT0('2009-02-12 14:00:35'); | |
49 | |
50 results = [results utp_11(mthd, [a1 a2], ple1)]; % Test plotinfo doesn't disappear | |
51 | |
52 disp('Done.'); | |
53 disp('******************************************************'); | |
54 | |
55 elseif nargin == 1 % Check for UTP functions | |
56 if strcmp(varargin{1}, 'isutp') | |
57 results = 1; | |
58 else | |
59 results = 0; | |
60 end | |
61 else | |
62 error('### Incorrect inputs') | |
63 end | |
64 | |
65 %% UTP_01 | |
66 | |
67 % <TestDescription> | |
68 % | |
69 % Tests that the getInfo call works for this method. | |
70 % | |
71 % </TestDescription> | |
72 function result = utp_01 | |
73 | |
74 | |
75 % <SyntaxDescription> | |
76 % | |
77 % Test that the getInfo call works for no sets, all sets, and each set | |
78 % individually. | |
79 % | |
80 % </SyntaxDescription> | |
81 | |
82 try | |
83 % <SyntaxCode> | |
84 % Call for no sets | |
85 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
86 % Call for all sets | |
87 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
88 % Call for each set | |
89 for kk=1:numel(io(2).sets) | |
90 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
91 end | |
92 % </SyntaxCode> | |
93 stest = true; | |
94 catch err | |
95 disp(err.message) | |
96 stest = false; | |
97 end | |
98 | |
99 % <AlgoDescription> | |
100 % | |
101 % 1) Check that getInfo call returned an minfo object in all cases. | |
102 % 2) Check that all plists have the correct parameters. | |
103 % | |
104 % </AlgoDescription> | |
105 | |
106 atest = true; | |
107 if stest | |
108 % <AlgoCode> | |
109 % check we have minfo objects | |
110 if isa(io, 'minfo') | |
111 %%% SET 'None' | |
112 if ~isempty(io(1).sets), atest = false; end | |
113 if ~isempty(io(1).plists), atest = false; end | |
114 %%% Check all Sets | |
115 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
116 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
117 %%%%%%%%%% SET 'Default' | |
118 if io(3).plists.nparams ~= 3, atest = false; end | |
119 % Check key | |
120 if ~io(3).plists.isparam('zerofill'), atest = false; end | |
121 if ~io(3).plists.isparam('sameT0'), atest = false; end | |
122 if ~io(3).plists.isparam('fstol'), atest = false; end | |
123 % Check default value | |
124 if ~isequal(io(3).plists.find('zerofill'), 'no'), atest = false; end | |
125 if ~isequal(io(3).plists.find('samet0'), 'no'), atest = false; end | |
126 if ~isequal(io(3).plists.find('fstol'), 1e-6), atest = false; end | |
127 % Check options | |
128 if ~isequal(io(3).plists.getOptionsForParam('zerofill'), {'yes', 'no'}), atest = false; end | |
129 if ~isequal(io(3).plists.getOptionsForParam('samet0'), {'yes', 'no'}), atest = false; end | |
130 if ~isequal(io(3).plists.getOptionsForParam('fstol'), {1e-6}), atest = false; end | |
131 end | |
132 % </AlgoCode> | |
133 else | |
134 atest = false; | |
135 end | |
136 | |
137 % Return a result structure | |
138 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
139 end % END UTP_01 | |
140 | |
141 %% UTP_02 | |
142 | |
143 % <TestDescription> | |
144 % | |
145 % Tests that the join method works with a vector of AOs as input. | |
146 % | |
147 % </TestDescription> | |
148 function result = utp_02 | |
149 | |
150 % <SyntaxDescription> | |
151 % | |
152 % Test that the join method works for a vector of AOs as input. | |
153 % | |
154 % </SyntaxDescription> | |
155 | |
156 try | |
157 % <SyntaxCode> | |
158 a1 = ao(0:29, randn(30,1), 1); | |
159 a2 = ao(0:29, randn(30,1), 1); | |
160 a3 = ao(0:29, randn(30,1), 1); | |
161 a1.setT0('2009-02-12 14:00:00'); | |
162 a2.setT0('2009-02-12 14:00:35'); | |
163 a3.setT0('2009-02-12 14:00:20'); | |
164 avec = [a1, a2, a3]; | |
165 out = join(avec); | |
166 mout = rebuild(out); | |
167 % </SyntaxCode> | |
168 stest = true; | |
169 catch err | |
170 disp(err.message) | |
171 stest = false; | |
172 end | |
173 | |
174 % <AlgoDescription> | |
175 % | |
176 % 1) Check that the output is exact one AO. | |
177 % 2) Check that the output have the correct data. | |
178 % 3) Check the re-built object | |
179 % | |
180 % </AlgoDescription> | |
181 | |
182 atest = true; | |
183 if stest | |
184 % <AlgoCode> | |
185 % Check we have the correct number of outputs | |
186 if numel(out) ~= 1, atest = false; end | |
187 % Compute reference data | |
188 % Toff is the smallest t0. Here t0 of a1 -> '2009-02-12 14:00:00' | |
189 Toff = time('2009-02-12 14:00:00').double; | |
190 | |
191 % Vector of input aos is sorted based on the t0 value | |
192 t0s = avec.t0.double; | |
193 [~, idx] = sort(t0s); | |
194 | |
195 t0 = avec(idx(1)).t0.double - Toff; | |
196 x0 = avec(idx(1)).x + t0; | |
197 y0 = avec(idx(1)).data.getY; | |
198 for kk = 2:numel(avec) | |
199 t0 = avec(idx(kk)).t0.double - Toff; | |
200 x = avec(idx(kk)).x + t0; | |
201 y = avec(idx(kk)).y; | |
202 idxPost = find(x > max(x0)); | |
203 idxPre = find(x < min(x0)); | |
204 x0 = [x(idxPre); x0; x(idxPost)]; | |
205 y0 = [y(idxPre); y0; y(idxPost)]; | |
206 end | |
207 if ~isequal(out.x, x0), atest = false; end | |
208 if ~isequal(out.y, y0), atest = false; end | |
209 if ~isequal(out.t0.double, Toff), atest = false; end | |
210 if ~eq(out, mout, ple2), atest = false; end | |
211 % </AlgoCode> | |
212 else | |
213 atest = false; | |
214 end | |
215 | |
216 % Return a result structure | |
217 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
218 end % END UTP_02 | |
219 | |
220 %% UTP_03 | |
221 | |
222 % <TestDescription> | |
223 % | |
224 % Tests that the join method works with a matrix of AOs as input. | |
225 % | |
226 % </TestDescription> | |
227 function result = utp_03 | |
228 | |
229 % <SyntaxDescription> | |
230 % | |
231 % Test that the join method works for a matrix of AOs as input. | |
232 % | |
233 % </SyntaxDescription> | |
234 | |
235 try | |
236 % <SyntaxCode> | |
237 a1 = ao(0:29, randn(30,1), 1); | |
238 a2 = ao(0:29, randn(30,1), 1); | |
239 a3 = ao(0:29, randn(30,1), 1); | |
240 a4 = ao(0:29, randn(30,1), 1); | |
241 a5 = ao(0:29, randn(30,1), 1); | |
242 a6 = ao(0:29, randn(30,1), 1); | |
243 a1.setT0('2009-02-12 14:01:00'); | |
244 a2.setT0('2009-02-12 14:00:20'); | |
245 a3.setT0('2009-02-12 14:00:00'); | |
246 a4.setT0('2009-02-12 14:00:50'); | |
247 a5.setT0('2009-02-12 14:01:50'); | |
248 a6.setT0('2009-02-12 14:02:00'); | |
249 amat = [a1, a2, a3]; | |
250 out = join(amat); | |
251 mout = rebuild(out); | |
252 % </SyntaxCode> | |
253 stest = true; | |
254 catch err | |
255 disp(err.message) | |
256 stest = false; | |
257 end | |
258 | |
259 % <AlgoDescription> | |
260 % | |
261 % 1) Check that the output is exact one AO. | |
262 % 2) Check that the output have the correct data. | |
263 % 3) Check the re-built object | |
264 % | |
265 % </AlgoDescription> | |
266 | |
267 atest = true; | |
268 if stest | |
269 % <AlgoCode> | |
270 % Check we have the correct number of outputs | |
271 if numel(out) ~= 1, atest = false; end | |
272 % Compute reference data | |
273 % Toff is the smallest t0. Here t0 of a1 -> '2009-02-12 14:00:00' | |
274 Toff = time('2009-02-12 14:00:00').double; | |
275 | |
276 % Matrix of input aos is sorted based on the t0 value | |
277 t0s = amat.t0.double; | |
278 [~, idx] = sort(t0s); | |
279 | |
280 t0 = amat(idx(1)).t0.double - Toff; | |
281 x0 = amat(idx(1)).x + t0; | |
282 y0 = amat(idx(1)).data.getY; | |
283 for kk = 2:numel(amat) | |
284 t0 = amat(idx(kk)).t0.double - Toff; | |
285 x = amat(idx(kk)).x + t0; | |
286 y = amat(idx(kk)).y; | |
287 idxPost = find(x > max(x0)); | |
288 idxPre = find(x < min(x0)); | |
289 x0 = [x(idxPre); x0; x(idxPost)]; | |
290 y0 = [y(idxPre); y0; y(idxPost)]; | |
291 end | |
292 if ~isequal(out.x, x0), atest = false; end | |
293 if ~isequal(out.y, y0), atest = false; end | |
294 if ~isequal(out.t0.double, Toff), atest = false; end | |
295 if ~eq(out, mout, ple2), atest = false; end | |
296 % </AlgoCode> | |
297 else | |
298 atest = false; | |
299 end | |
300 | |
301 % Return a result structure | |
302 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
303 end % END UTP_03 | |
304 | |
305 %% UTP_04 | |
306 | |
307 % <TestDescription> | |
308 % | |
309 % Tests that the join method works with a list of AOs as input. | |
310 % | |
311 % </TestDescription> | |
312 function result = utp_04 | |
313 | |
314 % <SyntaxDescription> | |
315 % | |
316 % Tests that the join method works with a list of AOs as input. | |
317 % | |
318 % </SyntaxDescription> | |
319 | |
320 try | |
321 % <SyntaxCode> | |
322 a1 = ao(0:29, randn(30,1), 1); | |
323 a2 = ao(0:29, randn(30,1), 1); | |
324 a3 = ao(0:29, randn(30,1), 1); | |
325 a1.setT0('2009-02-12 14:01:00'); | |
326 a2.setT0('2009-02-12 14:00:30'); | |
327 a3.setT0('2009-02-12 14:00:00'); | |
328 out = join(a1, a2, a3); | |
329 mout = rebuild(out); | |
330 % </SyntaxCode> | |
331 stest = true; | |
332 catch err | |
333 disp(err.message) | |
334 stest = false; | |
335 end | |
336 | |
337 % <AlgoDescription> | |
338 % | |
339 % 1) Check that the output is exact one AO. | |
340 % 2) Check that the output have the correct data. | |
341 % 3) Check the re-built object | |
342 % | |
343 % </AlgoDescription> | |
344 | |
345 atest = true; | |
346 aoin = [a1 a2 a3]; | |
347 if stest | |
348 % <AlgoCode> | |
349 % Check we have the correct number of outputs | |
350 if numel(out) ~= 1, atest = false; end | |
351 % Compute reference data | |
352 % Toff is the smallest t0. Here t0 of a1 -> '2009-02-12 14:00:00' | |
353 Toff = time('2009-02-12 14:00:00').double; | |
354 | |
355 % List of input aos is sorted based on the t0 value | |
356 t0s = aoin.t0.double; | |
357 [~, idx] = sort(t0s); | |
358 | |
359 t0 = aoin(idx(1)).t0.double - Toff; | |
360 x0 = aoin(idx(1)).x + t0; | |
361 y0 = aoin(idx(1)).data.getY; | |
362 for kk = 2:numel(aoin) | |
363 t0 = aoin(idx(kk)).t0.double - Toff; | |
364 x = aoin(idx(kk)).x + t0; | |
365 y = aoin(idx(kk)).y; | |
366 idxPost = find(x > max(x0)); | |
367 idxPre = find(x < min(x0)); | |
368 x0 = [x(idxPre); x0; x(idxPost)]; | |
369 y0 = [y(idxPre); y0; y(idxPost)]; | |
370 end | |
371 if ~isequal(out.x, x0), atest = false; end | |
372 if ~isequal(out.y, y0), atest = false; end | |
373 if ~isequal(out.t0.double, Toff), atest = false; end | |
374 if ~eq(out, mout, ple2), atest = false; end | |
375 % </AlgoCode> | |
376 else | |
377 atest = false; | |
378 end | |
379 | |
380 % Return a result structure | |
381 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
382 end % END UTP_04 | |
383 | |
384 %% UTP_05 | |
385 | |
386 % <TestDescription> | |
387 % | |
388 % Tests that the join method works with a mix of different shaped AOs as | |
389 % input. | |
390 % | |
391 % </TestDescription> | |
392 function result = utp_05 | |
393 | |
394 % <SyntaxDescription> | |
395 % | |
396 % Tests that the join method works with a mix of different shaped AOs | |
397 % as input. | |
398 % | |
399 % </SyntaxDescription> | |
400 | |
401 try | |
402 % <SyntaxCode> | |
403 a1 = ao(0:29, randn(30,1), 1); | |
404 a2 = ao(0:29, randn(30,1), 1); | |
405 a3 = ao(0:29, randn(30,1), 1); | |
406 a4 = ao(0:29, randn(30,1), 1); | |
407 a1.setT0('2009-02-12 14:01:00'); | |
408 a2.setT0('2009-02-12 14:00:20'); | |
409 a3.setT0('2009-02-12 14:00:00'); | |
410 a4.setT0('2009-02-12 14:00:50'); | |
411 out = join(a1, [a2 a3], a4); | |
412 mout = rebuild(out); | |
413 % </SyntaxCode> | |
414 stest = true; | |
415 catch err | |
416 disp(err.message) | |
417 stest = false; | |
418 end | |
419 | |
420 % <AlgoDescription> | |
421 % | |
422 % 1) Check that the output is exact one AO. | |
423 % 2) Check that the output have the correct data. | |
424 % 3) Check the re-built object | |
425 % | |
426 % </AlgoDescription> | |
427 | |
428 atest = true; | |
429 aoin = [a1, a2, a3, a4]; | |
430 if stest | |
431 % <AlgoCode> | |
432 % Check we have the correct number of outputs | |
433 if numel(out) ~= 1, atest = false; end | |
434 % Compute reference data | |
435 % Toff is the smallest t0. Here t0 of a1 -> '2009-02-12 14:00:00' | |
436 Toff = time('2009-02-12 14:00:00').double; | |
437 | |
438 % Matrix of input aos is sorted based on the t0 value | |
439 t0s = aoin.t0.double; | |
440 [~, idx] = sort(t0s); | |
441 | |
442 t0 = aoin(idx(1)).t0.double - Toff; | |
443 x0 = aoin(idx(1)).x + t0; | |
444 y0 = aoin(idx(1)).data.getY; | |
445 for kk = 2:numel(aoin) | |
446 t0 = aoin(idx(kk)).t0.double - Toff; | |
447 x = aoin(idx(kk)).x + t0; | |
448 y = aoin(idx(kk)).y; | |
449 idxPost = find(x > max(x0)); | |
450 idxPre = find(x < min(x0)); | |
451 x0 = [x(idxPre); x0; x(idxPost)]; | |
452 y0 = [y(idxPre); y0; y(idxPost)]; | |
453 end | |
454 if ~isequal(out.x, x0), atest = false; end | |
455 if ~isequal(out.y, y0), atest = false; end | |
456 if ~isequal(out.t0.double, Toff), atest = false; end | |
457 if ~eq(out, mout, ple2), atest = false; end | |
458 % </AlgoCode> | |
459 else | |
460 atest = false; | |
461 end | |
462 | |
463 % Return a result structure | |
464 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
465 end % END UTP_05 | |
466 | |
467 %% UTP_06 | |
468 | |
469 % <TestDescription> | |
470 % | |
471 % Tests that the join method properly applies history. | |
472 % | |
473 % </TestDescription> | |
474 function result = utp_06 | |
475 | |
476 % <SyntaxDescription> | |
477 % | |
478 % Test that the result of applying the join method can be processed back. | |
479 % | |
480 % </SyntaxDescription> | |
481 | |
482 try | |
483 % <SyntaxCode> | |
484 a1 = ao(0:29, randn(30,1), 1); | |
485 a2 = ao(0:29, randn(30,1), 1); | |
486 a1.setT0('2009-02-12 14:00:00'); | |
487 a2.setT0('2009-02-12 14:00:35'); | |
488 | |
489 out = join(a1, a2); | |
490 mout = rebuild(out); | |
491 % </SyntaxCode> | |
492 stest = true; | |
493 catch err | |
494 disp(err.message) | |
495 stest = false; | |
496 end | |
497 | |
498 % <AlgoDescription> | |
499 % | |
500 % 1) Check that the last entry in the history of 'out' corresponds to | |
501 % 'join'. | |
502 % 2) Check that the re-built object is the same object as the input. | |
503 % | |
504 % </AlgoDescription> | |
505 | |
506 atest = true; | |
507 if stest | |
508 % <AlgoCode> | |
509 % Check the last step in the history of 'out' | |
510 if ~strcmp(out.hist.methodInfo.mname, 'join'), atest = false; end | |
511 % The rebuilt object must be the same as 'out' | |
512 if ~eq(mout, out, ple2), atest = false; end | |
513 % </AlgoCode> | |
514 else | |
515 atest = false; | |
516 end | |
517 | |
518 % Return a result structure | |
519 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
520 end % END UTP_06 | |
521 | |
522 %% UTP_07 | |
523 | |
524 % <TestDescription> | |
525 % | |
526 % Tests that the join method can modify the input AO. | |
527 % | |
528 % </TestDescription> | |
529 function result = utp_07 | |
530 | |
531 % <SyntaxDescription> | |
532 % | |
533 % Test that the join method can modify the input AO by calling with no | |
534 % output and that the method doesn't change the input of the function | |
535 % notation (with a equal sign). | |
536 % | |
537 % </SyntaxDescription> | |
538 | |
539 try | |
540 % <SyntaxCode> | |
541 % copy at1 to work with | |
542 a1 = ao(0:29, randn(30,1), 1); | |
543 a2 = ao(0:29, randn(30,1), 1); | |
544 a1.setT0('2009-02-12 14:00:00'); | |
545 a2.setT0('2009-02-12 14:00:25'); | |
546 | |
547 amodi = ao(a1); | |
548 aeq = ao(a1); | |
549 out = aeq.join(a2); | |
550 amodi.join(a2); | |
551 % </SyntaxCode> | |
552 stest = true; | |
553 catch err | |
554 disp(err.message) | |
555 stest = false; | |
556 end | |
557 | |
558 % <AlgoDescription> | |
559 % | |
560 % 1) Check that 'out' and 'aeq' are now different. | |
561 % 2) Check that 'aeq' is not changed | |
562 % 3) Check that the modified input is joined | |
563 % 4) Check that out and amodi are the same | |
564 % | |
565 % </AlgoDescription> | |
566 | |
567 atest = true; | |
568 if stest | |
569 % <AlgoCode> | |
570 % Check that 'out' and 'aeq' are now different. | |
571 if eq(out, aeq, ple2), atest = false; end | |
572 % Check that 'aeq' is not changed | |
573 if ~eq(aeq, ao(a1), ple1), atest = false; end | |
574 % Check that the modified input is joined | |
575 Toff = time('2009-02-12 14:00:00').double; | |
576 | |
577 t0 = amodi.t0.double - Toff; | |
578 x0 = amodi.x + t0; | |
579 y0 = amodi.data.getY; | |
580 t0 = a2.t0.double - Toff; | |
581 x = a2.x + t0; | |
582 y = a2.y; | |
583 idxPost = find(x > max(x0)); | |
584 idxPre = find(x < min(x0)); | |
585 x0 = [x(idxPre); x0; x(idxPost)]; | |
586 y0 = [y(idxPre); y0; y(idxPost)]; | |
587 if ~isequal(amodi.x, x0), atest = false; end | |
588 if ~isequal(amodi.y, y0), atest = false; end | |
589 if ~isequal(amodi.t0.double, Toff), atest = false; end | |
590 % Check that out and amodi are the same | |
591 if ~eq(out, amodi, ple2), atest = false; end | |
592 % </AlgoCode> | |
593 else | |
594 atest = false; | |
595 end | |
596 | |
597 % Return a result structure | |
598 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
599 end % END UTP_07 | |
600 | |
601 %% UTP_08 | |
602 | |
603 % <TestDescription> | |
604 % | |
605 % Test that the join method fills the gaps with zeros. | |
606 % | |
607 % </TestDescription> | |
608 function result = utp_08 | |
609 | |
610 % <SyntaxDescription> | |
611 % | |
612 % Test that the join method fills the gaps with zeros. | |
613 % | |
614 % </SyntaxDescription> | |
615 | |
616 try | |
617 % <SyntaxCode> | |
618 n = 29; | |
619 fs = 3; | |
620 x = 0:(1/fs):(n/fs)-1/fs; | |
621 a1 = ao(x, randn(n,1), fs); | |
622 a2 = ao(x, randn(n,1), fs); | |
623 a3 = ao(x, randn(n,1), fs); | |
624 a1.setT0('2009-02-12 14:00:00'); | |
625 a2.setT0('2009-02-12 14:00:35'); | |
626 a3.setT0('2009-02-12 14:01:15'); | |
627 pl = plist('zerofill', true); | |
628 | |
629 out1 = join(a1, a2, pl); | |
630 out2 = join(a1, a2, a3, pl); | |
631 mout1 = rebuild(out1); | |
632 mout2 = rebuild(out2); | |
633 % </SyntaxCode> | |
634 stest = true; | |
635 catch err | |
636 disp(err.message) | |
637 stest = false; | |
638 end | |
639 | |
640 % <AlgoDescription> | |
641 % | |
642 % 1) Check that the join method filled the gaps with zero | |
643 % 2) Check that the re-built objects are the same as out[1..2] | |
644 % | |
645 % </AlgoDescription> | |
646 | |
647 atest = true; | |
648 TOL = 1e-13; | |
649 if stest | |
650 % <AlgoCode> | |
651 % Check 'out1' | |
652 Toff = time('2009-02-12 14:00:00').double; | |
653 t0 = a1.t0.double - Toff; | |
654 x0 = a1.x + t0; | |
655 y0 = a1.data.getY; | |
656 t0 = a2.t0.double - Toff; | |
657 x = a2.x + t0; | |
658 y = a2.y; | |
659 idxPost = find(x > max(x0)); | |
660 idxPre = find(x < min(x0)); | |
661 x0 = [x(idxPre); x0; x(idxPost)]; | |
662 y0 = [y(idxPre); y0; y(idxPost)]; | |
663 % Look for gaps | |
664 d = diff(x0); | |
665 gap = find(d >= 2*1/a1.fs); | |
666 xgap = linspace(x0(gap)+1/a1.fs, x0(gap+1)-1/a1.fs, (x0(gap+1)-x0(gap))*a1.fs-2*1/a1.fs).'; | |
667 ygap = zeros(length(xgap),1); | |
668 x0 = [x0(1:gap); xgap; x0(gap+1:end)]; | |
669 y0 = [y0(1:gap); ygap; y0(gap+1:end)]; | |
670 if any(abs(out1.x - x0) > TOL ), atest = false; end | |
671 if ~isequal(out1.y, y0), atest = false; end | |
672 | |
673 % Check 'out2' | |
674 Toff = time('2009-02-12 14:00:00').double; | |
675 t0 = a1.t0.double - Toff; | |
676 x0 = a1.x + t0; | |
677 y0 = a1.data.getY; | |
678 % Join a2 | |
679 t0 = a2.t0.double - Toff; | |
680 x = a2.x + t0; | |
681 y = a2.y; | |
682 idxPost = find(x > max(x0)); | |
683 idxPre = find(x < min(x0)); | |
684 x0 = [x(idxPre); x0; x(idxPost)]; | |
685 y0 = [y(idxPre); y0; y(idxPost)]; | |
686 % Look for gaps | |
687 d = diff(x0); | |
688 gap = find(d >= 2*1/a1.fs); | |
689 xgap = linspace(x0(gap)+1/a1.fs, x0(gap+1)-1/a1.fs, (x0(gap+1)-x0(gap))*a1.fs-2*1/a1.fs).'; | |
690 ygap = zeros(length(xgap),1); | |
691 x0 = [x0(1:gap); xgap; x0(gap+1:end)]; | |
692 y0 = [y0(1:gap); ygap; y0(gap+1:end)]; | |
693 % Join a3 | |
694 t0 = a3.t0.double - Toff; | |
695 x = a3.x + t0; | |
696 y = a3.y; | |
697 idxPost = find(x > max(x0)); | |
698 idxPre = find(x < min(x0)); | |
699 x0 = [x(idxPre); x0; x(idxPost)]; | |
700 y0 = [y(idxPre); y0; y(idxPost)]; | |
701 % Look for gaps | |
702 d = diff(x0); | |
703 gap = find(d >= 2*1/a1.fs); | |
704 xgap = linspace(x0(gap)+1/a1.fs, x0(gap+1)-1/a1.fs, (x0(gap+1)-x0(gap))*a1.fs-2*1/a1.fs).'; | |
705 ygap = zeros(length(xgap),1); | |
706 x0 = [x0(1:gap); xgap; x0(gap+1:end)]; | |
707 y0 = [y0(1:gap); ygap; y0(gap+1:end)]; | |
708 if any(abs(out2.x - x0) > TOL ), atest = false; end | |
709 if ~isequal(out2.y, y0), atest = false; end | |
710 | |
711 % Check out[1..2] | |
712 if ~eq(mout1, out1, ple2), atest = false; end | |
713 if ~eq(mout2, out2, ple2), atest = false; end | |
714 % </AlgoCode> | |
715 else | |
716 atest = false; | |
717 end | |
718 | |
719 % Return a result structure | |
720 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
721 end % END UTP_08 | |
722 | |
723 %% UTP_09 | |
724 | |
725 % <TestDescription> | |
726 % | |
727 % Test the shape of the output. | |
728 % | |
729 % </TestDescription> | |
730 function result = utp_09 | |
731 | |
732 % <SyntaxDescription> | |
733 % | |
734 % Test that the join method keeps the data shape of the input object. | |
735 % The input AO must be an AO with row data and an AO with column data. | |
736 % | |
737 % </SyntaxDescription> | |
738 | |
739 try | |
740 % <SyntaxCode> | |
741 a1 = ao([0:29 30:49], randn(50,1), 1); | |
742 a2 = ao([20:49 50:69], randn(1,50), 1); | |
743 a1.setT0('2009-02-12 14:00:00'); | |
744 a2.setT0('2009-02-12 14:00:00'); | |
745 | |
746 out1 = join(a1, a2); | |
747 out2 = join(a2, a1); | |
748 % </SyntaxCode> | |
749 stest = true; | |
750 catch err | |
751 disp(err.message) | |
752 stest = false; | |
753 end | |
754 | |
755 % <AlgoDescription> | |
756 % | |
757 % 1) Check that the shape of the data doesn't change. | |
758 % | |
759 % </AlgoDescription> | |
760 | |
761 atest = true; | |
762 if stest | |
763 % <AlgoCode> | |
764 % Check the shape of the output data | |
765 if size(out1.data.y, 1) == 1, atest = false; end | |
766 if size(out2.data.y, 2) == 1, atest = false; end | |
767 % </AlgoCode> | |
768 else | |
769 atest = false; | |
770 end | |
771 | |
772 % Return a result structure | |
773 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
774 end % END UTP_09 | |
775 | |
776 %% UTP_10 | |
777 | |
778 % <TestDescription> | |
779 % | |
780 % Test the x-values. | |
781 % | |
782 % </TestDescription> | |
783 function result = utp_10 | |
784 | |
785 % <SyntaxDescription> | |
786 % | |
787 % Test the x-values. | |
788 % | |
789 % </SyntaxDescription> | |
790 | |
791 try | |
792 % <SyntaxCode> | |
793 a1 = ao(1:20, randn(20,1), plist('type', 'tsdata')); | |
794 a2 = ao(11:30, randn(20,1), plist('type', 'tsdata')); | |
795 a3 = ao(41:50, randn(10,1), plist('type', 'tsdata')); | |
796 | |
797 out1 = join(a1, a2, a3, plist('zerofill', 'no')); | |
798 out2 = join(a1, a2, a3, plist('zerofill', 'yes')); | |
799 out3 = join(a2, a1, a3, plist('zerofill', 'no')); | |
800 out4 = join(a2, a1, a3, plist('zerofill', 'yes')); | |
801 % </SyntaxCode> | |
802 stest = true; | |
803 catch err | |
804 disp(err.message) | |
805 stest = false; | |
806 end | |
807 | |
808 % <AlgoDescription> | |
809 % | |
810 % 1) Check the x-values for the case where we 'zerofill' or not. | |
811 % 2) Compare the outputs to see that switching the order did not matter, | |
812 % because if the different t0 of the data, that get sorted anyways. | |
813 % | |
814 % </AlgoDescription> | |
815 | |
816 atest = true; | |
817 if stest | |
818 % <AlgoCode> | |
819 % Check the x-getter of the AO | |
820 if ~isequal(out1.x, [1:30, 41:50]'), atest = false; end | |
821 if ~isequal(out2.x, [1:50]'), atest = false; end | |
822 if ~isequal(out3.x, [1:30, 41:50]'), atest = false; end | |
823 if ~isequal(out4.x, [1:50]'), atest = false; end | |
824 % Check the real stored x values | |
825 if ~isequal(out1.data.x, [0:29, 40:49]') || ~isequal(out1.data.toffset, 1000), atest = false; end | |
826 if ~isempty(out2.data.x), atest = false; end | |
827 if ~isequal(out3.data.x, [0:29, 40:49]') || ~isequal(out3.data.toffset, 1000), atest = false; end | |
828 if ~isempty(out4.data.x), atest = false; end | |
829 % </AlgoCode> | |
830 else | |
831 atest = false; | |
832 end | |
833 | |
834 % Return a result structure | |
835 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
836 end % END UTP_10 | |
837 | |
838 end |