Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_split_interval.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_SPLIT a set of UTPs for the ao/split method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_split_interval.m,v 1.9 2011/09/29 12:09:56 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The split method of the ao class splits an analysis object into the | |
11 % specified segments. This UTP splits the AOs into sample segments. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_split_interval(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'split'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Exception list for the UTPs: | |
30 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
31 | |
32 % Run the tests | |
33 results = [results utp_01]; % getInfo call | |
34 results = [results utp_02]; % Vector input | |
35 results = [results utp_03]; % Matrix input | |
36 results = [results utp_04]; % List input | |
37 results = [results utp_05]; % Test with mixed input | |
38 results = [results utp_06]; % Test history is working | |
39 results = [results utp_07]; % Test the modify call works | |
40 results = [results utp_08]; % Test input data shape == output data shape | |
41 results = [results utp_09]; % Test output of the data | |
42 results = [results utp_10]; % Test with AO which can collapse the x-axis | |
43 | |
44 n = 300; | |
45 fs = 3; | |
46 x = 0:(1/fs):(n/fs)-1/fs; | |
47 a1 = ao(x, randn(n,1), fs); | |
48 a1.setT0(a1.t0 + time('14:00:00')); | |
49 st = '14:00:25'; | |
50 et = '14:01:15'; | |
51 pli = plist('start_time', st, 'end_time', et); | |
52 results = [results utp_11(mthd, a1, ple1, pli)]; % Test plotinfo doesn't disappear | |
53 | |
54 results = [results utp_12]; % Test key-words: start_time + duration | |
55 results = [results utp_13]; % Test key-words: timespan | |
56 results = [results utp_14]; % Test key-words: start_time + end_time | |
57 results = [results utp_15]; % Test not equal sampled data (tsdata) and 'timeshift' option | |
58 results = [results utp_16]; % Test not equal sampled data (tsdata) and 'timeshift' option | |
59 results = [results utp_17]; % Test not equal sampled data (tsdata) and 'timeshift' option | |
60 | |
61 disp('Done.'); | |
62 disp('******************************************************'); | |
63 | |
64 elseif nargin == 1 % Check for UTP functions | |
65 if strcmp(varargin{1}, 'isutp') | |
66 results = 1; | |
67 else | |
68 results = 0; | |
69 end | |
70 else | |
71 error('### Incorrect inputs') | |
72 end | |
73 | |
74 %% UTP_01 | |
75 | |
76 % <TestDescription> | |
77 % | |
78 % Tests that the getInfo call works for this method. | |
79 % | |
80 % </TestDescription> | |
81 function result = utp_01 | |
82 | |
83 | |
84 % <SyntaxDescription> | |
85 % | |
86 % Test that the getInfo call works for no sets, all sets, and each set | |
87 % individually. | |
88 % | |
89 % </SyntaxDescription> | |
90 | |
91 try | |
92 % <SyntaxCode> | |
93 % Call for no sets | |
94 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
95 % Call for all sets | |
96 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
97 % Call for each set | |
98 for kk=1:numel(io(2).sets) | |
99 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
100 end | |
101 % </SyntaxCode> | |
102 stest = true; | |
103 catch err | |
104 disp(err.message) | |
105 stest = false; | |
106 end | |
107 | |
108 % <AlgoDescription> | |
109 % | |
110 % 1) Check that getInfo call returned an minfo object in all cases. | |
111 % 2) Check that all plists have the correct parameters. | |
112 % | |
113 % </AlgoDescription> | |
114 | |
115 atest = true; | |
116 if stest | |
117 % <AlgoCode> | |
118 % check we have minfo objects | |
119 if isa(io, 'minfo') | |
120 %%% SET 'None' | |
121 idx = 1; | |
122 if ~isempty(io(idx).sets), atest = false; end | |
123 if ~isempty(io(idx).plists), atest = false; end | |
124 %%% Check all Sets | |
125 idx = 2; | |
126 if ~any(strcmpi(io(idx).sets, 'Default')), atest = false; end | |
127 if ~any(strcmpi(io(idx).sets, 'By times')), atest = false; end | |
128 if ~any(strcmpi(io(idx).sets, 'By frequencies')), atest = false; end | |
129 if ~any(strcmpi(io(idx).sets, 'By samples')), atest = false; end | |
130 if ~any(strcmpi(io(idx).sets, 'By chunks')), atest = false; end | |
131 if ~any(strcmpi(io(idx).sets, 'By interval start/end')), atest = false; end | |
132 if ~any(strcmpi(io(idx).sets, 'By interval start/duration')), atest = false; end | |
133 if ~any(strcmpi(io(idx).sets, 'By interval timespan')), atest = false; end | |
134 if numel(io(idx).plists) ~= numel(io(idx).sets), atest = false; end | |
135 %%%%%%%%%% SET 'Default' | |
136 idx = 3; | |
137 if io(idx).plists.nparams ~= 1, atest = false; end | |
138 % Check key | |
139 if ~io(idx).plists.isparam('times'), atest = false; end | |
140 % Check default value | |
141 if ~isEmptyDouble(io(idx).plists.find('times')), atest = false; end | |
142 % Check options | |
143 if ~isequal(io(idx).plists.getOptionsForParam('times'), {[]}), atest = false; end | |
144 %%%%%%%%%% SET 'By times' | |
145 idx = 4; | |
146 if io(idx).plists.nparams ~= 1, atest = false; end | |
147 % Check key | |
148 if ~io(idx).plists.isparam('times'), atest = false; end | |
149 % Check default value | |
150 if ~isEmptyDouble(io(idx).plists.find('times')), atest = false; end | |
151 % Check options | |
152 if ~isequal(io(idx).plists.getOptionsForParam('times'), {[]}), atest = false; end | |
153 %%%%%%%%%% SET 'By frequencies' | |
154 idx = 5; | |
155 if io(idx).plists.nparams ~= 1, atest = false; end | |
156 % Check key | |
157 if ~io(idx).plists.isparam('frequencies'), atest = false; end | |
158 % Check default value | |
159 if ~isEmptyDouble(io(idx).plists.find('frequencies')), atest = false; end | |
160 % Check options | |
161 if ~isequal(io(idx).plists.getOptionsForParam('frequencies'), {[]}), atest = false; end | |
162 %%%%%%%%%% SET 'By samples' | |
163 idx = 6; | |
164 if io(idx).plists.nparams ~= 1, atest = false; end | |
165 % Check key | |
166 if ~io(idx).plists.isparam('samples'), atest = false; end | |
167 % Check default value | |
168 if ~isEmptyDouble(io(idx).plists.find('samples')), atest = false; end | |
169 % Check options | |
170 if ~isequal(io(idx).plists.getOptionsForParam('samples'), {[]}), atest = false; end | |
171 %%%%%%%%%% SET 'By chunks' | |
172 idx = 7; | |
173 if io(idx).plists.nparams ~= 2, atest = false; end | |
174 % Check key | |
175 if ~io(idx).plists.isparam('N'), atest = false; end | |
176 if ~io(idx).plists.isparam('match'), atest = false; end | |
177 % Check default value | |
178 if ~isEmptyDouble(io(idx).plists.find('N')), atest = false; end | |
179 if ~isequal(io(idx).plists.find('match'), true), atest = false; end | |
180 % Check options | |
181 if ~isequal(io(idx).plists.getOptionsForParam('N'), {[]}), atest = false; end | |
182 if ~isequal(io(idx).plists.getOptionsForParam('match'), {true, false}), atest = false; end | |
183 %%%%%%%%%% SET 'By interval start/end' | |
184 idx = 8; | |
185 if io(idx).plists.nparams ~= 2, atest = false; end | |
186 % Check key | |
187 if ~io(idx).plists.isparam('start_time'), atest = false; end | |
188 if ~io(idx).plists.isparam('end_time'), atest = false; end | |
189 % Check default value | |
190 if ~eq(io(idx).plists.find('start_time'), time(0), ple1), atest = false; end | |
191 if ~eq(io(idx).plists.find('end_time'), time(0), ple1), atest = false; end | |
192 % Check options | |
193 %%%%%%%%%% SET 'By interval start/duration' | |
194 idx = 9; | |
195 if io(idx).plists.nparams ~= 2, atest = false; end | |
196 % Check key | |
197 if ~io(idx).plists.isparam('start_time'), atest = false; end | |
198 if ~io(idx).plists.isparam('duration'), atest = false; end | |
199 % Check default value | |
200 if ~eq(io(idx).plists.find('start_time'), time(0), ple1), atest = false; end | |
201 if ~eq(io(idx).plists.find('duration'), time(0), ple1), atest = false; end | |
202 % Check options | |
203 %%%%%%%%%% SET 'By interval timespan' | |
204 idx = 10; | |
205 if io(idx).plists.nparams ~= 1, atest = false; end | |
206 % Check key | |
207 if ~io(idx).plists.isparam('timespan'), atest = false; end | |
208 % Check default value | |
209 ts = timespan(0,0); | |
210 if ~eq(io(idx).plists.find('timespan'), ts, ple1), atest = false; end | |
211 % Check options | |
212 end | |
213 % </AlgoCode> | |
214 else | |
215 atest = false; | |
216 end | |
217 | |
218 % Return a result structure | |
219 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
220 end % END UTP_01 | |
221 | |
222 %% UTP_02 | |
223 | |
224 % <TestDescription> | |
225 % | |
226 % Tests that the split method works with a vector of AOs as input. | |
227 % | |
228 % </TestDescription> | |
229 function result = utp_02 | |
230 | |
231 % <SyntaxDescription> | |
232 % | |
233 % Test that the split method works for a vector of AOs as input. | |
234 % | |
235 % </SyntaxDescription> | |
236 | |
237 try | |
238 % <SyntaxCode> | |
239 n1 = 300; | |
240 fs1 = 3; | |
241 x1 = 0:(1/fs1):(n1/fs1)-1/fs1; | |
242 a1 = ao(x1, randn(n1,1), fs1); | |
243 n2 = 100; | |
244 fs2 = 1; | |
245 x2 = 0:(1/fs2):(n2/fs2)-1/fs2; | |
246 a2 = ao(x2, randn(n2,1), fs2); | |
247 n3 = 100; | |
248 fs3 = .3; | |
249 x3 = 0:(1/fs3):(n3/fs3)-1/fs3; | |
250 a3 = ao(x3, randn(n3,1), fs3); | |
251 a1.setT0(a1.t0 + time('14:00:00')); | |
252 a2.setT0(a2.t0 + time('14:00:00')); | |
253 a3.setT0(a3.t0 + time('14:00:00')); | |
254 avec = [a1, a2, a3]; | |
255 st = '14:00:25'; | |
256 et = '14:01:15'; | |
257 pl = plist('start_time', st, 'end_time', et); | |
258 out = split(avec, pl); | |
259 % </SyntaxCode> | |
260 stest = true; | |
261 catch err | |
262 disp(err.message) | |
263 stest = false; | |
264 end | |
265 | |
266 % <AlgoDescription> | |
267 % | |
268 % 1) Check that the number of elements in 'out' is the same as in | |
269 % 'avec' times numbers of intervals | |
270 % 2) Check that each output AO contains the correct data. | |
271 % | |
272 % </AlgoDescription> | |
273 | |
274 atest = true; | |
275 if stest | |
276 % <AlgoCode> | |
277 % Check we have the correct number of outputs | |
278 if numel(out) ~= numel(avec), atest = false; end | |
279 % Check each output | |
280 for kk=1:2:numel(out) | |
281 %%%% Check Interval '14:00:25' .. '14:01:15' | |
282 x = avec(kk).x + avec(kk).t0.double; | |
283 y = avec(kk).y; | |
284 % Comput start/end time | |
285 ts = time(st).double; | |
286 te = time(et).double; | |
287 idx = find(x >= ts & x < te); | |
288 % Normalize out data | |
289 ox = out(kk).x + out(kk).t0.double; | |
290 oy = out(kk).y; | |
291 % Check data | |
292 if ~isequal(ox, x(idx)), atest = false; end | |
293 if ~isequal(oy, y(idx)), atest = false; end | |
294 end | |
295 % </AlgoCode> | |
296 else | |
297 atest = false; | |
298 end | |
299 | |
300 % Return a result structure | |
301 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
302 end % END UTP_02 | |
303 | |
304 %% UTP_03 | |
305 | |
306 % <TestDescription> | |
307 % | |
308 % Tests that the split method works with a matrix of AOs as input. | |
309 % | |
310 % </TestDescription> | |
311 function result = utp_03 | |
312 | |
313 % <SyntaxDescription> | |
314 % | |
315 % Tests that the split method works with a matrix of AOs as input. | |
316 % | |
317 % </SyntaxDescription> | |
318 | |
319 try | |
320 % <SyntaxCode> | |
321 n1 = 300; | |
322 fs1 = 3; | |
323 x1 = 0:(1/fs1):(n1/fs1)-1/fs1; | |
324 a1 = ao(x1, randn(n1,1), fs1); | |
325 n2 = 100; | |
326 fs2 = 1; | |
327 x2 = 0:(1/fs2):(n2/fs2)-1/fs2; | |
328 a2 = ao(x2, randn(n2,1), fs2); | |
329 n3 = 100; | |
330 fs3 = .3; | |
331 x3 = 0:(1/fs3):(n3/fs3)-1/fs3; | |
332 a3 = ao(x3, randn(n3,1), fs3); | |
333 a1.setT0(a1.t0 + time('14:00:00')); | |
334 a2.setT0(a2.t0 + time('14:00:00')); | |
335 a3.setT0(a3.t0 + time('14:00:00')); | |
336 amat = [a1, a2, a3; a3, a1, a2]; | |
337 st = '14:00:25'; | |
338 et = '14:01:15'; | |
339 pl = plist('start_time', st, 'end_time', et); | |
340 out = split(amat, pl); | |
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 % 'amat' times numbers of intervals | |
352 % 2) Check that each output AO contains the correct data. | |
353 % | |
354 % </AlgoDescription> | |
355 | |
356 atest = true; | |
357 if stest | |
358 % <AlgoCode> | |
359 % Check we have the correct number of outputs | |
360 if numel(out) ~= numel(amat), atest = false; end | |
361 % Check each output | |
362 for kk=1:2:numel(out) | |
363 %%%% Check Interval '14:00:25' .. '14:01:15' | |
364 x = amat(kk).x + amat(kk).t0.double; | |
365 y = amat(kk).y; | |
366 % Comput start/end time | |
367 ts = time(st).double; | |
368 te = time(et).double; | |
369 idx = find(x >= ts & x < te); | |
370 % Normalize out data | |
371 ox = out(kk).x + out(kk).t0.double; | |
372 oy = out(kk).y; | |
373 % Check data | |
374 if ~isequal(ox, x(idx)), atest = false; end | |
375 if ~isequal(oy, y(idx)), atest = false; end | |
376 end | |
377 % </AlgoCode> | |
378 else | |
379 atest = false; | |
380 end | |
381 | |
382 % Return a result structure | |
383 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
384 end % END UTP_03 | |
385 | |
386 %% UTP_04 | |
387 | |
388 % <TestDescription> | |
389 % | |
390 % Tests that the split method works with a list of AOs as input. | |
391 % | |
392 % </TestDescription> | |
393 function result = utp_04 | |
394 | |
395 % <SyntaxDescription> | |
396 % | |
397 % Tests that the split method works with a list of AOs as input. | |
398 % | |
399 % </SyntaxDescription> | |
400 | |
401 try | |
402 % <SyntaxCode> | |
403 n1 = 300; | |
404 fs1 = 3; | |
405 x1 = 0:(1/fs1):(n1/fs1)-1/fs1; | |
406 a1 = ao(x1, randn(n1,1), fs1); | |
407 n2 = 100; | |
408 fs2 = 1; | |
409 x2 = 0:(1/fs2):(n2/fs2)-1/fs2; | |
410 a2 = ao(x2, randn(n2,1), fs2); | |
411 n3 = 100; | |
412 fs3 = .3; | |
413 x3 = 0:(1/fs3):(n3/fs3)-1/fs3; | |
414 a3 = ao(x3, randn(n3,1), fs3); | |
415 a1.setT0(a1.t0 + time('14:00:00')); | |
416 a2.setT0(a2.t0 + time('14:00:00')); | |
417 a3.setT0(a3.t0 + time('14:00:00')); | |
418 st = '14:00:25'; | |
419 et = '14:01:15'; | |
420 pl = plist('start_time', st, 'end_time', et); | |
421 out = split(a1, a2, a3, pl); | |
422 % </SyntaxCode> | |
423 stest = true; | |
424 catch err | |
425 disp(err.message) | |
426 stest = false; | |
427 end | |
428 | |
429 % <AlgoDescription> | |
430 % | |
431 % 1) Check that the number of elements in 'out' is the same as in | |
432 % 'amat' times numbers of intervals | |
433 % 2) Check that each output AO contains the correct data. | |
434 % | |
435 % </AlgoDescription> | |
436 | |
437 atest = true; | |
438 aoin = [a1, a2, a3]; | |
439 if stest | |
440 % <AlgoCode> | |
441 % Check we have the correct number of outputs | |
442 if numel(out) ~= numel(aoin), atest = false; end | |
443 % Check each output | |
444 for kk=1:2:numel(out) | |
445 %%%% Check Interval '14:00:25' .. '14:01:15' | |
446 x = aoin(kk).x + aoin(kk).t0.double; | |
447 y = aoin(kk).y; | |
448 % Comput start/end time | |
449 ts = time(st).double; | |
450 te = time(et).double; | |
451 idx = find(x >= ts & x < te); | |
452 % Normalize out data | |
453 ox = out(kk).x + out(kk).t0.double; | |
454 oy = out(kk).y; | |
455 % Check data | |
456 if ~isequal(ox, x(idx)), atest = false; end | |
457 if ~isequal(oy, y(idx)), atest = false; end | |
458 end | |
459 % </AlgoCode> | |
460 else | |
461 atest = false; | |
462 end | |
463 | |
464 % Return a result structure | |
465 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
466 end % END UTP_04 | |
467 | |
468 %% UTP_05 | |
469 | |
470 % <TestDescription> | |
471 % | |
472 % Tests that the split method works with a mix of different shaped AOs as | |
473 % input. | |
474 % | |
475 % </TestDescription> | |
476 function result = utp_05 | |
477 | |
478 % <SyntaxDescription> | |
479 % | |
480 % Tests that the split method works with a mix of different shaped AOs as | |
481 % input. | |
482 % | |
483 % </SyntaxDescription> | |
484 | |
485 try | |
486 % <SyntaxCode> | |
487 n1 = 300; | |
488 fs1 = 3; | |
489 x1 = 0:(1/fs1):(n1/fs1)-1/fs1; | |
490 a1 = ao(x1, randn(n1,1), fs1); | |
491 n2 = 100; | |
492 fs2 = 1; | |
493 x2 = 0:(1/fs2):(n2/fs2)-1/fs2; | |
494 a2 = ao(x2, randn(n2,1), fs2); | |
495 n3 = 100; | |
496 fs3 = .3; | |
497 x3 = 5000:(1/fs3):5000+((n3/fs3)-1/fs3); | |
498 a3 = ao(x3, randn(n3,1), fs3); | |
499 a1.setT0(a1.t0 + time('14:00:00')); | |
500 a2.setT0(a2.t0 + time('14:00:00')); | |
501 a3.setT0(a3.t0 + time('14:00:00')); | |
502 st = '14:00:25'; | |
503 et = '14:01:15'; | |
504 pl = plist('start_time', st, 'end_time', et); | |
505 out = split(a1, [a2;a1], a3, pl); | |
506 % </SyntaxCode> | |
507 stest = true; | |
508 catch err | |
509 disp(err.message) | |
510 stest = false; | |
511 end | |
512 | |
513 % <AlgoDescription> | |
514 % | |
515 % 1) Check that the number of elements in 'out' is the same as in | |
516 % 'amat' times numbers of intervals | |
517 % 2) Check that each output AO contains the correct data. | |
518 % | |
519 % </AlgoDescription> | |
520 | |
521 atest = true; | |
522 aoin = [a1, a2, a1, a3]; | |
523 if stest | |
524 % <AlgoCode> | |
525 % Check we have the correct number of outputs | |
526 if numel(out) ~= numel(aoin), atest = false; end | |
527 % Check each output | |
528 for kk=1:2:numel(out) | |
529 %%%% Check Interval '14:00:25' .. '14:01:15' | |
530 x = aoin(kk).x + aoin(kk).t0.double; | |
531 y = aoin(kk).y; | |
532 % Comput start/end time | |
533 ts = time(st).double; | |
534 te = time(et).double; | |
535 idx = find(x >= ts & x < te); | |
536 % Normalize out data | |
537 ox = out(kk).x + out(kk).t0.double; | |
538 oy = out(kk).y; | |
539 % Check data | |
540 if ~isequal(ox, x(idx)), atest = false; end | |
541 if ~isequal(oy, y(idx)), atest = false; end | |
542 end | |
543 % </AlgoCode> | |
544 else | |
545 atest = false; | |
546 end | |
547 | |
548 % Return a result structure | |
549 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
550 end % END UTP_05 | |
551 | |
552 %% UTP_06 | |
553 | |
554 % <TestDescription> | |
555 % | |
556 % Tests that the split method properly applies history. | |
557 % | |
558 % </TestDescription> | |
559 function result = utp_06 | |
560 | |
561 % <SyntaxDescription> | |
562 % | |
563 % Test that the result of applying the split method can be processed back. | |
564 % | |
565 % </SyntaxDescription> | |
566 | |
567 try | |
568 % <SyntaxCode> | |
569 n1 = 100; | |
570 fs1 = .3; | |
571 x1 = 5000:1/fs1:5000+((n1/fs1)-1/fs1); | |
572 a1 = ao(x1, randn(n1,1), fs1); | |
573 a1.setT0(a1.t0 + time('14:00:00')); | |
574 st = '14:00:25'; | |
575 et = '14:01:15'; | |
576 pl = plist('start_time', st, 'end_time', et); | |
577 out = split(a1, pl); | |
578 mout = rebuild(out); | |
579 % </SyntaxCode> | |
580 stest = true; | |
581 catch err | |
582 disp(err.message) | |
583 stest = false; | |
584 end | |
585 | |
586 % <AlgoDescription> | |
587 % | |
588 % 1) Check that the last entry in the history of 'out' corresponds to | |
589 % 'split'. | |
590 % 2) Check that the re-built object is the same object as the input. | |
591 % | |
592 % </AlgoDescription> | |
593 | |
594 atest = true; | |
595 if stest | |
596 % <AlgoCode> | |
597 % Check the last step in the history of 'out' | |
598 if ~strcmp(out.hist.methodInfo.mname, 'split'), atest = false; end | |
599 % The rebuilt object must be the same as 'out' | |
600 if ~eq(mout, out, ple2), atest = false; end | |
601 % </AlgoCode> | |
602 else | |
603 atest = false; | |
604 end | |
605 | |
606 % Return a result structure | |
607 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
608 end % END UTP_06 | |
609 | |
610 %% UTP_07 | |
611 | |
612 % <TestDescription> | |
613 % | |
614 % The split method can not modify the input AO. | |
615 % | |
616 % </TestDescription> | |
617 function result = utp_07 | |
618 | |
619 % <SyntaxDescription> | |
620 % | |
621 % The split method can not modify the input AO. | |
622 % | |
623 % </SyntaxDescription> | |
624 | |
625 try | |
626 % <SyntaxCode> | |
627 a1 = ao(5000:5099, randn(100,1), 1); | |
628 a1.setT0(a1.t0 + time('14:00:00')); | |
629 st = '14:00:25'; | |
630 et = '14:01:15'; | |
631 pl = plist('start_time', st, 'end_time', et); | |
632 amodi = ao(at1); | |
633 aeq = ao(at1); | |
634 out = aeq.split(pl); | |
635 amodi.split(pl); | |
636 stest = false; | |
637 % </SyntaxCode> | |
638 catch | |
639 stest = true; | |
640 end | |
641 | |
642 % <AlgoDescription> | |
643 % | |
644 % 1) Nothind to do. | |
645 % | |
646 % </AlgoDescription> | |
647 | |
648 atest = true; | |
649 if stest | |
650 % <AlgoCode> | |
651 % </AlgoCode> | |
652 else | |
653 atest = false; | |
654 end | |
655 | |
656 % Return a result structure | |
657 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
658 end % END UTP_07 | |
659 | |
660 %% UTP_08 | |
661 | |
662 % <TestDescription> | |
663 % | |
664 % Test the shape of the output. | |
665 % | |
666 % </TestDescription> | |
667 function result = utp_08 | |
668 | |
669 % <SyntaxDescription> | |
670 % | |
671 % Test that the split method keeps the data shape of the input object. | |
672 % The input AO must be an AO with row data and an AO with column data. | |
673 % | |
674 % </SyntaxDescription> | |
675 | |
676 try | |
677 % <SyntaxCode> | |
678 a1 = ao(5000:5099, randn(100,1), 1); | |
679 a2 = ao(5000:5099, randn(100,1).', 1); | |
680 a1.setT0(a1.t0 + time('14:00:00')); | |
681 a2.setT0(a1.t0 + time('14:00:00')); | |
682 st = '14:00:25'; | |
683 et = '14:01:15'; | |
684 pl = plist('start_time', st, 'end_time', et); | |
685 out1 = split(a1, pl); | |
686 out2 = split(a2, pl); | |
687 % </SyntaxCode> | |
688 stest = true; | |
689 catch err | |
690 disp(err.message) | |
691 stest = false; | |
692 end | |
693 | |
694 % <AlgoDescription> | |
695 % | |
696 % 1) Check that the shape of the data doesn't change. | |
697 % | |
698 % </AlgoDescription> | |
699 | |
700 atest = true; | |
701 if stest | |
702 % <AlgoCode> | |
703 % Check the shape of the output data | |
704 if size(out1.data.y,1) == 1, atest = false; end | |
705 if size(out2.data.y,2) == 1, atest = false; end | |
706 % </AlgoCode> | |
707 else | |
708 atest = false; | |
709 end | |
710 | |
711 % Return a result structure | |
712 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
713 end % END UTP_08 | |
714 | |
715 %% UTP_09 | |
716 | |
717 % <TestDescription> | |
718 % | |
719 % Check that the split method pass back the output objects to a list of | |
720 % output variables or to a single variable. | |
721 % | |
722 % </TestDescription> | |
723 function result = utp_09 | |
724 | |
725 % <SyntaxDescription> | |
726 % | |
727 % Call the method with a list of output variables and with a single | |
728 % output variable. Additionaly check that the rebuild method works on | |
729 % the output. | |
730 % | |
731 % </SyntaxDescription> | |
732 | |
733 try | |
734 % <SyntaxCode> | |
735 a1 = ao(5000:5099, randn(100,1), 1); | |
736 a2 = ao(5000:5099, randn(100,1).', 1); | |
737 a1.setT0(a1.t0 + time('14:00:00')); | |
738 a2.setT0(a1.t0 + time('14:00:00')); | |
739 st = '14:00:25'; | |
740 et = '14:01:15'; | |
741 pl = plist('start_time', st, 'end_time', et); | |
742 [o1, o2] = split(a1, a2, pl); | |
743 o3 = split(a1, a2, pl); | |
744 mout1 = rebuild(o1); | |
745 mout2 = rebuild(o2); | |
746 mout3 = rebuild(o3); | |
747 % </SyntaxCode> | |
748 stest = true; | |
749 catch err | |
750 disp(err.message) | |
751 stest = false; | |
752 end | |
753 | |
754 % <AlgoDescription> | |
755 % | |
756 % 1) Check that the output contains the right number of objects | |
757 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
758 % | |
759 % </AlgoDescription> | |
760 | |
761 atest = true; | |
762 if stest | |
763 % <AlgoCode> | |
764 % Check the number of outputs | |
765 if numel(o1) ~=1, atest = false; end | |
766 if numel(o2) ~=1, atest = false; end | |
767 if numel(o3) ~=2, atest = false; end | |
768 % Check the rebuilding of the object | |
769 if ~eq(o1, mout1, ple2), atest = false; end | |
770 if ~eq(o2, mout2, ple2), atest = false; end | |
771 if ~eq(o3, mout3, ple2), atest = false; end | |
772 % </AlgoCode> | |
773 else | |
774 atest = false; | |
775 end | |
776 | |
777 % Return a result structure | |
778 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
779 end % END UTP_09 | |
780 | |
781 %% UTP_10 | |
782 | |
783 % <TestDescription> | |
784 % | |
785 % Check that the split method can handle AO which have a collaped x-axis. | |
786 % | |
787 % </TestDescription> | |
788 function result = utp_10 | |
789 | |
790 % <SyntaxDescription> | |
791 % | |
792 % Check that the split method can handle AO which have a collaped x-axis. | |
793 % | |
794 % </SyntaxDescription> | |
795 | |
796 try | |
797 % <SyntaxCode> | |
798 plao = plist('fs', 30, 'nsecs', 30, 'waveform', 'sine wave', 'f', 1.23, 'phi', 30); | |
799 a1 = ao(plao); | |
800 a1.setT0(a1.t0 + time('14:00:00')); | |
801 st = '14:00:07'; | |
802 et = '14:00:17'; | |
803 pl = plist('start_time', st, 'end_time', et); | |
804 out = split(a1, pl); | |
805 mout = rebuild(out); | |
806 % </SyntaxCode> | |
807 stest = true; | |
808 catch err | |
809 disp(err.message) | |
810 stest = false; | |
811 end | |
812 | |
813 % <AlgoDescription> | |
814 % | |
815 % 1) Check the number of outputs | |
816 % 2) Check the output | |
817 % 3) Check that the 'rebuild' method produces the same object as 'out'. | |
818 % | |
819 % </AlgoDescription> | |
820 | |
821 atest = true; | |
822 if stest | |
823 % <AlgoCode> | |
824 % Check the number of outputs | |
825 if numel(out) ~= 1, atest = false; end | |
826 % Check the output | |
827 x = a1.x + a1.t0.double; | |
828 y = a1.y; | |
829 % Comput start/end time | |
830 ts = time(st).double; | |
831 te = time(et).double; | |
832 idx = find(x >= ts & x < te); | |
833 % Normalize out data | |
834 ox = out.x + out.t0.double; | |
835 oy = out.y; | |
836 % Check data | |
837 if ~isequal(ox, x(idx)), atest = false; end | |
838 if ~isequal(oy, y(idx)), atest = false; end | |
839 % Check the rebuilding of the object | |
840 if ~eq(out, mout, ple2), atest = false; end | |
841 % </AlgoCode> | |
842 else | |
843 atest = false; | |
844 end | |
845 | |
846 % Return a result structure | |
847 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
848 end % END UTP_10 | |
849 | |
850 | |
851 %% UTP_12 | |
852 | |
853 % <TestDescription> | |
854 % | |
855 % Check that the split method uses the key-words: start_time and duration | |
856 % | |
857 % </TestDescription> | |
858 function result = utp_12 | |
859 | |
860 % <SyntaxDescription> | |
861 % | |
862 % Check that the split method uses the key-words: start_time and | |
863 % duration | |
864 % | |
865 % </SyntaxDescription> | |
866 | |
867 try | |
868 % <SyntaxCode> | |
869 a1 = ao(5000:5099, randn(100,1), 1); | |
870 a1.setT0(a1.t0 + time('14:00:00')); | |
871 st = format(time('14:01:00')+5000, 'HH:MM:SS'); | |
872 du = '00:00:10'; | |
873 plc = plist('start_time', st, 'duration', du); | |
874 plo = plist('start_time', time(st), 'duration', time(du)); | |
875 outc = split(a1, plc); | |
876 outo = split(a1, plo); | |
877 moutc = rebuild(outc); | |
878 mouto = rebuild(outo); | |
879 % </SyntaxCode> | |
880 stest = true; | |
881 catch err | |
882 disp(err.message) | |
883 stest = false; | |
884 end | |
885 | |
886 % <AlgoDescription> | |
887 % | |
888 % 1) Check the number of outputs | |
889 % 2) Check the output | |
890 % 3) Check that the 'rebuild' method produces the same object as 'out'. | |
891 % | |
892 % </AlgoDescription> | |
893 | |
894 atest = true; | |
895 TOL = 1e-11; | |
896 if stest | |
897 % <AlgoCode> | |
898 % Check the number of outputs | |
899 if numel(outc) ~= 1, atest = false; end | |
900 if numel(outo) ~= 1, atest = false; end | |
901 % Check the output | |
902 x = a1.x + a1.t0.double; | |
903 y = a1.y; | |
904 % Comput start/end time | |
905 ts = time(st).double; | |
906 te = ts + time(du).double; | |
907 idx = find(x >= ts & x < te); | |
908 % Normalize out data | |
909 oxc = outc.x + outc.t0.double; | |
910 oyc = outc.y; | |
911 oxo = outo.x + outo.t0.double; | |
912 oyo = outo.y; | |
913 % Check data | |
914 if any(abs(oxc - x(idx)) > TOL), atest = false; end | |
915 if ~isequal(oyc, y(idx)), atest = false; end | |
916 if any(abs(oxo - x(idx)) > TOL), atest = false; end | |
917 if ~isequal(oyo, y(idx)), atest = false; end | |
918 % Check the rebuilding of the object | |
919 if ~eq(outc, moutc, ple2), atest = false; end | |
920 if ~eq(outo, mouto, ple2), atest = false; end | |
921 % </AlgoCode> | |
922 else | |
923 atest = false; | |
924 end | |
925 | |
926 % Return a result structure | |
927 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
928 end % END UTP_12 | |
929 | |
930 %% UTP_13 | |
931 | |
932 % <TestDescription> | |
933 % | |
934 % Check that the split method uses the key-words: timespan | |
935 % | |
936 % </TestDescription> | |
937 function result = utp_13 | |
938 | |
939 % <SyntaxDescription> | |
940 % | |
941 % Check that the split method uses the key-words: timespan | |
942 % | |
943 % </SyntaxDescription> | |
944 | |
945 try | |
946 % <SyntaxCode> | |
947 a1 = ao(5000:5099, randn(100,1), 1); | |
948 a1.setT0(a1.t0 + time('14:00:00')); | |
949 ts = timespan(time('14:00:20')+5e3, time('14:00:50')+5e3); | |
950 pl = plist('timespan', ts); | |
951 out = split(a1, pl); | |
952 mout = rebuild(out); | |
953 % </SyntaxCode> | |
954 stest = true; | |
955 catch err | |
956 disp(err.message) | |
957 stest = false; | |
958 end | |
959 | |
960 % <AlgoDescription> | |
961 % | |
962 % 1) Check the number of outputs | |
963 % 2) Check the output | |
964 % 3) Check that the 'rebuild' method produces the same object as 'out'. | |
965 % | |
966 % </AlgoDescription> | |
967 | |
968 atest = true; | |
969 TOL = 1e-11; | |
970 if stest | |
971 % <AlgoCode> | |
972 % Check the number of outputs | |
973 if numel(out) ~= 1, atest = false; end | |
974 % Check the output | |
975 x = a1.x + a1.t0.double; | |
976 y = a1.y; | |
977 % Comput start/end time | |
978 ts = double(time('14:00:20')+5e3); | |
979 te = double(time('14:00:50')+5e3); | |
980 idx = find(x >= ts & x < te); | |
981 % Normalize out data | |
982 ox = out.x + out.t0.double; | |
983 oy = out.y; | |
984 % Check data | |
985 if any(abs(ox - x(idx)) > TOL), atest = false; end | |
986 if ~isequal(oy, y(idx)), atest = false; end | |
987 % Check the rebuilding of the object | |
988 if ~eq(out, mout, ple2), atest = false; end | |
989 % </AlgoCode> | |
990 else | |
991 atest = false; | |
992 end | |
993 | |
994 % Return a result structure | |
995 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
996 end % END UTP_13 | |
997 | |
998 %% UTP_14 | |
999 | |
1000 % <TestDescription> | |
1001 % | |
1002 % Check that the split method uses the key-words: start_time and end_time | |
1003 % | |
1004 % </TestDescription> | |
1005 function result = utp_14 | |
1006 | |
1007 % <SyntaxDescription> | |
1008 % | |
1009 % Check that the split method uses the key-words: start_time and end_time | |
1010 % | |
1011 % </SyntaxDescription> | |
1012 | |
1013 try | |
1014 % <SyntaxCode> | |
1015 a1 = ao(plist('xvals', '0:199', 'yvals', 'randn(200,1)', 'fs', 1, 't0', '14:00:00 2009-02-17')); | |
1016 st = '14:01:40 2009-02-17'; | |
1017 et = '14:03:20 17-02-2009'; | |
1018 plc = plist('start_time', st, 'end_time', et); | |
1019 plo = plist('start_time', time(st), 'end_time', time(et)); | |
1020 outc = split(a1, plc); | |
1021 outo = split(a1, plo); | |
1022 moutc = rebuild(outc); | |
1023 mouto = rebuild(outo); | |
1024 % </SyntaxCode> | |
1025 stest = true; | |
1026 catch err | |
1027 disp(err.message) | |
1028 stest = false; | |
1029 end | |
1030 | |
1031 % <AlgoDescription> | |
1032 % | |
1033 % 1) Check the number of outputs | |
1034 % 2) Check the output | |
1035 % 3) Check that the 'rebuild' method produces the same object as 'out'. | |
1036 % | |
1037 % </AlgoDescription> | |
1038 | |
1039 atest = true; | |
1040 if stest | |
1041 % <AlgoCode> | |
1042 % Check the number of outputs | |
1043 if numel(outc) ~= 1, atest = false; end | |
1044 if numel(outo) ~= 1, atest = false; end | |
1045 % Check the output | |
1046 x = a1.x + a1.t0.double; | |
1047 y = a1.y; | |
1048 % Comput start/end time | |
1049 ts = time(st).double; | |
1050 te = time(et).double; | |
1051 idx = find(x >= ts & x < te); | |
1052 % Normalize out data | |
1053 oxc = outc.x + outc.t0.double; | |
1054 oyc = outc.y; | |
1055 oxo = outo.x + outo.t0.double; | |
1056 oyo = outo.y; | |
1057 % Check data | |
1058 if ~isequal(oxc, x(idx)), atest = false; end | |
1059 if ~isequal(oyc, y(idx)), atest = false; end | |
1060 if ~isequal(oxo, x(idx)), atest = false; end | |
1061 if ~isequal(oyo, y(idx)), atest = false; end | |
1062 % Check the rebuilding of the object | |
1063 if ~eq(outc, moutc, ple2), atest = false; end | |
1064 if ~eq(outo, mouto, ple2), atest = false; end | |
1065 % </AlgoCode> | |
1066 else | |
1067 atest = false; | |
1068 end | |
1069 | |
1070 % Return a result structure | |
1071 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1072 end % END UTP_14 | |
1073 | |
1074 %% UTP_15 | |
1075 | |
1076 % <TestDescription> | |
1077 % | |
1078 % Check that the split method works with notequal sampled data. | |
1079 % Check that the interval can be passed via two time objects. | |
1080 % | |
1081 % </TestDescription> | |
1082 function result = utp_15 | |
1083 | |
1084 % <SyntaxDescription> | |
1085 % | |
1086 % Check that the split method works with notequal sampled data. | |
1087 % Check that the interval can be passed via two time objects. | |
1088 % | |
1089 % </SyntaxDescription> | |
1090 | |
1091 try | |
1092 % <SyntaxCode> | |
1093 x = [1:1018 1020:1999 2001:3000 3002:6500 6502:7000 7002:10000]; | |
1094 y = randn(1e4,1); | |
1095 y = y(x); % Use the x values as an index | |
1096 a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 't0', '2009-11-03 18:00:00.000', 'yunits', 'N')); | |
1097 | |
1098 start_time = time('2009-11-03 18:10:00.000'); | |
1099 end_time = time('2009-11-03 18:20:00.000'); | |
1100 | |
1101 pl1 = plist(... | |
1102 'start_time', start_time, ... | |
1103 'end_time', end_time); | |
1104 out1 = split(a1, pl1); | |
1105 mout1 = rebuild(out1); | |
1106 % </SyntaxCode> | |
1107 stest = true; | |
1108 catch err | |
1109 disp(err.message) | |
1110 stest = false; | |
1111 end | |
1112 | |
1113 % <AlgoDescription> | |
1114 % | |
1115 % 1) Check the outputs | |
1116 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
1117 % | |
1118 % </AlgoDescription> | |
1119 | |
1120 atest = true; | |
1121 if stest | |
1122 % <AlgoCode> | |
1123 | |
1124 % Check number of seconds | |
1125 dt = double(end_time - start_time); | |
1126 if out1.nsecs ~= dt, atest = false; end | |
1127 % Check t0 | |
1128 dt0 = double(out1.t0 - a1.t0); | |
1129 if dt0 ~= 0, atest = false; end | |
1130 % Check the rebuilding of the object | |
1131 if ~eq(out1, mout1, ple2), atest = false; end | |
1132 % </AlgoCode> | |
1133 else | |
1134 atest = false; | |
1135 end | |
1136 | |
1137 % Return a result structure | |
1138 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1139 end % END UTP_15 | |
1140 | |
1141 | |
1142 %% UTP_16 | |
1143 | |
1144 % <TestDescription> | |
1145 % | |
1146 % Check that the split method works with notequal sampled data. | |
1147 % Check that the interval can be passed via two time strings. | |
1148 % | |
1149 % </TestDescription> | |
1150 function result = utp_16 | |
1151 | |
1152 % <SyntaxDescription> | |
1153 % | |
1154 % Check that the split method works with notequal sampled data. | |
1155 % Check that the interval can be passed via two time strings. | |
1156 % | |
1157 % </SyntaxDescription> | |
1158 | |
1159 try | |
1160 % <SyntaxCode> | |
1161 x = [1:1018 1020:1999 2001:3000 3002:6500 6502:7000 7002:10000]; | |
1162 y = randn(1e5, 1); | |
1163 y = y(x); % Use the x values as an index | |
1164 a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 't0', '2009-11-03 18:00:00.000', 'yunits', 'N')); | |
1165 | |
1166 start_time = '2009-11-03 18:10:00.000'; | |
1167 end_time = '2009-11-03 18:20:00.000'; | |
1168 | |
1169 pl1 = plist(... | |
1170 'start_time', start_time, ... | |
1171 'end_time', end_time); | |
1172 out1 = split(a1, pl1); | |
1173 mout1 = rebuild(out1); | |
1174 % </SyntaxCode> | |
1175 stest = true; | |
1176 catch err | |
1177 disp(err.message) | |
1178 stest = false; | |
1179 end | |
1180 | |
1181 % <AlgoDescription> | |
1182 % | |
1183 % 1) Check the output | |
1184 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
1185 % | |
1186 % </AlgoDescription> | |
1187 | |
1188 atest = true; | |
1189 if stest | |
1190 % <AlgoCode> | |
1191 | |
1192 % Check number of seconds | |
1193 dt = double(time(end_time) - time(start_time)); | |
1194 if out1.nsecs ~= dt, atest = false; end | |
1195 % Check t0 | |
1196 dt0 = double(out1.t0 - a1.t0); | |
1197 if dt0 ~= 0, atest = false; end | |
1198 % Check the rebuilding of the object | |
1199 if ~eq(out1, mout1, ple2), atest = false; end | |
1200 % </AlgoCode> | |
1201 else | |
1202 atest = false; | |
1203 end | |
1204 | |
1205 % Return a result structure | |
1206 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1207 end % END UTP_16 | |
1208 | |
1209 %% UTP_17 | |
1210 | |
1211 % <TestDescription> | |
1212 % | |
1213 % Check that the split method works with notequal sampled data. | |
1214 % Check that the interval can be passed via one timespan object. | |
1215 % | |
1216 % </TestDescription> | |
1217 function result = utp_17 | |
1218 | |
1219 % <SyntaxDescription> | |
1220 % | |
1221 % Check that the split method works with notequal sampled data. | |
1222 % Check that the interval can be passed via one timespan object. | |
1223 % | |
1224 % </SyntaxDescription> | |
1225 | |
1226 try | |
1227 % <SyntaxCode> | |
1228 x = [1:1018 1020:1999 2001:3000 3002:6500 6502:7000 7002:10000]; | |
1229 y = randn(1e5, 1); | |
1230 y = y(x); % Use the x values as an index | |
1231 a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 't0', '2009-11-03 18:00:00.000', 'yunits', 'N')); | |
1232 | |
1233 start_time = '2009-11-03 18:10:00.000'; | |
1234 end_time = '2009-11-03 18:15:00.000'; | |
1235 | |
1236 time_range = timespan(start_time, end_time); | |
1237 | |
1238 pl1 = plist(... | |
1239 'timespan', time_range); | |
1240 out1 = split(a1, pl1); | |
1241 mout1 = rebuild(out1); | |
1242 % </SyntaxCode> | |
1243 stest = true; | |
1244 catch err | |
1245 disp(err.message) | |
1246 stest = false; | |
1247 end | |
1248 | |
1249 % <AlgoDescription> | |
1250 % | |
1251 % 1) Check the output | |
1252 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
1253 % | |
1254 % </AlgoDescription> | |
1255 | |
1256 atest = true; | |
1257 if stest | |
1258 % <AlgoCode> | |
1259 | |
1260 % Check number of seconds | |
1261 dt = double(time_range.endT - time_range.startT); | |
1262 if out1.nsecs ~= dt, atest = false; end | |
1263 % Check t0 | |
1264 dt0 = double(out1.t0 - a1.t0); | |
1265 if dt0 ~= 0, atest = false; end | |
1266 % Check the rebuilding of the object | |
1267 if ~eq(out1, mout1, ple2), atest = false; end | |
1268 % </AlgoCode> | |
1269 else | |
1270 atest = false; | |
1271 end | |
1272 | |
1273 % Return a result structure | |
1274 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1275 end % END UTP_17 | |
1276 | |
1277 end |