comparison testing/utp_1.1/utps/ao/utp_ao_timeshift.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_TIMESHIFT a set of UTPs for the ao/timeshift method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_timeshift.m,v 1.11 2011/09/29 12:15:14 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The timeshift method of the ao class timeshifts time-series AOs.
11 %
12 % </MethodDescription>
13
14 function results = utp_ao_timeshift(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'ao';
21 mthd = 'timeshift';
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 % Run the tests
35 results = [results utp_01]; % getInfo call
36 results = [results utp_02]; % Vector input
37 results = [results utp_03]; % Matrix input
38 results = [results utp_04]; % List input
39 results = [results utp_05]; % Test with mixed input
40 results = [results utp_06]; % Test history is working
41 results = [results utp_07]; % Test the modify call works
42 results = [results utp_08]; % Test input data shape == output data shape
43 results = [results utp_09]; % Test output of the data
44 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear
45
46 disp('Done.');
47 disp('******************************************************');
48
49 elseif nargin == 1 % Check for UTP functions
50 if strcmp(varargin{1}, 'isutp')
51 results = 1;
52 else
53 results = 0;
54 end
55 else
56 error('### Incorrect inputs')
57 end
58
59 %% UTP_01
60
61 % <TestDescription>
62 %
63 % Tests that the getInfo call works for this method.
64 %
65 % </TestDescription>
66 function result = utp_01
67
68
69 % <SyntaxDescription>
70 %
71 % Test that the getInfo call works for no sets, all sets, and each set
72 % individually.
73 %
74 % </SyntaxDescription>
75
76 try
77 % <SyntaxCode>
78 % Call for no sets
79 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
80 % Call for all sets
81 io(2) = eval([class '.getInfo(''' mthd ''')']);
82 % Call for each set
83 for kk=1:numel(io(2).sets)
84 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
85 end
86 % </SyntaxCode>
87 stest = true;
88 catch err
89 disp(err.message)
90 stest = false;
91 end
92
93 % <AlgoDescription>
94 %
95 % 1) Check that getInfo call returned an minfo object in all cases.
96 % 2) Check that all plists have the correct parameters.
97 %
98 % </AlgoDescription>
99
100 atest = true;
101 if stest
102 % <AlgoCode>
103 % check we have minfo objects
104 if isa(io, 'minfo')
105 % SET 'None'
106 if ~isempty(io(1).sets), atest = false; end
107 if ~isempty(io(1).plists), atest = false; end
108 % Check all Sets
109 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
110 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
111 % SET 'Default'
112 if io(3).plists.nparams ~= 1, atest = false; end
113 % Check key
114 if ~io(3).plists.isparam('offset'), atest = false; end
115 % Check default value
116 if ~isequal(io(3).plists.find('offset'), 0), atest = false; end
117 % Check options
118 if ~isequal(io(3).plists.getOptionsForParam('offset'), {0}), atest = false; end
119 end
120 % </AlgoCode>
121 else
122 atest = false;
123 end
124
125 % Return a result structure
126 result = utp_prepare_result(atest, stest, dbstack, mfilename);
127 end % END UTP_01
128
129 %% UTP_02
130
131 % <TestDescription>
132 %
133 % Tests that the timeshift method works with a vector of AOs as input.
134 %
135 % </TestDescription>
136 function result = utp_02
137
138 % <SyntaxDescription>
139 %
140 % Test that the timeshift method works for a vector of AOs as input.
141 %
142 % </SyntaxDescription>
143
144 try
145 % <SyntaxCode>
146 avec = [at1 at5 at6];
147 out = timeshift(avec);
148 % </SyntaxCode>
149 stest = true;
150 catch err
151 disp(err.message)
152 stest = false;
153 end
154
155 % <AlgoDescription>
156 %
157 % 1) Check that the number of elements in 'out' is the square of the
158 % number in the input.
159 % 2) Check that each output AO contains the correct data.
160 %
161 % </AlgoDescription>
162
163 atest = true;
164 if stest
165 % <AlgoCode>
166 % Check we have the correct number of outputs
167 if numel(out) ~= numel(avec), atest = false; end
168 % </AlgoCode>
169 else
170 atest = false;
171 end
172
173 % Return a result structure
174 result = utp_prepare_result(atest, stest, dbstack, mfilename);
175 end % END UTP_02
176
177 %% UTP_03
178
179 % <TestDescription>
180 %
181 % Tests that the timeshift method works with a matrix of AOs as input.
182 %
183 % </TestDescription>
184 function result = utp_03
185
186 % <SyntaxDescription>
187 %
188 % Test that the timeshift method works for a matrix of AOs as input.
189 %
190 % </SyntaxDescription>
191
192 try
193 % <SyntaxCode>
194 amat = [at1 at5 at6; at5 at6 at1];
195 out = timeshift(amat);
196 % </SyntaxCode>
197 stest = true;
198 catch err
199 disp(err.message)
200 stest = false;
201 end
202
203 % <AlgoDescription>
204 %
205 % 1) Check that the number of elements in 'out' is the square of the
206 % number in the input.
207 % 2) Check that each output AO contains the correct data.
208 %
209 % </AlgoDescription>
210
211 atest = true;
212 if stest
213 % <AlgoCode>
214 % Check we have the correct number of outputs
215 if numel(out) ~= numel(amat), atest = false; end
216 % </AlgoCode>
217 else
218 atest = false;
219 end
220
221 % Return a result structure
222 result = utp_prepare_result(atest, stest, dbstack, mfilename);
223 end % END UTP_03
224
225 %% UTP_04
226
227 % <TestDescription>
228 %
229 % Tests that the timeshift method works with a list of AOs as input.
230 %
231 % </TestDescription>
232 function result = utp_04
233
234 % <SyntaxDescription>
235 %
236 % Test that the timeshift method works for a list of AOs as input.
237 %
238 % </SyntaxDescription>
239
240 try
241 % <SyntaxCode>
242 out = timeshift(at1,at5,at6);
243 % </SyntaxCode>
244 stest = true;
245 catch err
246 disp(err.message)
247 stest = false;
248 end
249
250 % <AlgoDescription>
251 %
252 % 1) Check that the number of elements in 'out' is the square of the
253 % number in the input.
254 % 2) Check that each output AO contains the correct data.
255 %
256 % </AlgoDescription>
257
258 atest = true;
259 if stest
260 % <AlgoCode>
261 % Check we have the correct number of outputs
262 if numel(out) ~= 3, atest = false; end
263 % </AlgoCode>
264 else
265 atest = false;
266 end
267
268 % Return a result structure
269 result = utp_prepare_result(atest, stest, dbstack, mfilename);
270 end % END UTP_04
271
272 %% UTP_05
273
274 % <TestDescription>
275 %
276 % Tests that the timeshift method works with a mix of different shaped AOs as
277 % input.
278 %
279 % </TestDescription>
280 function result = utp_05
281
282 % <SyntaxDescription>
283 %
284 % Test that the timeshift method works with an input of matrices and vectors
285 % and single AOs.
286 %
287 % </SyntaxDescription>
288
289 try
290 % <SyntaxCode>
291 out = timeshift(at1,[at5 at6],at5,[at5 at1; at6 at1],at6);
292 % </SyntaxCode>
293 stest = true;
294 catch err
295 disp(err.message)
296 stest = false;
297 end
298
299 % <AlgoDescription>
300 %
301 % 1) Check that the number of elements in 'out' is the same as in
302 % input.
303 % 2) Check that each output AO contains the correct data.
304 % </AlgoDescription>
305
306 atest = true;
307 if stest
308 % <AlgoCode>
309 % Check we have the correct number of outputs
310 if numel(out) ~= 9, atest = false; end
311 % </AlgoCode>
312 else
313 atest = false;
314 end
315
316 % Return a result structure
317 result = utp_prepare_result(atest, stest, dbstack, mfilename);
318 end % END UTP_05
319
320 %% UTP_06
321
322 % <TestDescription>
323 %
324 % Tests that the timeshift method properly applies history.
325 %
326 % </TestDescription>
327 function result = utp_06
328
329 % <SyntaxDescription>
330 %
331 % Test that the result of applying the timeshift method can be processed back
332 % to an m-file.
333 %
334 % </SyntaxDescription>
335
336 try
337 % <SyntaxCode>
338 out = timeshift(at5);
339 mout = rebuild(out);
340 % </SyntaxCode>
341 stest = true;
342 catch err
343 disp(err.message)
344 stest = false;
345 end
346
347 % <AlgoDescription>
348 %
349 % 1) Check that the last entry in the history of 'out' corresponds to
350 % 'timeshift'.
351 % 2) Check that the re-built object is the same object as 'out'.
352 %
353 % </AlgoDescription>
354
355 atest = true;
356 if stest
357 % <AlgoCode>
358 % Check the last step in the history of 'out'
359 if ~strcmp(out.hist.methodInfo.mname, 'timeshift'), atest = false; end
360 % Check the re-built object
361 if ~eq(mout, out, ple2), atest = false; end
362 % </AlgoCode>
363 else
364 atest = false;
365 end
366
367 % Return a result structure
368 result = utp_prepare_result(atest, stest, dbstack, mfilename);
369 end % END UTP_06
370
371 %% UTP_07
372
373 % <TestDescription>
374 %
375 % Tests that the timeshift method can modify the input AO.
376 %
377 % </TestDescription>
378 function result = utp_07
379
380 % <SyntaxDescription>
381 %
382 % Test that the timeshift method can modify the input AO by calling with no
383 % output and that the method doesn't change the input of the function
384 % notation (with a equal sign).
385 %
386 % </SyntaxDescription>
387
388 try
389 % <SyntaxCode>
390 % copy at1 to work with
391 ain = ao(at1);
392 % modify ain
393 aout = ain.timeshift();
394 ain.timeshift();
395 % </SyntaxCode>
396 stest = true;
397 catch err
398 disp(err.message)
399 stest = false;
400 end
401
402 % <AlgoDescription>
403 %
404 % 1) Check that 'at1' and 'ain' are now different.
405 % 2) Check that 'ain' is timeshift(at1).
406 % 3) Check the algorithm
407 %
408 % </AlgoDescription>
409
410 atest = true;
411 if stest
412 % <AlgoCode>
413 % Check that timeshift modified the input by comparing to the copy
414 if eq(ao(at1), ain, ple1), atest = false; end
415 % Check that timeshift doesn't modified the input for the function notation
416 if ~eq(aout, ain, ple1), atest = false; end
417 %
418 % </AlgoCode>
419 else
420 atest = false;
421 end
422
423 % Return a result structure
424 result = utp_prepare_result(atest, stest, dbstack, mfilename);
425 end % END UTP_07
426
427 %% UTP_08
428
429 % <TestDescription>
430 %
431 % Control the method with a plist.
432 %
433 % </TestDescription>
434 function result = utp_08
435
436 % <SyntaxDescription>
437 %
438 % Test that the timeshift method keeps the data shape of the input object. The
439 % input AO must be an AO with row data and an AO with column data.
440 %
441 % </SyntaxDescription>
442
443 try
444 % <SyntaxCode>
445 out1 = timeshift(at5);
446 out2 = timeshift(at6);
447 % </SyntaxCode>
448 stest = true;
449 catch err
450 disp(err.message)
451 stest = false;
452 end
453
454 % <AlgoDescription>
455 %
456 % 1) Check that the shpe of the data doesn't change.
457 %
458 % </AlgoDescription>
459
460 atest = true;
461 if stest
462 % <AlgoCode>
463 % Check the shape of the output data
464 if size(out1.data.y) ~= size(at5.data.y), atest = false; end
465 if size(out2.data.y) ~= size(at6.data.y), atest = false; end
466 % </AlgoCode>
467 else
468 atest = false;
469 end
470
471 % Return a result structure
472 result = utp_prepare_result(atest, stest, dbstack, mfilename);
473 end % END UTP_08
474
475 %% UTP_09
476
477 % <TestDescription>
478 %
479 % Check that the timeshift method pass back the output objects to a list of
480 % output variables or to a single variable.
481 %
482 % </TestDescription>
483 function result = utp_09
484
485 % <SyntaxDescription>
486 %
487 % Call the method with a list of output variables and with a single output
488 % variable. Additionaly check that the rebuild method works on the output.
489 %
490 % </SyntaxDescription>
491
492 try
493 % <SyntaxCode>
494 [o1, o2] = timeshift(at5, at6);
495 o3 = timeshift(at5, at6);
496 mout1 = rebuild(o1);
497 mout2 = rebuild(o2);
498 mout3 = rebuild(o3);
499 % </SyntaxCode>
500 stest = true;
501 catch err
502 disp(err.message)
503 stest = false;
504 end
505
506 % <AlgoDescription>
507 %
508 % 1) Check that the output contains the right number of objects
509 % 2) Check that the 'rebuild' method produces the same object as 'out'.
510 %
511 % </AlgoDescription>
512
513 atest = true;
514 if stest
515 % <AlgoCode>
516 % Check the number of outputs
517 if numel(o1) ~=1, atest = false; end
518 if numel(o2) ~=1, atest = false; end
519 if numel(o3) ~=2, atest = false; end
520 % Check the rebuilding of the object
521 if ~eq(o1, mout1, ple2), atest = false; end
522 if ~eq(o2, mout2, ple2), atest = false; end
523 if ~eq(o3, mout3, ple2), atest = false; end
524 % </AlgoCode>
525 else
526 atest = false;
527 end
528
529 % Return a result structure
530 result = utp_prepare_result(atest, stest, dbstack, mfilename);
531 end % END UTP_09
532
533 end