comparison testing/utp_1.1/utps/ao/utp_ao_split_chunks.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_chunks.m,v 1.7 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_chunks(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 % Test AOs
30 [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao;
31 at4.setY(randn(15));
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 plist(N) || plist(CHUNKS)
47 results = [results utp_11(mthd, at1, ple1, plist('N', 10))]; % Test plotinfo doesn't disappear
48 results = [results utp_12]; % Test 'dx' and 'dy'
49 results = [results utp_13]; % Test plist(match)
50 results = [results utp_15]; % Test not equal sampled data (tsdata)
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 idx = 1;
113 if ~isempty(io(idx).sets), atest = false; end
114 if ~isempty(io(idx).plists), atest = false; end
115 %%% Check all Sets
116 idx = 2;
117 if ~any(strcmpi(io(idx).sets, 'Default')), atest = false; end
118 if ~any(strcmpi(io(idx).sets, 'By times')), atest = false; end
119 if ~any(strcmpi(io(idx).sets, 'By frequencies')), atest = false; end
120 if ~any(strcmpi(io(idx).sets, 'By samples')), atest = false; end
121 if ~any(strcmpi(io(idx).sets, 'By chunks')), atest = false; end
122 if ~any(strcmpi(io(idx).sets, 'By interval start/end')), atest = false; end
123 if ~any(strcmpi(io(idx).sets, 'By interval start/duration')), atest = false; end
124 if ~any(strcmpi(io(idx).sets, 'By interval timespan')), atest = false; end
125 if numel(io(idx).plists) ~= numel(io(idx).sets), atest = false; end
126 %%%%%%%%%% SET 'Default'
127 idx = 3;
128 if io(idx).plists.nparams ~= 1, atest = false; end
129 % Check key
130 if ~io(idx).plists.isparam('times'), atest = false; end
131 % Check default value
132 if ~isEmptyDouble(io(idx).plists.find('times')), atest = false; end
133 % Check options
134 if ~isequal(io(idx).plists.getOptionsForParam('times'), {[]}), atest = false; end
135 %%%%%%%%%% SET 'By times'
136 idx = 4;
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 frequencies'
145 idx = 5;
146 if io(idx).plists.nparams ~= 1, atest = false; end
147 % Check key
148 if ~io(idx).plists.isparam('frequencies'), atest = false; end
149 % Check default value
150 if ~isEmptyDouble(io(idx).plists.find('frequencies')), atest = false; end
151 % Check options
152 if ~isequal(io(idx).plists.getOptionsForParam('frequencies'), {[]}), atest = false; end
153 %%%%%%%%%% SET 'By samples'
154 idx = 6;
155 if io(idx).plists.nparams ~= 1, atest = false; end
156 % Check key
157 if ~io(idx).plists.isparam('samples'), atest = false; end
158 % Check default value
159 if ~isEmptyDouble(io(idx).plists.find('samples')), atest = false; end
160 % Check options
161 if ~isequal(io(idx).plists.getOptionsForParam('samples'), {[]}), atest = false; end
162 %%%%%%%%%% SET 'By chunks'
163 idx = 7;
164 if io(idx).plists.nparams ~= 2, atest = false; end
165 % Check key
166 if ~io(idx).plists.isparam('N'), atest = false; end
167 if ~io(idx).plists.isparam('match'), atest = false; end
168 % Check default value
169 if ~isEmptyDouble(io(idx).plists.find('N')), atest = false; end
170 if ~isequal(io(idx).plists.find('match'), true), atest = false; end
171 % Check options
172 if ~isequal(io(idx).plists.getOptionsForParam('N'), {[]}), atest = false; end
173 if ~isequal(io(idx).plists.getOptionsForParam('match'), {true, false}), atest = false; end
174 %%%%%%%%%% SET 'By interval start/end'
175 idx = 8;
176 if io(idx).plists.nparams ~= 2, atest = false; end
177 % Check key
178 if ~io(idx).plists.isparam('start_time'), atest = false; end
179 if ~io(idx).plists.isparam('end_time'), atest = false; end
180 % Check default value
181 if ~eq(io(idx).plists.find('start_time'), time(0), ple1), atest = false; end
182 if ~eq(io(idx).plists.find('end_time'), time(0), ple1), atest = false; end
183 % Check options
184 %%%%%%%%%% SET 'By interval start/duration'
185 idx = 9;
186 if io(idx).plists.nparams ~= 2, atest = false; end
187 % Check key
188 if ~io(idx).plists.isparam('start_time'), atest = false; end
189 if ~io(idx).plists.isparam('duration'), atest = false; end
190 % Check default value
191 if ~eq(io(idx).plists.find('start_time'), time(0), ple1), atest = false; end
192 if ~eq(io(idx).plists.find('duration'), time(0), ple1), atest = false; end
193 % Check options
194 %%%%%%%%%% SET 'By interval timespan'
195 idx = 10;
196 if io(idx).plists.nparams ~= 1, atest = false; end
197 % Check key
198 if ~io(idx).plists.isparam('timespan'), atest = false; end
199 % Check default value
200 ts = timespan(0,0);
201 if ~eq(io(idx).plists.find('timespan'), ts, ple1), atest = false; end
202 % Check options
203 end
204 % </AlgoCode>
205 else
206 atest = false;
207 end
208
209 % Return a result structure
210 result = utp_prepare_result(atest, stest, dbstack, mfilename);
211 end % END UTP_01
212
213 %% UTP_02
214
215 % <TestDescription>
216 %
217 % Tests that the split method works with a vector of AOs as input.
218 %
219 % </TestDescription>
220 function result = utp_02
221
222 % <SyntaxDescription>
223 %
224 % Test that the split method works for a vector of AOs as input.
225 %
226 % </SyntaxDescription>
227
228 try
229 % <SyntaxCode>
230 N = 13;
231 pl = plist('chunks', N);
232 out = split(atvec, pl);
233 % </SyntaxCode>
234 stest = true;
235 catch err
236 disp(err.message)
237 stest = false;
238 end
239
240 % <AlgoDescription>
241 %
242 % 1) Check that the number of outputs
243 % 2) Check that each output AO contains the correct data.
244 %
245 % </AlgoDescription>
246
247 atest = true;
248 TOL = 1e-12;
249 if stest
250 % <AlgoCode>
251 % Check we have the correct number of outputs
252 if numel(out) ~= numel(atvec) * N, atest = false; end
253
254 % Check each output
255 for kk=1:numel(atvec)
256
257 ff = floor(length(atvec(kk).y)/N);
258 is = 1:ff:length(atvec(kk).y);
259 ie = ff:ff:length(atvec(kk).y);
260 idx = sort([is(1:N) ie(1:N)]);
261 idx(end) = length(atvec(kk).y);
262 for jj = 1:N
263
264 % Get reference values
265 x = atvec(kk).x;
266 y = atvec(kk).y;
267 % Get and normalize for tsdata the values
268 if isa(atvec(kk).data, 'tsdata')
269 t0off = (out((kk-1)*N+jj).t0.utc_epoch_milli - atvec(kk).t0.utc_epoch_milli)/1e3;
270 ox = out((kk-1)*N+jj).x + t0off;
271 else
272 ox = out((kk-1)*N+jj).x;
273 end
274 oy = out((kk-1)*N+jj).y;
275 % Compute the range
276 range = idx(jj*2-1):idx(jj*2);
277 % Check data
278 if any(abs(ox - x(range)) > TOL), atest = false; end
279 if ~isequal(oy, y(range)), atest = false; end
280 end
281 end
282 % </AlgoCode>
283 else
284 atest = false;
285 end
286
287 % Return a result structure
288 result = utp_prepare_result(atest, stest, dbstack, mfilename);
289 end % END UTP_02
290
291 %% UTP_03
292
293 % <TestDescription>
294 %
295 % Tests that the split method works with a matrix of AOs as input.
296 %
297 % </TestDescription>
298 function result = utp_03
299
300 % <SyntaxDescription>
301 %
302 % Tests that the split method works with a matrix of AOs as input.
303 %
304 % </SyntaxDescription>
305
306 try
307 % <SyntaxCode>
308 N = 4;
309 pl = plist('chunks', N);
310 out = split(atmat, pl);
311 % </SyntaxCode>
312 stest = true;
313 catch err
314 disp(err.message)
315 stest = false;
316 end
317
318 % <AlgoDescription>
319 %
320 % 1) Check that the number of outputs
321 % 2) Check that each output AO contains the correct data.
322 %
323 % </AlgoDescription>
324
325 atest = true;
326 TOL = 1e-14;
327 if stest
328 % <AlgoCode>
329 % Check we have the correct number of outputs
330 if numel(out) ~= numel(atmat) * N, atest = false; end
331
332 % Check each output
333 for kk=1:numel(atmat)
334
335 ff = floor(length(atmat(kk).y)/N);
336 is = 1:ff:length(atmat(kk).y);
337 ie = ff:ff:length(atmat(kk).y);
338 idx = sort([is(1:N) ie(1:N)]);
339 idx(end) = length(atmat(kk).y);
340
341 for jj = 1:N
342
343 % Get reference values
344 x = atmat(kk).x;
345 y = atmat(kk).y;
346 % Get and normalize for tsdata the values
347 if isa(atmat(kk).data, 'tsdata')
348 t0off = (out((kk-1)*N+jj).t0.utc_epoch_milli - atmat(kk).t0.utc_epoch_milli)/1e3;
349 ox = out((kk-1)*N+jj).x + t0off;
350 else
351 ox = out((kk-1)*N+jj).x;
352 end
353 oy = out((kk-1)*N+jj).y;
354 % Compute the range
355 range = idx(jj*2-1):idx(jj*2);
356 % Check data
357 if ~isa(atmat(kk).data, 'cdata')
358 if any(abs(ox - x(range)) > TOL), atest = false; end
359 if ~isequal(oy, y(range)), atest = false; end
360 else
361 if ~isequal(oy, y(range).'), atest = false; end
362 end
363 end
364 end
365 % </AlgoCode>
366 else
367 atest = false;
368 end
369
370 % Return a result structure
371 result = utp_prepare_result(atest, stest, dbstack, mfilename);
372 end % END UTP_03
373
374 %% UTP_04
375
376 % <TestDescription>
377 %
378 % Tests that the split method works with a list of AOs as input.
379 %
380 % </TestDescription>
381 function result = utp_04
382
383 % <SyntaxDescription>
384 %
385 % Tests that the split method works with a matrix of AOs as input.
386 %
387 % </SyntaxDescription>
388
389 try
390 % <SyntaxCode>
391 N = 4;
392 pl = plist('chunks', N);
393 out = split(at1, at2, at3, pl);
394 % </SyntaxCode>
395 stest = true;
396 catch err
397 disp(err.message)
398 stest = false;
399 end
400
401 % <AlgoDescription>
402 %
403 % 1) Check that the number of outputs
404 % 2) Check that each output AO contains the correct data.
405 %
406 % </AlgoDescription>
407
408 atest = true;
409 TOL = 1e-14;
410 aoin = [at1, at2, at3];
411 if stest
412 % <AlgoCode>
413 % Check we have the correct number of outputs
414 if numel(out) ~= numel(aoin) * N, atest = false; end
415
416 % Check each output
417 for kk=1:numel(aoin)
418
419 ff = floor(length(aoin(kk).y)/N);
420 is = 1:ff:length(aoin(kk).y);
421 ie = ff:ff:length(aoin(kk).y);
422 idx = sort([is(1:N) ie(1:N)]);
423 idx(end) = length(aoin(kk).y);
424
425 for jj = 1:N
426
427 % Get reference values
428 x = aoin(kk).x;
429 y = aoin(kk).y;
430 % Get and normalize for tsdata the values
431 if isa(aoin(kk).data, 'tsdata')
432 t0off = (out((kk-1)*N+jj).t0.utc_epoch_milli - aoin(kk).t0.utc_epoch_milli)/1e3;
433 ox = out((kk-1)*N+jj).x + t0off;
434 else
435 ox = out((kk-1)*N+jj).x;
436 end
437 oy = out((kk-1)*N+jj).y;
438 % Compute the range
439 range = idx(jj*2-1):idx(jj*2);
440 % Check data
441 if ~isa(aoin(kk).data, 'cdata')
442 if any(abs(ox - x(range)) > TOL), atest = false; end
443 if ~isequal(oy, y(range)), atest = false; end
444 else
445 if ~isequal(oy, y(range).'), atest = false; end
446 end
447 end
448 end
449 % </AlgoCode>
450 else
451 atest = false;
452 end
453
454 % Return a result structure
455 result = utp_prepare_result(atest, stest, dbstack, mfilename);
456 end % END UTP_04
457
458 %% UTP_05
459
460 % <TestDescription>
461 %
462 % Tests that the split method works with a mix of different shaped AOs as
463 % input.
464 %
465 % </TestDescription>
466 function result = utp_05
467
468 % <SyntaxDescription>
469 %
470 % Tests that the split method works with a matrix of AOs as input.
471 %
472 % </SyntaxDescription>
473
474 try
475 % <SyntaxCode>
476 N = 3;
477 pl = plist('chunks', N);
478 out = split(at1, atmat, atvec, at3, pl);
479 % </SyntaxCode>
480 stest = true;
481 catch err
482 disp(err.message)
483 stest = false;
484 end
485
486 % <AlgoDescription>
487 %
488 % 1) Check that the number of outputs
489 % 2) Check that each output AO contains the correct data.
490 %
491 % </AlgoDescription>
492
493 atest = true;
494 TOL = 1e-14;
495 aoin = [at1, reshape(atmat, 1, []), reshape(atvec, 1, []), at3];
496 if stest
497 % <AlgoCode>
498 % Check we have the correct number of outputs
499 if numel(out) ~= numel(aoin) * N, atest = false; end
500
501 % Check each output
502 for kk=1:numel(aoin)
503
504 ff = floor(length(aoin(kk).y)/N);
505 is = 1:ff:length(aoin(kk).y);
506 ie = ff:ff:length(aoin(kk).y);
507 idx = sort([is(1:N) ie(1:N)]);
508 idx(end) = length(aoin(kk).y);
509
510 for jj = 1:N
511
512 % Get reference values
513 x = aoin(kk).x;
514 y = aoin(kk).y;
515 % Get and normalize for tsdata the values
516 if isa(aoin(kk).data, 'tsdata')
517 t0off = (out((kk-1)*N+jj).t0.utc_epoch_milli - aoin(kk).t0.utc_epoch_milli)/1e3;
518 ox = out((kk-1)*N+jj).x + t0off;
519 else
520 ox = out((kk-1)*N+jj).x;
521 end
522 oy = out((kk-1)*N+jj).y;
523 % Compute the range
524 range = idx(jj*2-1):idx(jj*2);
525 % Check data
526 if ~isa(aoin(kk).data, 'cdata')
527 if any(abs(ox - x(range)) > TOL), atest = false; end
528 if ~isequal(oy, y(range)), atest = false; end
529 else
530 if ~isequal(oy, y(range).'), atest = false; end
531 end
532 end
533 end
534 % </AlgoCode>
535 else
536 atest = false;
537 end
538
539 % Return a result structure
540 result = utp_prepare_result(atest, stest, dbstack, mfilename);
541 end % END UTP_05
542
543 %% UTP_06
544
545 % <TestDescription>
546 %
547 % Tests that the split method properly applies history.
548 %
549 % </TestDescription>
550 function result = utp_06
551
552 % <SyntaxDescription>
553 %
554 % Test that the result of applying the split method can be processed back.
555 %
556 % </SyntaxDescription>
557
558 try
559 % <SyntaxCode>
560 pl = plist('N', 3);
561 out = split(at1, pl);
562 mout = rebuild(out);
563 % </SyntaxCode>
564 stest = true;
565 catch err
566 disp(err.message)
567 stest = false;
568 end
569
570 % <AlgoDescription>
571 %
572 % 1) Check that the last entry in the history of 'out' corresponds to
573 % 'split'.
574 % 2) Check that the re-built object is the same object as the input.
575 %
576 % </AlgoDescription>
577
578 atest = true;
579 if stest
580 % <AlgoCode>
581 % Check the last step in the history of 'out'
582 if ~strcmp(out(1).hist.methodInfo.mname, 'split'), atest = false; end
583 if ~strcmp(out(2).hist.methodInfo.mname, 'split'), atest = false; end
584 if ~strcmp(out(3).hist.methodInfo.mname, 'split'), atest = false; end
585 % The rebuilt object must be the same as 'out'
586 if ~eq(mout, out, ple2), atest = false; end
587 % </AlgoCode>
588 else
589 atest = false;
590 end
591
592 % Return a result structure
593 result = utp_prepare_result(atest, stest, dbstack, mfilename);
594 end % END UTP_06
595
596 %% UTP_07
597
598 % <TestDescription>
599 %
600 % The split method can not modify the input AO.
601 %
602 % </TestDescription>
603 function result = utp_07
604
605 % <SyntaxDescription>
606 %
607 % The split method can not modify the input AO.
608 %
609 % </SyntaxDescription>
610
611 try
612 % <SyntaxCode>
613 pl = plist('N', 7);
614 amodi = ao(at1);
615 aeq = ao(at1);
616 out = aeq.split(pl);
617 amodi.split(pl);
618 stest = false;
619 % </SyntaxCode>
620 catch
621 stest = true;
622 end
623
624 % <AlgoDescription>
625 %
626 % 1) Nothind to do.
627 %
628 % </AlgoDescription>
629
630 atest = true;
631 if stest
632 % <AlgoCode>
633 % </AlgoCode>
634 else
635 atest = false;
636 end
637
638 % Return a result structure
639 result = utp_prepare_result(atest, stest, dbstack, mfilename);
640 end % END UTP_07
641
642 %% UTP_08
643
644 % <TestDescription>
645 %
646 % Test the shape of the output.
647 %
648 % </TestDescription>
649 function result = utp_08
650
651 % <SyntaxDescription>
652 %
653 % Test that the split method keeps the data shape of the input object.
654 % The input AO must be an AO with row data and an AO with column data.
655 %
656 % </SyntaxDescription>
657
658 try
659 % <SyntaxCode>
660 pl = plist('chunks', 3);
661 out1 = split(at5, pl);
662 out2 = split(at6, pl);
663 % </SyntaxCode>
664 stest = true;
665 catch err
666 disp(err.message)
667 stest = false;
668 end
669
670 % <AlgoDescription>
671 %
672 % 1) Check that the shape of the data doesn't change.
673 %
674 % </AlgoDescription>
675
676 atest = true;
677 if stest
678 % <AlgoCode>
679 % Check the shape of the output data
680 if size(out1(1).data.y,1) == 1, atest = false; end
681 if size(out1(2).data.y,1) == 1, atest = false; end
682 if size(out1(3).data.y,1) == 1, atest = false; end
683 if size(out2(1).data.y,2) == 1, atest = false; end
684 if size(out2(2).data.y,2) == 1, atest = false; end
685 if size(out2(3).data.y,2) == 1, atest = false; end
686 % </AlgoCode>
687 else
688 atest = false;
689 end
690
691 % Return a result structure
692 result = utp_prepare_result(atest, stest, dbstack, mfilename);
693 end % END UTP_08
694
695 %% UTP_09
696
697 % <TestDescription>
698 %
699 % Check that the split method pass back the output objects to a list of
700 % output variables or to a single variable.
701 %
702 % </TestDescription>
703 function result = utp_09
704
705 % <SyntaxDescription>
706 %
707 % Call the method with a list of output variables and with a single
708 % output variable. Additionaly check that the rebuild method works on
709 % the output.
710 %
711 % </SyntaxDescription>
712
713 try
714 % <SyntaxCode>
715 pl = plist('chunks', 2);
716 [o1, o2] = split(at5, pl);
717 o3 = split(at5, pl);
718 mout1 = rebuild(o1);
719 mout2 = rebuild(o2);
720 mout3 = rebuild(o3);
721 % </SyntaxCode>
722 stest = true;
723 catch err
724 disp(err.message)
725 stest = false;
726 end
727
728 % <AlgoDescription>
729 %
730 % 1) Check that the output contains the right number of objects
731 % 2) Check that the 'rebuild' method produces the same object as 'out'.
732 %
733 % </AlgoDescription>
734
735 atest = true;
736 if stest
737 % <AlgoCode>
738 % Check the number of outputs
739 if numel(o1) ~=1, atest = false; end
740 if numel(o2) ~=1, atest = false; end
741 if numel(o3) ~=2, atest = false; end
742 % Check the rebuilding of the object
743 if ~eq(o1, mout1, ple2), atest = false; end
744 if ~eq(o2, mout2, ple2), atest = false; end
745 if ~eq(o3, mout3, ple2), atest = false; end
746 % </AlgoCode>
747 else
748 atest = false;
749 end
750
751 % Return a result structure
752 result = utp_prepare_result(atest, stest, dbstack, mfilename);
753 end % END UTP_09
754
755 %% UTP_10
756
757 % <TestDescription>
758 %
759 % Check that the split method accepts both key-words 'N' and 'chunks'.
760 %
761 % </TestDescription>
762 function result = utp_10
763
764 % <SyntaxDescription>
765 %
766 % Check that the split method accepts both key-words 'N' and 'chunks'.
767 %
768 % </SyntaxDescription>
769
770 try
771 % <SyntaxCode>
772 N = 4;
773 plC = plist('chunks', N);
774 plN = plist('N', N);
775 outC = split(at5, plC);
776 outN = split(at5, plN);
777 moutC = rebuild(outC);
778 moutN = rebuild(outN);
779 % </SyntaxCode>
780 stest = true;
781 catch err
782 disp(err.message)
783 stest = false;
784 end
785
786 % <AlgoDescription>
787 %
788 % 1) Check that the number of outputs
789 % 2) Check that the 'rebuild' method produces the same object as 'out'.
790 %
791 % </AlgoDescription>
792
793 atest = true;
794 if stest
795 % <AlgoCode>
796 % Check the number of outputs
797 if numel(outC) ~= 4, atest = false; end
798 if numel(outN) ~= 4, atest = false; end
799 % Check that 'outN' and 'outC' are the same
800 if ~eq(outN, outC,ple2), atest = false; end
801 % Check the rebuilding of the object
802 if ~eq(outC, moutC, ple2), atest = false; end
803 if ~eq(outN, moutN, ple2), atest = false; end
804 % </AlgoCode>
805 else
806 atest = false;
807 end
808
809 % Return a result structure
810 result = utp_prepare_result(atest, stest, dbstack, mfilename);
811 end % END UTP_10
812
813 %% UTP_12
814
815 % <TestDescription>
816 %
817 % Tests that the split method works also split 'dx' and 'dy'.
818 %
819 % </TestDescription>
820 function result = utp_12
821
822 % <SyntaxDescription>
823 %
824 % Tests that the split method works also split 'dx' and 'dy'.
825 %
826 % </SyntaxDescription>
827
828 try
829 % <SyntaxCode>
830 N = 4;
831 pl = plist('chunks', N);
832 out = split(atmat, pl);
833 % </SyntaxCode>
834 stest = true;
835 catch err
836 disp(err.message)
837 stest = false;
838 end
839
840 % <AlgoDescription>
841 %
842 % 1) Check that the number of outputs
843 % 2) Check that each output AO contains the correct data.
844 %
845 % </AlgoDescription>
846
847 atest = true;
848 TOL = 1e-14;
849 if stest
850 % <AlgoCode>
851 % Check we have the correct number of outputs
852 if numel(out) ~= numel(atmat) * N, atest = false; end
853
854 % Check each output
855 for kk=1:numel(atmat)
856
857 ff = floor(length(atmat(kk).y)/N);
858 is = 1:ff:length(atmat(kk).y);
859 ie = ff:ff:length(atmat(kk).y);
860 idx = sort([is(1:N) ie(1:N)]);
861 idx(end) = length(atmat(kk).y);
862
863 for jj = 1:N
864
865 % Get reference values
866 x = atmat(kk).x;
867 y = atmat(kk).y;
868 % Get and normalize for tsdata the values
869 if isa(atmat(kk).data, 'tsdata')
870 t0off = (out((kk-1)*N+jj).t0.utc_epoch_milli - atmat(kk).t0.utc_epoch_milli)/1e3;
871 ox = out((kk-1)*N+jj).x + t0off;
872 else
873 ox = out((kk-1)*N+jj).x;
874 end
875 oy = out((kk-1)*N+jj).y;
876 % Compute the range
877 range = idx(jj*2-1):idx(jj*2);
878 % Check data
879 if ~isa(atmat(kk).data, 'cdata')
880 if any(abs(ox - x(range)) > TOL), atest = false; end
881 if ~isequal(oy, y(range)), atest = false; end
882 else
883 if ~isequal(oy, y(range).'), atest = false; end
884 end
885 end
886 end
887 % </AlgoCode>
888 else
889 atest = false;
890 end
891
892 % Return a result structure
893 result = utp_prepare_result(atest, stest, dbstack, mfilename);
894 end % END UTP_12
895
896
897 %% UTP_13
898
899 % <TestDescription>
900 %
901 % Check that the split method ignores the samples which doesn't fit.
902 %
903 % </TestDescription>
904 function result = utp_13
905
906 % <SyntaxDescription>
907 %
908 % Check that the split method ignores the samples which doesn't fit.
909 % Use for this test the key-word 'match'
910 %
911 % </SyntaxDescription>
912
913 try
914 % <SyntaxCode>
915 N = 7;
916 pl = plist('chunks', N, 'match', false);
917 out = split(at5, pl);
918 mout = rebuild(out);
919 % </SyntaxCode>
920 stest = true;
921 catch err
922 disp(err.message)
923 stest = false;
924 end
925
926 % <AlgoDescription>
927 %
928 % 1) Check that the number of outputs
929 % 2) Check that the 'rebuild' method produces the same object as 'out'.
930 %
931 % </AlgoDescription>
932
933 atest = true;
934 TOL = 1e-14;
935 if stest
936 % <AlgoCode>
937 % Check the number of outputs
938 if numel(out) ~= N, atest = false; end
939 % Check the output
940 ff = floor(length(at5.y)/N);
941 is = 1:ff:length(at5.y);
942 ie = ff:ff:length(at5.y);
943 idx = sort([is(1:N) ie(1:N)]);
944
945 for jj = 1:N
946
947 % Get reference values
948 x = at5.x;
949 y = at5.y;
950 % Get and normalize for tsdata the values
951 ox = out(jj).x + (out(jj).t0.utc_epoch_milli - at5.t0.utc_epoch_milli)/1000;
952 oy = out(jj).y;
953 % Compute the range
954 range = idx(jj*2-1):idx(jj*2);
955 % Check data
956 if any(abs(ox - x(range)) > TOL), atest = false; end
957 if ~isequal(oy, y(range)), atest = false; end
958 end
959
960 % Check the rebuilding of the object
961 if ~eq(out, mout, ple2), atest = false; end
962 % </AlgoCode>
963 else
964 atest = false;
965 end
966
967 % Return a result structure
968 result = utp_prepare_result(atest, stest, dbstack, mfilename);
969 end % END UTP_13
970
971 %% UTP_15
972
973 % <TestDescription>
974 %
975 % Check that the split method works with notequal sampled data.
976 %
977 % </TestDescription>
978 function result = utp_15
979
980 % <SyntaxDescription>
981 %
982 % Check that the split method works with notequal sampled data.
983 %
984 % </SyntaxDescription>
985
986 try
987 % <SyntaxCode>
988 xOffset = 60;
989 y = randn(2e3,1);
990 x = [1:150 152:400 402:1019 1021:1999];
991 y = y(x);
992
993 a1 = ao(plist('xvals', x, 'yvals', y, 'fs', 1, 'yunits', 'N'));
994 a1.setXY(x + xOffset, y);
995 a1.setT0(time('2009-11-03 18:00:00.000'));
996
997 N = 5;
998
999 pl1 = plist(...
1000 'chunks', N, ...
1001 'match', false);
1002 pl2 = plist(...
1003 'chunks', N, ...
1004 'match', true);
1005 out1 = split(a1, pl1);
1006 out2 = split(a1, pl2);
1007 mout1 = rebuild(out1);
1008 mout2 = rebuild(out2);
1009 % </SyntaxCode>
1010 stest = true;
1011 catch err
1012 disp(err.message)
1013 stest = false;
1014 end
1015
1016 % <AlgoDescription>
1017 %
1018 % 1) Check the outputs
1019 % 2) Check that the 'rebuild' method produces the same object as 'out'.
1020 %
1021 % </AlgoDescription>
1022
1023 atest = true;
1024 if stest
1025 % <AlgoCode>
1026 % Compute the starting point of the first data sample.
1027 firstX = 1:floor(a1.len/N):a1.len;
1028 firstX = a1.x(firstX(1:N));
1029
1030 % Check the number of outputs
1031 if numel(out1) ~= N, atest = false; end
1032 if numel(out2) ~= N, atest = false; end
1033
1034 for jj = 1:numel(out1)
1035 % Check t0
1036 if ~isequal(out1(jj).t0, a1.t0), atest = false; end
1037 % Check first x value
1038 if ~isequal(out1(jj).x(1), firstX(jj)), atest = false; end
1039 if ~isequal(out2(jj).x(1), firstX(jj)), atest = false; end
1040 % Check the rebuilding of the object
1041 if ~eq(out1(jj), mout1(jj), ple2), atest = false; end
1042 if ~eq(out2(jj), mout2(jj), ple2), atest = false; end
1043 end
1044
1045 % Check length
1046 if ~isequal(sum(out2.len), a1.len), atest = false; end
1047
1048 % </AlgoCode>
1049 else
1050 atest = false;
1051 end
1052
1053 % Return a result structure
1054 result = utp_prepare_result(atest, stest, dbstack, mfilename);
1055 end % END UTP_15
1056 end