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