comparison testing/utp_1.1/utps/ao/utp_ao_average.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_AVERAGE a set of UTPs for the ao/average method
2 %
3 % M Hueller 24-02-1
4 %
5 % $Id: utp_ao_average.m,v 1.2 2011/04/17 15:46:21 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The average method of the ao class averages aos point-by-point
11 %
12 % </MethodDescription>
13
14 function results = utp_ao_average(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'ao';
21 mthd = 'average';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test AOs
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
30
31 % Exception list for the UTPs:
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
33
34 % Set the same y-units for the test AOs
35 at1.setYunits('uHz');
36 at2.setYunits('uHz');
37 at3.setYunits('uHz');
38 at4.setYunits('uHz');
39 at5.setYunits('uHz');
40 at6.setYunits('uHz');
41
42 % Run the tests
43 results = [results utp_01]; % getInfo call
44 results = [results utp_02]; % Vector input
45 results = [results utp_03]; % Matrix input
46 results = [results utp_04]; % List input
47 results = [results utp_05]; % Test with mixed input
48 results = [results utp_06(mthd, at1, at5, ple2)]; % Test history is working
49 results = [results utp_07]; % Test the modify call does not work
50 results = [results utp_08]; % Test input data shape == output data shape
51 results = [results utp_18]; % Test with single input
52
53
54 disp('Done.');
55 disp('******************************************************');
56
57 elseif nargin == 1 % Check for UTP functions
58 if strcmp(varargin{1}, 'isutp')
59 results = 1;
60 else
61 results = 0;
62 end
63 else
64 error('### Incorrect inputs')
65 end
66
67 %% UTP_01
68
69 % <TestDescription>
70 %
71 % Tests that the getInfo call works for this method.
72 %
73 % </TestDescription>
74 function result = utp_01
75
76
77 % <SyntaxDescription>
78 %
79 % Test that the getInfo call works for no sets, all sets, and each set
80 % individually.
81 %
82 % </SyntaxDescription>
83
84 try
85 % <SyntaxCode>
86 % Call for no sets
87 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
88 % Call for all sets
89 io(2) = eval([class '.getInfo(''' mthd ''')']);
90 % Call for each set
91 for kk=1:numel(io(2).sets)
92 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
93 end
94 % </SyntaxCode>
95 stest = true;
96 catch err
97 disp(err.message)
98 stest = false;
99 end
100
101 % <AlgoDescription>
102 %
103 % 1) Check that getInfo call returned an minfo object in all cases.
104 % 2) Check that all plists have the correct parameters.
105 %
106 % </AlgoDescription>
107
108 atest = true;
109 if stest
110 % <AlgoCode>
111 % check we have minfo objects
112 if isa(io, 'minfo')
113 % SET 'None'
114 if ~isempty(io(1).sets), atest = false; end
115 if ~isempty(io(1).plists), atest = false; end
116 % Check all Sets
117 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
118 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
119 % SET 'Default'
120 if io(3).plists.nparams ~= 0, atest = false; end
121 % Check key
122 % Check default value
123 % Check options
124 end
125 % </AlgoCode>
126 else
127 atest = false;
128 end
129
130 % Return a result structure
131 result = utp_prepare_result(atest, stest, dbstack, mfilename);
132 end % END UTP_01
133
134 %% UTP_02
135
136 % <TestDescription>
137 %
138 % Tests that the average method works with a vector of AOs as input.
139 %
140 % </TestDescription>
141 function result = utp_02
142
143 % <SyntaxDescription>
144 %
145 % Tests that the average method works with a vector of AOs as input.
146 %
147 % </SyntaxDescription>
148
149 try
150 % <SyntaxCode>
151 % Pick units and prefix from those supported
152 unit_list = unit.supportedUnits;
153 % remove the first empty unit '' from the list, because then is it
154 % possible that we add a prefix to an empty unit
155 unit_list = unit_list(2:end);
156 prefix_list = unit.supportedPrefixes;
157 u = unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]);
158
159 % tsdata: settings
160 fs = 3;
161 ts_pl = plist('fs', fs, 'nsecs', 30, 'waveform', 'sine wave', 'f', 10, 'yunits', u);
162 ts_a1 = ao(ts_pl);
163 ts_a2 = ao(ts_pl);
164 ts_a3 = ao(ts_pl);
165 ts_a1.setT0('14:00:00');
166 ts_a2.setT0('14:00:05');
167 ts_a3.setT0('14:00:10');
168
169 % tsdata: call the method with a vector of inputs
170 ts_out = average([ts_a1, ts_a2, ts_a3]);
171
172 % fsdata: settings
173 fs_pl = plist('fsfcn', '1./f.^2', 'scale', 'lin', 'nf', 100, 'yunits', u);
174 fs_a1 = ao(fs_pl);
175 fs_a2 = 2*ao(fs_pl);
176
177 % tsdata: call the method with a vector of inputs
178 fs_out = average([fs_a1, fs_a2]);
179
180 % xydata: settings
181 xy_pl = plist('X', [1:50,52:2:100,110:10:1000], 'xyfcn', 'log(x)', 'yunits', u);
182 xy_a1 = ao(xy_pl);
183 xy_a2 = ao(xy_pl.pset('xyfcn', 'log10(x)'));
184 xy_a3 = ao(xy_pl.pset('xyfcn', 'exp(-x)'));
185
186 % xydata: call the method with a vector of inputs
187 xy_out = average([xy_a1, xy_a2, xy_a3]);
188
189 % cdata: settings
190 c_pl = plist('yunits', u);
191 c_a1 = ao([1 2 3], c_pl);
192 c_a2 = ao([4 3 2], c_pl);
193 c_a3 = ao([7 4 9], c_pl);
194 c_a4 = ao([-4 -1 2], c_pl);
195
196 % cdata: call the method with a vector of inputs
197 c_out = average([c_a1, c_a2, c_a3, c_a4]);
198
199 % Rebuild the objects
200 ts_mout = rebuild(ts_out);
201 fs_mout = rebuild(fs_out);
202 xy_mout = rebuild(xy_out);
203 c_mout = rebuild(c_out);
204
205 % </SyntaxCode>
206 stest = true;
207 catch err
208 disp(err.message)
209 stest = false;
210 end
211
212 % <AlgoDescription>
213 %
214 % 1) Check that the outputs have exactly one AO
215 % 2) Check that the outputs have the correct data.
216 % 3) Check the rebuilt objects
217 %
218 % </AlgoDescription>
219
220 atest = true;
221
222 if stest
223 % <AlgoCode>
224 % Check that the output is exactly one AO
225 if numel(ts_out) ~= 1, atest = false; end
226 if numel(fs_out) ~= 1, atest = false; end
227 if numel(xy_out) ~= 1, atest = false; end
228 if numel(c_out) ~= 1, atest = false; end
229 if ~isa(ts_out, 'ao'), atest = false; end
230 if ~isa(fs_out, 'ao'), atest = false; end
231 if ~isa(xy_out, 'ao'), atest = false; end
232 if ~isa(c_out, 'ao'), atest = false; end
233
234 % Check output data: x
235 if ~isequal(ts_out.x, ts_a1.x), atest = false; end
236 if ~isequal(fs_out.x, fs_a1.x), atest = false; end
237 if ~isequal(xy_out.x, xy_a1.x), atest = false; end
238
239 % Check output data: t0
240 if ~isequal(ts_out.t0, ts_a1.t0), atest = false; end
241
242 % Check output data: y
243 ts_data_in = [ts_a1.y ts_a2.y ts_a3.y];
244 if ~isequal(ts_out.y, mean(ts_data_in, 2)), atest = false; end
245 fs_data_in = [fs_a1.y fs_a2.y];
246 if ~isequal(fs_out.y, mean(fs_data_in, 2)), atest = false; end
247 xy_data_in = [xy_a1.y xy_a2.y xy_a3.y];
248 if ~isequal(xy_out.y, mean(xy_data_in, 2)), atest = false; end
249 c_data_in = [c_a1.y c_a2.y c_a3.y c_a4.y];
250 if ~isequal(c_out.y, mean(c_data_in, 2)), atest = false; end
251
252 % Check output data: dy
253 if ~isequal(ts_out.dy, std(ts_data_in, 0, 2)/sqrt(3)), atest = false; end
254 if ~isequal(fs_out.dy, std(fs_data_in, 0, 2)/sqrt(2)), atest = false; end
255 if ~isequal(xy_out.dy, std(xy_data_in, 0, 2)/sqrt(3)), atest = false; end
256 if ~isequal(c_out.dy, std(c_data_in, 0, 2)/sqrt(4)), atest = false; end
257
258 % Check output data: xunits
259 if ~isequal(ts_out.xunits, ts_a1.xunits), atest = false; end
260 if ~isequal(fs_out.xunits, fs_a1.xunits), atest = false; end
261 if ~isequal(xy_out.xunits, xy_a1.xunits), atest = false; end
262
263 % Check output data: yunits
264 if ~isequal(ts_out.yunits, ts_a1.yunits), atest = false; end
265 if ~isequal(fs_out.yunits, fs_a1.yunits), atest = false; end
266 if ~isequal(xy_out.yunits, xy_a1.yunits), atest = false; end
267 if ~isequal(c_out.yunits, c_a1.yunits), atest = false; end
268
269 % Check the re-built objects
270 if ~eq(ts_out, ts_mout, ple2), atest = false; end
271 if ~eq(fs_out, fs_mout, ple2), atest = false; end
272 if ~eq(xy_out, xy_mout, ple2), atest = false; end
273 if ~eq(c_out, c_mout, ple2), atest = false; end
274
275 % </AlgoCode>
276 else
277 atest = false;
278 end
279
280 % Return a result structure
281 result = utp_prepare_result(atest, stest, dbstack, mfilename);
282 end % END UTP_02
283
284 %% UTP_03
285
286 % <TestDescription>
287 %
288 % Tests that the average method works with a matrix of AOs as input.
289 %
290 % </TestDescription>
291 function result = utp_03
292
293 % <SyntaxDescription>
294 %
295 % Tests that the average method works with a matrix of AOs as input.
296 %
297 % </SyntaxDescription>
298
299 try
300 % <SyntaxCode>
301 % Pick units and prefix from those supported
302 unit_list = unit.supportedUnits;
303 % remove the first empty unit '' from the list, because then is it
304 % possible that we add a prefix to an empty unit
305 unit_list = unit_list(2:end);
306 prefix_list = unit.supportedPrefixes;
307 u = unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]);
308
309 % tsdata: settings
310 fs = 3;
311 ts_pl = plist('fs', fs, 'nsecs', 30, 'waveform', 'sine wave', 'f', 10, 'yunits', u);
312 ts_a1 = ao(ts_pl);
313 ts_a2 = ao(ts_pl);
314 ts_a3 = ao(ts_pl);
315 ts_a1.setT0('14:00:00');
316 ts_a2.setT0('14:00:05');
317 ts_a3.setT0('14:00:10');
318
319 % tsdata: call the method with a list of inputs
320 ts_out = average([ts_a1, ts_a2, ts_a3; ts_a1, ts_a2, ts_a3]);
321
322 % tsdata: settings
323 fs_pl = plist('fsfcn', '1./f.^2', 'scale', 'lin', 'nf', 100, 'yunits', u);
324 fs_a1 = ao(fs_pl);
325 fs_a2 = 2*ao(fs_pl);
326
327 % fsdata: call the method with a list of inputs
328 fs_out = average([fs_a1, fs_a2; fs_a1, fs_a2]);
329
330 % xydata: settings
331 xy_pl = plist('X', [1:50,52:2:100,110:10:1000], 'xyfcn', 'log(x)', 'yunits', u);
332 xy_a1 = ao(xy_pl);
333 xy_a2 = ao(xy_pl.pset('xyfcn', 'log10(x)'));
334 xy_a3 = ao(xy_pl.pset('xyfcn', 'exp(-x)'));
335
336 % xydata: call the method with a list of inputs
337 xy_out = average([xy_a1, xy_a2, xy_a3; xy_a1, xy_a2, xy_a3]);
338
339 % cdata: settings
340 c_pl = plist('yunits', u);
341 c_a1 = ao([1 2 3], c_pl);
342 c_a2 = ao([4 3 2], c_pl);
343 c_a3 = ao([7 4 9], c_pl);
344 c_a4 = ao([-4 -1 2], c_pl);
345
346 % cdata: call the method with a list of inputs
347 c_out = average([c_a1, c_a2, c_a3, c_a4; c_a1, c_a2, c_a3, c_a4]);
348
349 % Rebuild the objects
350 ts_mout = rebuild(ts_out);
351 fs_mout = rebuild(fs_out);
352 xy_mout = rebuild(xy_out);
353 c_mout = rebuild(c_out);
354
355 % </SyntaxCode>
356 stest = true;
357 catch err
358 disp(err.message)
359 stest = false;
360 end
361
362 % <AlgoDescription>
363 %
364 % 1) Check that the outputs have exactly one AO
365 % 2) Check that the outputs have the correct data.
366 % 3) Check the rebuilt objects
367 %
368 % </AlgoDescription>
369
370 TOL = 1e-15;
371 atest = true;
372
373 if stest
374 % <AlgoCode>
375 % Check that the output is exactly one AO
376 if numel(ts_out) ~= 1, atest = false; end
377 if numel(fs_out) ~= 1, atest = false; end
378 if numel(xy_out) ~= 1, atest = false; end
379 if numel(c_out) ~= 1, atest = false; end
380 if ~isa(ts_out, 'ao'), atest = false; end
381 if ~isa(fs_out, 'ao'), atest = false; end
382 if ~isa(xy_out, 'ao'), atest = false; end
383 if ~isa(c_out, 'ao'), atest = false; end
384
385 % Check output data: x
386 if ~isequal(ts_out.x, ts_a1.x), atest = false; end
387 if ~isequal(fs_out.x, fs_a1.x), atest = false; end
388 if ~isequal(xy_out.x, xy_a1.x), atest = false; end
389
390 % Check output data: t0
391 if ~isequal(ts_out.t0, ts_a1.t0), atest = false; end
392
393 % Check output data: y
394 ts_data_in = [ts_a1.y ts_a2.y ts_a3.y ts_a1.y ts_a2.y ts_a3.y];
395 if ~isequal(ts_out.y, mean(ts_data_in, 2)), atest = false; end
396 fs_data_in = [fs_a1.y fs_a2.y fs_a1.y fs_a2.y];
397 if ~isequal(fs_out.y, mean(fs_data_in, 2)), atest = false; end
398 xy_data_in = [xy_a1.y xy_a2.y xy_a3.y xy_a1.y xy_a2.y xy_a3.y];
399 if any(abs(xy_out.y - mean(xy_data_in, 2)) > TOL), atest = false; end
400 c_data_in = [c_a1.y c_a2.y c_a3.y c_a4.y c_a1.y c_a2.y c_a3.y c_a4.y];
401 if ~isequal(c_out.y, mean(c_data_in, 2)), atest = false; end
402
403 % Check output data: dy
404 if ~isequal(ts_out.dy, std(ts_data_in, 0, 2)/sqrt(6)), atest = false; end
405 if any(abs(fs_out.dy - std(fs_data_in, 0, 2)/sqrt(4)) > TOL), atest = false; end
406 if any(abs(xy_out.dy - std(xy_data_in, 0, 2)/sqrt(6)) > TOL), atest = false; end
407 if ~isequal(c_out.dy, std(c_data_in, 0, 2)/sqrt(8)), atest = false; end
408
409 % Check output data: xunits
410 if ~isequal(ts_out.xunits, ts_a1.xunits), atest = false; end
411 if ~isequal(fs_out.xunits, fs_a1.xunits), atest = false; end
412 if ~isequal(xy_out.xunits, xy_a1.xunits), atest = false; end
413
414 % Check output data: yunits
415 if ~isequal(ts_out.yunits, ts_a1.yunits), atest = false; end
416 if ~isequal(fs_out.yunits, fs_a1.yunits), atest = false; end
417 if ~isequal(xy_out.yunits, xy_a1.yunits), atest = false; end
418 if ~isequal(c_out.yunits, c_a1.yunits), atest = false; end
419
420 % Check the re-built objects
421 if ~eq(ts_out, ts_mout, ple2), atest = false; end
422 if ~eq(fs_out, fs_mout, ple2), atest = false; end
423 if ~eq(xy_out, xy_mout, ple2), atest = false; end
424 if ~eq(c_out, c_mout, ple2), atest = false; end
425
426 % </AlgoCode>
427 else
428 atest = false;
429 end
430
431 % Return a result structure
432 result = utp_prepare_result(atest, stest, dbstack, mfilename);
433 end % END UTP_03
434
435 %% UTP_04
436
437 % <TestDescription>
438 %
439 % Tests that the average method works with a list of AOs as input.
440 %
441 % </TestDescription>
442 function result = utp_04
443
444 % <SyntaxDescription>
445 %
446 % Tests that the average method works with a list of AOs as input.
447 %
448 % </SyntaxDescription>
449
450 try
451 % <SyntaxCode>
452 % Pick units and prefix from those supported
453 unit_list = unit.supportedUnits;
454 % remove the first empty unit '' from the list, because then is it
455 % possible that we add a prefix to an empty unit
456 unit_list = unit_list(2:end);
457 prefix_list = unit.supportedPrefixes;
458 u = unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]);
459
460 % tsdata: settings
461 fs = 3;
462 ts_pl = plist('fs', fs, 'nsecs', 30, 'waveform', 'sine wave', 'f', 10, 'yunits', u);
463 ts_a1 = ao(ts_pl);
464 ts_a2 = ao(ts_pl);
465 ts_a3 = ao(ts_pl);
466 ts_a1.setT0('14:00:00');
467 ts_a2.setT0('14:00:05');
468 ts_a3.setT0('14:00:10');
469
470 % tsdata: call the method with a list of inputs
471 ts_out = average(ts_a1, ts_a2, ts_a3);
472
473 % fsdata: settings
474 fs_pl = plist('fsfcn', '1./f.^2', 'scale', 'lin', 'nf', 100, 'yunits', u);
475 fs_a1 = ao(fs_pl);
476 fs_a2 = 2*ao(fs_pl);
477
478 % fsdata: call the method with a list of inputs
479 fs_out = average(fs_a1, fs_a2);
480
481 % xydata: settings
482 xy_pl = plist('X', [1:50,52:2:100,110:10:1000], 'xyfcn', 'log(x)', 'yunits', u);
483 xy_a1 = ao(xy_pl);
484 xy_a2 = ao(xy_pl.pset('xyfcn', 'log10(x)'));
485 xy_a3 = ao(xy_pl.pset('xyfcn', 'exp(-x)'));
486
487 % xydata: call the method with a list of inputs
488 xy_out = average(xy_a1, xy_a2, xy_a3);
489
490 % cdata: settings
491 c_pl = plist('yunits', u);
492 c_a1 = ao([1 2 3], c_pl);
493 c_a2 = ao([4 3 2], c_pl);
494 c_a3 = ao([7 4 9], c_pl);
495 c_a4 = ao([-4 -1 2], c_pl);
496
497 % cdata: call the method with a list of inputs
498 c_out = average(c_a1, c_a2, c_a3, c_a4);
499
500 % Rebuild the objects
501 ts_mout = rebuild(ts_out);
502 fs_mout = rebuild(fs_out);
503 xy_mout = rebuild(xy_out);
504 c_mout = rebuild(c_out);
505
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 outputs have exactly one AO
516 % 2) Check that the outputs have the correct data.
517 % 3) Check the rebuilt objects
518 %
519 % </AlgoDescription>
520
521 atest = true;
522
523 if stest
524 % <AlgoCode>
525 % Check that the output is exactly one AO
526 if numel(ts_out) ~= 1, atest = false; end
527 if numel(fs_out) ~= 1, atest = false; end
528 if numel(xy_out) ~= 1, atest = false; end
529 if numel(c_out) ~= 1, atest = false; end
530 if ~isa(ts_out, 'ao'), atest = false; end
531 if ~isa(fs_out, 'ao'), atest = false; end
532 if ~isa(xy_out, 'ao'), atest = false; end
533 if ~isa(c_out, 'ao'), atest = false; end
534
535
536 % Check output data: x
537 if ~isequal(ts_out.x, ts_a1.x), atest = false; end
538 if ~isequal(fs_out.x, fs_a1.x), atest = false; end
539 if ~isequal(xy_out.x, xy_a1.x), atest = false; end
540
541 % Check output data: t0
542 if ~isequal(ts_out.t0, ts_a1.t0), atest = false; end
543
544 % Check output data: y
545 ts_data_in = [ts_a1.y ts_a2.y ts_a3.y];
546 if ~isequal(ts_out.y, mean(ts_data_in, 2)), atest = false; end
547 fs_data_in = [fs_a1.y fs_a2.y];
548 if ~isequal(fs_out.y, mean(fs_data_in, 2)), atest = false; end
549 xy_data_in = [xy_a1.y xy_a2.y xy_a3.y];
550 if ~isequal(xy_out.y, mean(xy_data_in, 2)), atest = false; end
551 c_data_in = [c_a1.y c_a2.y c_a3.y c_a4.y];
552 if ~isequal(c_out.y, mean(c_data_in, 2)), atest = false; end
553
554 % Check output data: dy
555 if ~isequal(ts_out.dy, std(ts_data_in, 0, 2)/sqrt(3)), atest = false; end
556 if ~isequal(fs_out.dy, std(fs_data_in, 0, 2)/sqrt(2)), atest = false; end
557 if ~isequal(xy_out.dy, std(xy_data_in, 0, 2)/sqrt(3)), atest = false; end
558 if ~isequal(c_out.dy, std(c_data_in, 0, 2)/sqrt(4)), atest = false; end
559
560 % Check output data: xunits
561 if ~isequal(ts_out.xunits, ts_a1.xunits), atest = false; end
562 if ~isequal(fs_out.xunits, fs_a1.xunits), atest = false; end
563 if ~isequal(xy_out.xunits, xy_a1.xunits), atest = false; end
564
565 % Check output data: yunits
566 if ~isequal(ts_out.yunits, ts_a1.yunits), atest = false; end
567 if ~isequal(fs_out.yunits, fs_a1.yunits), atest = false; end
568 if ~isequal(xy_out.yunits, xy_a1.yunits), atest = false; end
569 if ~isequal(c_out.yunits, c_a1.yunits), atest = false; end
570
571 % Check the re-built objects
572 if ~eq(ts_out, ts_mout, ple2), atest = false; end
573 if ~eq(fs_out, fs_mout, ple2), atest = false; end
574 if ~eq(xy_out, xy_mout, ple2), atest = false; end
575 if ~eq(c_out, c_mout, ple2), atest = false; end
576
577 % </AlgoCode>
578 else
579 atest = false;
580 end
581
582 % Return a result structure
583 result = utp_prepare_result(atest, stest, dbstack, mfilename);
584 end % END UTP_04
585
586 %% UTP_05
587
588 % <TestDescription>
589 %
590 % Tests that the average method works with a mix of different shaped AOs as
591 % input.
592 %
593 % </TestDescription>
594 function result = utp_05
595
596 % <SyntaxDescription>
597 %
598 % Tests that the average method works with a mix of different shaped AOs as
599 % input.
600 %
601 % </SyntaxDescription>
602
603 try
604 % <SyntaxCode>
605 fs = .3;
606 pl = plist('fs', fs, 'nsecs', 300, 'waveform', 'sine wave', 'f', .1);
607 a1 = ao(pl);
608 a2 = ao(pl);
609 a3 = ao(pl);
610 a4 = ao(pl);
611 a5 = ao(pl);
612 a6 = ao(pl);
613 a1.setT0('14:00:20');
614 a2.setT0('14:01:40');
615 a3.setT0('14:02:00');
616 a4.setT0('14:00:00');
617 a5.setT0('14:01:20');
618 a6.setT0('14:00:40');
619 out = average(a1, [a2, a3; a4, a5], [a6;a1]);
620 % Rebuild the object
621 mout = rebuild(out);
622
623 % </SyntaxCode>
624 stest = true;
625 catch err
626 disp(err.message)
627 stest = false;
628 end
629
630 % <AlgoDescription>
631 %
632 % 1) Check that the output is exact one AO
633 % 2) Check that the output have the correct data.
634 %
635 % </AlgoDescription>
636
637 atest = true;
638 aoin = [a1, reshape([a2, a3; a4, a5], 1, []), a6, a1];
639 if stest
640 % <AlgoCode>
641 % Check that the output is exact one AO
642 if numel(out) ~= 1, atest = false; end
643 if ~isa(out, 'ao'), atest = false; end
644
645 % Check output data: x
646 if ~isequal(out.x, a1.x), atest = false; end
647
648 % Check output data: t0
649 if ~isequal(out.t0, a1.t0), atest = false; end
650
651 % Check output data: y
652 data_in = [aoin(:).y];
653 if ~isequal(out.y, mean(data_in, 2)), atest = false; end
654
655 % Check output data: dy
656 if ~isequal(out.dy, std(data_in, 0, 2)/sqrt(7)), atest = false; end
657
658 % Check output data: xunits
659 if ~isequal(out.xunits, a1.xunits), atest = false; end
660
661 % Check output data: yunits
662 if ~isequal(out.yunits, a1.yunits), atest = false; end
663
664 % Check the re-built object
665 if ~eq(out, mout, ple2), atest = false; end
666
667 % </AlgoCode>
668 else
669 atest = false;
670 end
671
672 % Return a result structure
673 result = utp_prepare_result(atest, stest, dbstack, mfilename);
674 end % END UTP_05
675
676
677 %% UTP_07
678
679 % <TestDescription>
680 %
681 % Tests that the average method cannot modify the input AO.
682 % The method must throw an error for the modifier call.
683 %
684 % </TestDescription>
685 function result = utp_07
686
687 % <SyntaxDescription>
688 %
689 % Test that the average method cannot modify the input AO by calling with
690 % no output
691 %
692 % </SyntaxDescription>
693
694 try
695 % <SyntaxCode>
696 % prepare one ao to work with
697 fs = 3;
698 pl = plist('fs', fs, 'nsecs', 30, 'waveform', 'sine wave', 'f', 10);
699 a1 = ao(pl);
700 a2 = ao(pl);
701
702 % modify a1
703 a1.average(a2);
704 % </SyntaxCode>
705 stest = false;
706 catch
707 stest = true;
708 end
709
710 % <AlgoDescription>
711 %
712 % 1) Nothing to check.
713 %
714 % </AlgoDescription>
715
716 atest = true;
717 if stest
718 % <AlgoCode>
719 % </AlgoCode>
720 else
721 atest = false;
722 end
723
724 % Return a result structure
725 result = utp_prepare_result(atest, stest, dbstack, mfilename);
726 end % END UTP_07
727
728 %% UTP_08
729
730 % <TestDescription>
731 %
732 % Test the shape of the output.
733 %
734 % </TestDescription>
735 function result = utp_08
736
737 % <SyntaxDescription>
738 %
739 % Test that the average method keeps the data shape of the input
740 % object. The input AO must be an AO with row data and an AO with
741 % column data.
742 %
743 % </SyntaxDescription>
744
745 try
746 % <SyntaxCode>
747 fs = 3;
748 pl = plist('fs', fs, 'nsecs', 30, 'waveform', 'sine wave', 'f', 10);
749 a1 = ao(pl);
750 a2 = ao(pl);
751 a2 = a2.';
752 a1.setT0('14:00:05');
753 a2.setT0('14:00:00');
754 out1 = average(a1, a2);
755 out2 = average(a2, a1);
756 % </SyntaxCode>
757 stest = true;
758 catch err
759 disp(err.message)
760 stest = false;
761 end
762
763 % <AlgoDescription>
764 %
765 % 1) Check that the shape of the data doesn't change.
766 %
767 % </AlgoDescription>
768
769 atest = true;
770 if stest
771 % <AlgoCode>
772 % Check the shape of the output data
773 if size(out1.data.y,1) == 1, atest = false; end
774 if size(out2.data.y,2) == 1, atest = false; end
775
776 % Check the output data: y values
777 if out1.data.y ~= out2.data.y', atest = false; end
778
779 % Check the output data: y uncertanties
780 if out1.data.dy ~= out2.data.dy', atest = false; end
781
782 % </AlgoCode>
783 else
784 atest = false;
785 end
786
787 % Return a result structure
788 result = utp_prepare_result(atest, stest, dbstack, mfilename);
789 end % END UTP_08
790
791 %% UTP_18
792
793 % <TestDescription>
794 %
795 % Tests that the average method works with a single AO as input.
796 %
797 % </TestDescription>
798 function result = utp_18
799
800 % <SyntaxDescription>
801 %
802 % Tests that the average method works with a single AO as input.
803 %
804 % </SyntaxDescription>
805
806 try
807 % <SyntaxCode>
808 % Pick units and prefix from those supported
809 unit_list = unit.supportedUnits;
810 % remove the first empty unit '' from the list, because then is it
811 % possible that we add a prefix to an empty unit
812 unit_list = unit_list(2:end);
813 prefix_list = unit.supportedPrefixes;
814 u = unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]);
815
816 % tsdata: settings
817 fs = 3;
818 ts_pl = plist('fs', fs, 'nsecs', 30, 'waveform', 'sine wave', 'f', 10, 'yunits', u);
819 ts_a1 = ao(ts_pl);
820 ts_a1.setT0('14:00:00');
821
822 % tsdata: call the method with a list of inputs
823 ts_out = average(ts_a1);
824
825 % fsdata: settings
826 fs_pl = plist('fsfcn', '1./f.^2', 'scale', 'lin', 'nf', 100, 'yunits', u);
827 fs_a1 = ao(fs_pl);
828
829 % fsdata: call the method with a list of inputs
830 fs_out = average(fs_a1);
831
832 % xydata: settings
833 xy_pl = plist('X', [1:50,52:2:100,110:10:1000], 'xyfcn', 'log(x)', 'yunits', u);
834 xy_a1 = ao(xy_pl);
835
836 % xydata: call the method with a list of inputs
837 xy_out = average(xy_a1);
838
839 % cdata: settings
840 c_pl = plist('yunits', u);
841 c_a1 = ao([1 2 3], c_pl);
842
843 % cdata: call the method with a list of inputs
844 c_out = average(c_a1);
845
846 % Rebuild the objects
847 ts_mout = rebuild(ts_out);
848 fs_mout = rebuild(fs_out);
849 xy_mout = rebuild(xy_out);
850 c_mout = rebuild(c_out);
851
852 % </SyntaxCode>
853 stest = true;
854 catch err
855 disp(err.message)
856 stest = false;
857 end
858
859 % <AlgoDescription>
860 %
861 % 1) Check that the outputs have exactly one AO
862 % 2) Check that the outputs have the correct data.
863 % 3) Check the rebuilt objects
864 %
865 % </AlgoDescription>
866
867 atest = true;
868
869 if stest
870 % <AlgoCode>
871 % Check that the output is exactly one AO
872 if numel(ts_out) ~= 1, atest = false; end
873 if numel(fs_out) ~= 1, atest = false; end
874 if numel(xy_out) ~= 1, atest = false; end
875 if numel(c_out) ~= 1, atest = false; end
876 if ~isa(ts_out, 'ao'), atest = false; end
877 if ~isa(fs_out, 'ao'), atest = false; end
878 if ~isa(xy_out, 'ao'), atest = false; end
879 if ~isa(c_out, 'ao'), atest = false; end
880
881
882 % Check output data: x
883 if ~isequal(ts_out.x, ts_a1.x), atest = false; end
884 if ~isequal(fs_out.x, fs_a1.x), atest = false; end
885 if ~isequal(xy_out.x, xy_a1.x), atest = false; end
886
887 % Check output data: t0
888 if ~isequal(ts_out.t0, ts_a1.t0), atest = false; end
889
890 % Check output data: y
891 if ~isequal(ts_out.y, ts_a1.y), atest = false; end
892 if ~isequal(fs_out.y, fs_a1.y), atest = false; end
893 if ~isequal(xy_out.y, xy_a1.y), atest = false; end
894 if ~isequal(c_out.y, c_a1.y), atest = false; end
895
896 % Check output data: dy
897 if ~isequal(ts_out.dy, ts_a1.dy), atest = false; end
898 if ~isequal(fs_out.dy, fs_a1.dy), atest = false; end
899 if ~isequal(xy_out.dy, xy_a1.dy), atest = false; end
900 if ~isequal(c_out.dy, c_a1.dy), atest = false; end
901
902 % Check output data: xunits
903 if ~isequal(ts_out.xunits, ts_a1.xunits), atest = false; end
904 if ~isequal(fs_out.xunits, fs_a1.xunits), atest = false; end
905 if ~isequal(xy_out.xunits, xy_a1.xunits), atest = false; end
906
907 % Check output data: yunits
908 if ~isequal(ts_out.yunits, ts_a1.yunits), atest = false; end
909 if ~isequal(fs_out.yunits, fs_a1.yunits), atest = false; end
910 if ~isequal(xy_out.yunits, xy_a1.yunits), atest = false; end
911 if ~isequal(c_out.yunits, c_a1.yunits), atest = false; end
912
913 % Check the re-built objects
914 if ~eq(ts_out, ts_mout, ple2), atest = false; end
915 if ~eq(fs_out, fs_mout, ple2), atest = false; end
916 if ~eq(xy_out, xy_mout, ple2), atest = false; end
917 if ~eq(c_out, c_mout, ple2), atest = false; end
918
919 % </AlgoCode>
920 else
921 atest = false;
922 end
923
924 % Return a result structure
925 result = utp_prepare_result(atest, stest, dbstack, mfilename);
926 end % END UTP_18
927 end