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