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