Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_mpower.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_MPOWER a set of UTPs for the ao/mpower method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_mpower.m,v 1.6 2011/02/28 15:55:13 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The mpower method of the ao class computes the matrix power of the y data | |
11 % of the two inputs. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_mpower(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'mpower'; | |
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 | |
45 disp('Done.'); | |
46 disp('******************************************************'); | |
47 | |
48 elseif nargin == 1 % Check for UTP functions | |
49 if strcmp(varargin{1}, 'isutp') | |
50 results = 1; | |
51 else | |
52 results = 0; | |
53 end | |
54 else | |
55 error('### Incorrect inputs') | |
56 end | |
57 | |
58 %% UTP_01 | |
59 | |
60 % <TestDescription> | |
61 % | |
62 % Tests that the getInfo call works for this method. | |
63 % | |
64 % </TestDescription> | |
65 function result = utp_01 | |
66 | |
67 | |
68 % <SyntaxDescription> | |
69 % | |
70 % Test that the getInfo call works for no sets, all sets, and each set | |
71 % individually. | |
72 % | |
73 % </SyntaxDescription> | |
74 | |
75 try | |
76 % <SyntaxCode> | |
77 % Call for no sets | |
78 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
79 % Call for all sets | |
80 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
81 % Call for each set | |
82 for kk=1:numel(io(2).sets) | |
83 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
84 end | |
85 % </SyntaxCode> | |
86 stest = true; | |
87 catch err | |
88 disp(err.message) | |
89 stest = false; | |
90 end | |
91 | |
92 % <AlgoDescription> | |
93 % | |
94 % 1) Check that getInfo call returned an minfo object in all cases. | |
95 % 2) Check that all plists have the correct parameters. | |
96 % | |
97 % </AlgoDescription> | |
98 | |
99 atest = true; | |
100 if stest | |
101 % <AlgoCode> | |
102 % check we have minfo objects | |
103 if isa(io, 'minfo') | |
104 %%% SET 'None' | |
105 if ~isempty(io(1).sets), atest = false; end | |
106 if ~isempty(io(1).plists), atest = false; end | |
107 %%% Check all Sets | |
108 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
109 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
110 %%%%%%%%%% SET 'Default' | |
111 if io(3).plists.nparams ~= 1, atest = false; end | |
112 % Check key | |
113 if ~io(3).plists.isparam('exponent'), atest = false; end | |
114 % Check default value | |
115 if ~isEmptyDouble(io(3).plists.find('exponent')), atest = false; end | |
116 % Check options | |
117 if ~isequal(io(3).plists.getOptionsForParam('exponent'), {[]}), atest = false; end | |
118 end | |
119 % </AlgoCode> | |
120 else | |
121 atest = false; | |
122 end | |
123 | |
124 % Return a result structure | |
125 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
126 end % END UTP_01 | |
127 | |
128 %% UTP_02 | |
129 | |
130 % <TestDescription> | |
131 % | |
132 % Tests that the mpower method works with a vector of AOs as input. | |
133 % | |
134 % </TestDescription> | |
135 function result = utp_02 | |
136 | |
137 % <SyntaxDescription> | |
138 % | |
139 % Test that the mpower method works for a vector of AOs as input. | |
140 % | |
141 % </SyntaxDescription> | |
142 | |
143 try | |
144 % <SyntaxCode> | |
145 % We need a vector of AOs all the same size. | |
146 % The shape of the data shouldn't have an effect to the algorithm. | |
147 avec = [at4 ao(3) ao(1)]; | |
148 out = mpower(avec); | |
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 1 | |
159 % 2) Check that each output AO contains the correct data. | |
160 % 3) Check the y-units | |
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 matrix 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 mpower 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 mpower 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 = [at4 ao(1) ao(2); ao(3) ao(4) ao(5)]; | |
203 out = mpower(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 matrix 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 mpower 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 mpower method works for a list of AOs as input. | |
250 % | |
251 % </SyntaxDescription> | |
252 | |
253 try | |
254 % <SyntaxCode> | |
255 out = mpower(at4,ao(7),ao(4)); | |
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 matrix power of the inputs | |
277 s = at4.data.getY ^ 7 ^ 4; | |
278 if ~isequal(s, out.data.getY), atest = false; end | |
279 % </AlgoCode> | |
280 else | |
281 atest = false; | |
282 end | |
283 | |
284 % Return a result structure | |
285 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
286 end % END UTP_04 | |
287 | |
288 %% UTP_05 | |
289 | |
290 % <TestDescription> | |
291 % | |
292 % Tests that the mpower method works with a mix of different shaped AOs as | |
293 % input. | |
294 % | |
295 % </TestDescription> | |
296 function result = utp_05 | |
297 | |
298 % <SyntaxDescription> | |
299 % | |
300 % Test that the mpower method works with an input of matrices and vectors | |
301 % and single AOs. | |
302 % | |
303 % </SyntaxDescription> | |
304 | |
305 try | |
306 % <SyntaxCode> | |
307 % This UTP doen't make sense. | |
308 % </SyntaxCode> | |
309 stest = true; | |
310 catch err | |
311 disp(err.message) | |
312 stest = false; | |
313 end | |
314 | |
315 % <AlgoDescription> | |
316 % | |
317 % 1) Nothing to check | |
318 % | |
319 % </AlgoDescription> | |
320 | |
321 atest = true; | |
322 if stest | |
323 % <AlgoCode> | |
324 % </AlgoCode> | |
325 else | |
326 atest = false; | |
327 end | |
328 | |
329 % Return a result structure | |
330 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
331 end % END UTP_05 | |
332 | |
333 %% UTP_06 | |
334 | |
335 % <TestDescription> | |
336 % | |
337 % Tests that the mpower method properly applies history. | |
338 % | |
339 % </TestDescription> | |
340 function result = utp_06 | |
341 | |
342 % <SyntaxDescription> | |
343 % | |
344 % Test that the result of applying the mpower method can be processed back | |
345 % to an m-file. | |
346 % | |
347 % </SyntaxDescription> | |
348 | |
349 try | |
350 % <SyntaxCode> | |
351 out1 = mpower(at4,5); | |
352 out2 = mpower(at4,ao(5)); | |
353 mout1 = rebuild(out1); | |
354 mout2 = rebuild(out2); | |
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 last entry in the history of 'out1' and 'out2' corresponds to | |
365 % 'mpower'. | |
366 % 2) Check that the re-built objects are the same objectd as 'out1' and 'out2'. | |
367 % | |
368 % </AlgoDescription> | |
369 | |
370 atest = true; | |
371 if stest | |
372 % <AlgoCode> | |
373 % Check the last step in the history of 'out1' and 'out2' | |
374 if ~strcmp(out1.hist.methodInfo.mname, 'mpower'), atest = false; end | |
375 if ~strcmp(out2.hist.methodInfo.mname, 'mpower'), atest = false; end | |
376 % Check the re-built objects | |
377 if ~eq(mout1, out1, ple2), atest = false; end | |
378 if ~eq(mout2, out2, ple2), atest = false; end | |
379 % </AlgoCode> | |
380 else | |
381 atest = false; | |
382 end | |
383 | |
384 % Return a result structure | |
385 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
386 end % END UTP_06 | |
387 | |
388 %% UTP_07 | |
389 | |
390 % <TestDescription> | |
391 % | |
392 % Tests that the mpower method can modify the input AO. | |
393 % | |
394 % </TestDescription> | |
395 function result = utp_07 | |
396 | |
397 % <SyntaxDescription> | |
398 % | |
399 % Test that the mpower method can modify the input AO by calling with no | |
400 % output and that the method doesn't change the input of the function | |
401 % notation (with a equal sign). | |
402 % | |
403 % </SyntaxDescription> | |
404 | |
405 try | |
406 % <SyntaxCode> | |
407 % copy at4 to work with | |
408 ain = ao(at4); | |
409 % modify ain | |
410 aout = ain.mpower(5); | |
411 ain ^ 5; | |
412 % </SyntaxCode> | |
413 stest = true; | |
414 catch err | |
415 disp(err.message) | |
416 stest = false; | |
417 end | |
418 | |
419 % <AlgoDescription> | |
420 % | |
421 % 1) Check that 'at4' and 'ain' are now different. | |
422 % 2) Check that 'ain' is mpower(at4). | |
423 % | |
424 % </AlgoDescription> | |
425 | |
426 atest = true; | |
427 if stest | |
428 % <AlgoCode> | |
429 % Check that mpower modified the input by comparing to the copy | |
430 if eq(ao(at4), ain, ple1), atest = false; end | |
431 % Check that mpower doesn't modified the input for the function notation | |
432 if ~eq(aout, ain, ple1), atest = false; end | |
433 % Check that the modified input is the mpower value of the copy | |
434 if ~isequal(mpower(at4.y, 5), ain.y), atest = false; end | |
435 % </AlgoCode> | |
436 else | |
437 atest = false; | |
438 end | |
439 | |
440 % Return a result structure | |
441 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
442 end % END UTP_07 | |
443 | |
444 %% UTP_08 | |
445 | |
446 % <TestDescription> | |
447 % | |
448 % Test the shape of the output. | |
449 % | |
450 % </TestDescription> | |
451 function result = utp_08 | |
452 | |
453 % <SyntaxDescription> | |
454 % | |
455 % Test that the mpower method keeps the data shape of the input object. The | |
456 % input AO must be an AO with row data and an AO with column data. | |
457 % | |
458 % </SyntaxDescription> | |
459 | |
460 try | |
461 % <SyntaxCode> | |
462 % This UTP doesn't make sense because the AO must contain a square matrix | |
463 % </SyntaxCode> | |
464 stest = true; | |
465 catch err | |
466 disp(err.message) | |
467 stest = false; | |
468 end | |
469 | |
470 % <AlgoDescription> | |
471 % | |
472 % 1) Nothinf to check | |
473 % | |
474 % </AlgoDescription> | |
475 | |
476 atest = true; | |
477 if stest | |
478 % <AlgoCode> | |
479 % </AlgoCode> | |
480 else | |
481 atest = false; | |
482 end | |
483 | |
484 % Return a result structure | |
485 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
486 end % END UTP_08 | |
487 | |
488 end |