Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_power.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_POWER a set of UTPs for the ao/power method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_power.m,v 1.7 2011/02/28 15:55:13 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The power method of the ao class computes the power of the y data of the two | |
11 % inputs. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_power(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'power'; | |
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 | |
38 results = [results utp_03]; % Matrix input | |
39 results = [results utp_04]; % List input | |
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 input data shape == output data shape | |
44 results = [results utp_09]; % Test all data types | |
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('exponent'), atest = false; end | |
115 % Check default value | |
116 if ~isEmptyDouble(io(3).plists.find('exponent')), atest = false; end | |
117 % Check options | |
118 if ~isequal(io(3).plists.getOptionsForParam('exponent'), {[]}), 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 power 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 power method works for a vector of AOs as input. | |
141 % | |
142 % </SyntaxDescription> | |
143 | |
144 try | |
145 % <SyntaxCode> | |
146 % We need a vector of AOs all the same size. | |
147 % The shape of the data shouldn't have an effect to the algorithm. | |
148 avec = [at1 at5 at6]; | |
149 out = power(avec); | |
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 1 | |
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 one output | |
168 if numel(out) ~= 1, atest = false; end | |
169 % Check the output against the power of the inputs | |
170 s = avec(1).data.getY; | |
171 for jj=2:numel(avec) | |
172 s = s .^ avec(jj).data.getY; | |
173 end | |
174 if ~isequal(s, out.data.getY), atest = false; end | |
175 % </AlgoCode> | |
176 else | |
177 atest = false; | |
178 end | |
179 | |
180 % Return a result structure | |
181 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
182 end % END UTP_02 | |
183 | |
184 %% UTP_03 | |
185 | |
186 % <TestDescription> | |
187 % | |
188 % Tests that the power method works with a matrix of AOs as input. | |
189 % | |
190 % </TestDescription> | |
191 function result = utp_03 | |
192 | |
193 % <SyntaxDescription> | |
194 % | |
195 % Test that the power method works for a matrix of AOs as input. | |
196 % | |
197 % </SyntaxDescription> | |
198 | |
199 try | |
200 % <SyntaxCode> | |
201 % We need a matrix of AOs all the same size | |
202 amat = [at1 at6 at1; at6 at5 at6]; | |
203 out = power(amat); | |
204 stest = true; | |
205 % </SyntaxCode> | |
206 catch err | |
207 disp(err.message) | |
208 stest = false; | |
209 end | |
210 | |
211 % <AlgoDescription> | |
212 % | |
213 % 1) Check that the number of elements in 'out' is 1 | |
214 % 2) Check that each output AO contains the correct data. | |
215 % | |
216 % </AlgoDescription> | |
217 | |
218 atest = true; | |
219 if stest | |
220 % <AlgoCode> | |
221 % Check we have the correct number of outputs | |
222 if numel(out) ~= 1, atest = false; end | |
223 % Check the output against the power of the inputs | |
224 s = amat(1).data.getY; | |
225 for kk=2:numel(amat) | |
226 s = s .^ amat(kk).data.getY; | |
227 end | |
228 if ~isequal(s, out.data.getY), atest = false; end | |
229 % </AlgoCode> | |
230 else | |
231 atest = false; | |
232 end | |
233 | |
234 % Return a result structure | |
235 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
236 end % END UTP_03 | |
237 | |
238 %% UTP_04 | |
239 | |
240 % <TestDescription> | |
241 % | |
242 % Tests that the power method works with a list of AOs as input. | |
243 % | |
244 % </TestDescription> | |
245 function result = utp_04 | |
246 | |
247 % <SyntaxDescription> | |
248 % | |
249 % Test that the power method works for a list of AOs as input. | |
250 % | |
251 % </SyntaxDescription> | |
252 | |
253 try | |
254 % <SyntaxCode> | |
255 out = power(at1,at5,at6); | |
256 % </SyntaxCode> | |
257 stest = true; | |
258 catch err | |
259 disp(err.message) | |
260 stest = false; | |
261 end | |
262 | |
263 % <AlgoDescription> | |
264 % | |
265 % 1) Check that the number of elements in 'out' is 1. | |
266 % 2) Check that each output AO contains the correct data. | |
267 % 3) Check the y-units | |
268 % | |
269 % </AlgoDescription> | |
270 | |
271 atest = true; | |
272 if stest | |
273 % <AlgoCode> | |
274 % Check we have the correct number of outputs | |
275 if numel(out) ~= 1, atest = false; end | |
276 % Check the output against the power of the inputs | |
277 s = at1.data.getY .^ at5.data.getY .^ at6.data.getY; | |
278 if ~isequal(s, out.data.getY), atest = false; end | |
279 % Check the units | |
280 if ~eq(out.yunits, at1.yunits), atest = false; end | |
281 % </AlgoCode> | |
282 else | |
283 atest = false; | |
284 end | |
285 | |
286 % Return a result structure | |
287 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
288 end % END UTP_04 | |
289 | |
290 %% UTP_05 | |
291 | |
292 % <TestDescription> | |
293 % | |
294 % Tests that the power method works with a mix of different shaped AOs as | |
295 % input. | |
296 % | |
297 % </TestDescription> | |
298 function result = utp_05 | |
299 | |
300 % <SyntaxDescription> | |
301 % | |
302 % Test that the power method works with an input of matrices and vectors | |
303 % and single AOs. | |
304 % | |
305 % </SyntaxDescription> | |
306 | |
307 try | |
308 % <SyntaxCode> | |
309 % We need a vector of AOs all the same size | |
310 avec = [at5 at6 at5]; | |
311 % We need a matrix of AOs all the same size | |
312 amat = [at5 at6 at5; at6 at5 at6]; | |
313 % Compute power | |
314 out = power(at5,avec,at5,amat,at5); | |
315 % </SyntaxCode> | |
316 stest = true; | |
317 catch err | |
318 disp(err.message) | |
319 stest = false; | |
320 end | |
321 | |
322 % <AlgoDescription> | |
323 % | |
324 % 1) Check that the number of elements in 'out' is 1. | |
325 % 2) Check that each output AO contains the correct data. | |
326 % | |
327 % </AlgoDescription> | |
328 | |
329 atest = true; | |
330 if stest | |
331 % <AlgoCode> | |
332 % Check we have the correct number of outputs | |
333 if numel(out) ~= 1, atest = false; end | |
334 % Check the power of all the inputs | |
335 s = at5.data.getY; | |
336 for jj=1:numel(avec) | |
337 s = s .^ avec(jj).data.getY; | |
338 end | |
339 s = s .^ at5.data.getY; | |
340 for jj=1:numel(amat) | |
341 s = s .^ amat(jj).data.getY; | |
342 end | |
343 s = s .^ at5.data.getY; | |
344 if ~isequal(s, out.data.getY), atest = false; end | |
345 % </AlgoCode> | |
346 else | |
347 atest = false; | |
348 end | |
349 | |
350 % Return a result structure | |
351 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
352 end % END UTP_05 | |
353 | |
354 %% UTP_06 | |
355 | |
356 % <TestDescription> | |
357 % | |
358 % Tests that the power method properly applies history. | |
359 % | |
360 % </TestDescription> | |
361 function result = utp_06 | |
362 | |
363 % <SyntaxDescription> | |
364 % | |
365 % Test that the result of applying the power method can be processed back | |
366 % to an m-file. | |
367 % | |
368 % </SyntaxDescription> | |
369 | |
370 try | |
371 % <SyntaxCode> | |
372 out = power(at5,at6); | |
373 mout = rebuild(out); | |
374 % </SyntaxCode> | |
375 stest = true; | |
376 catch err | |
377 disp(err.message) | |
378 stest = false; | |
379 end | |
380 | |
381 % <AlgoDescription> | |
382 % | |
383 % 1) Check that the last entry in the history of 'out' corresponds to | |
384 % 'power'. | |
385 % 2) Check that the re-built object is the same object as 'out'. | |
386 % | |
387 % </AlgoDescription> | |
388 | |
389 atest = true; | |
390 if stest | |
391 % <AlgoCode> | |
392 % Check the last step in the history of 'out' | |
393 if ~strcmp(out.hist.methodInfo.mname, 'power'), atest = false; end | |
394 % Check the re-built object | |
395 if ~eq(mout, out, ple2), atest = false; end | |
396 % </AlgoCode> | |
397 else | |
398 atest = false; | |
399 end | |
400 | |
401 % Return a result structure | |
402 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
403 end % END UTP_06 | |
404 | |
405 %% UTP_07 | |
406 | |
407 % <TestDescription> | |
408 % | |
409 % Tests that the power method can modify the input AO. | |
410 % | |
411 % </TestDescription> | |
412 function result = utp_07 | |
413 | |
414 % <SyntaxDescription> | |
415 % | |
416 % Test that the power method can modify the input AO by calling with no | |
417 % output and that the method doesn't change the input of the function | |
418 % notation (with a equal sign). | |
419 % | |
420 % </SyntaxDescription> | |
421 | |
422 try | |
423 % <SyntaxCode> | |
424 % copy at1 to work with | |
425 ain = ao(at1); | |
426 % modify ain | |
427 aout = ain.power(5); | |
428 ain .^ 5; | |
429 % </SyntaxCode> | |
430 stest = true; | |
431 catch err | |
432 disp(err.message) | |
433 stest = false; | |
434 end | |
435 | |
436 % <AlgoDescription> | |
437 % | |
438 % 1) Check that 'at1' and 'ain' are now different. | |
439 % 2) Check that 'ain' is power(at1). | |
440 % | |
441 % </AlgoDescription> | |
442 | |
443 atest = true; | |
444 if stest | |
445 % <AlgoCode> | |
446 % Check that power modified the input by comparing to the copy | |
447 if eq(ao(at1), ain, ple1), atest = false; end | |
448 % Check that power doesn't modified the input for the function notation | |
449 if ~eq(aout, ain, ple1), atest = false; end | |
450 % Check that the modified input is the power value of the copy | |
451 if ~isequal(power(at1.y, 5), ain.y), atest = false; end | |
452 % </AlgoCode> | |
453 else | |
454 atest = false; | |
455 end | |
456 | |
457 % Return a result structure | |
458 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
459 end % END UTP_07 | |
460 | |
461 %% UTP_08 | |
462 | |
463 % <TestDescription> | |
464 % | |
465 % Test the shape of the output. | |
466 % | |
467 % </TestDescription> | |
468 function result = utp_08 | |
469 | |
470 % <SyntaxDescription> | |
471 % | |
472 % Test that the power method keeps the data shape of the input object. The | |
473 % input AO must be an AO with row data and an AO with column data. | |
474 % | |
475 % </SyntaxDescription> | |
476 | |
477 try | |
478 % <SyntaxCode> | |
479 out1 = at5 .^ 5; | |
480 out3 = at6 .^ 5; | |
481 % </SyntaxCode> | |
482 stest = true; | |
483 catch err | |
484 disp(err.message) | |
485 stest = false; | |
486 end | |
487 | |
488 % <AlgoDescription> | |
489 % | |
490 % 1) Check that the shpe of the data doesn't change. | |
491 % | |
492 % </AlgoDescription> | |
493 | |
494 atest = true; | |
495 if stest | |
496 % <AlgoCode> | |
497 % Check the shape of the output data | |
498 if size(out1.data.y, 1) ~= size(at5.data.y, 1), atest = false; end | |
499 if size(out3.data.y, 2) ~= size(at6.data.y, 2), atest = false; end | |
500 % Check y-units | |
501 if ~eq(out1.yunits, at5.yunits.^5), atest = false; end | |
502 if ~eq(out3.yunits, at6.yunits.^5), atest = false; end | |
503 % </AlgoCode> | |
504 else | |
505 atest = false; | |
506 end | |
507 | |
508 % Return a result structure | |
509 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
510 end % END UTP_08 | |
511 | |
512 %% UTP_09 | |
513 | |
514 % <TestDescription> | |
515 % | |
516 % Test the method with all data objects. | |
517 % | |
518 % </TestDescription> | |
519 function result = utp_09 | |
520 | |
521 % <SyntaxDescription> | |
522 % | |
523 % Test that the power method works with cdata-, fsdata-, tsdata-, and xydata | |
524 % objects | |
525 % | |
526 % </SyntaxDescription> | |
527 | |
528 try | |
529 % <SyntaxCode> | |
530 out11 = at1 .^ 5; | |
531 out21 = at2 .^ 5; | |
532 out31 = at3 .^ 5; | |
533 out41 = at4 .^ 5; | |
534 out51 = at1 .^ ao(5); | |
535 out61 = at2 .^ ao(5); | |
536 out71 = at3 .^ ao(5); | |
537 out81 = at4 .^ ao(5); | |
538 % </SyntaxCode> | |
539 stest = true; | |
540 catch err | |
541 disp(err.message) | |
542 stest = false; | |
543 end | |
544 | |
545 % <AlgoDescription> | |
546 % | |
547 % 1) Check that the shpe of the data doesn't change. | |
548 % 2) Check that re-building of output is the same as the output | |
549 % | |
550 % </AlgoDescription> | |
551 | |
552 atest = true; | |
553 if stest | |
554 % <AlgoCode> | |
555 % Check the shape of the output data | |
556 if ~isequal(power(at1.y, 5), out11.y), atest = false; end | |
557 if ~isequal(power(at2.y, 5), out21.y), atest = false; end | |
558 if ~isequal(power(at3.y, 5), out31.y), atest = false; end | |
559 if ~isequal(power(at4.y, 5), out41.y), atest = false; end | |
560 if ~isequal(power(at1.y, 5), out51.y), atest = false; end | |
561 if ~isequal(power(at2.y, 5), out61.y), atest = false; end | |
562 if ~isequal(power(at3.y, 5), out71.y), atest = false; end | |
563 if ~isequal(power(at4.y, 5), out81.y), atest = false; end | |
564 % Check the rebuilding | |
565 if ~eq(rebuild(out11), out11, ple2), atest = false; end | |
566 if ~eq(rebuild(out21), out21, ple2), atest = false; end | |
567 if ~eq(rebuild(out31), out31, ple2), atest = false; end | |
568 if ~eq(rebuild(out41), out41, ple2), atest = false; end | |
569 if ~eq(rebuild(out51), out51, ple2), atest = false; end | |
570 if ~eq(rebuild(out61), out61, ple2), atest = false; end | |
571 if ~eq(rebuild(out71), out71, ple2), atest = false; end | |
572 if ~eq(rebuild(out81), out81, ple2), atest = false; end | |
573 % </AlgoCode> | |
574 else | |
575 atest = false; | |
576 end | |
577 | |
578 % Return a result structure | |
579 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
580 end % END UTP_09 | |
581 | |
582 end |