Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_norm.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_NORM a set of UTPs for the ao/norm method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_norm.m,v 1.8 2011/04/17 10:47:22 hewitson Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The norm method of the ao class computes the norm of the y data. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_norm(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'norm'; | |
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 with additional plist with the key 'axis' | |
43 results = [results utp_09]; % 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 atest = check_axis_sets(io); | |
105 end | |
106 % </AlgoCode> | |
107 else | |
108 atest = false; | |
109 end | |
110 | |
111 % Return a result structure | |
112 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
113 end % END UTP_01 | |
114 | |
115 %% UTP_02 | |
116 | |
117 % <TestDescription> | |
118 % | |
119 % Tests that the norm method works with a vector of AOs as input. | |
120 % | |
121 % </TestDescription> | |
122 function result = utp_02 | |
123 | |
124 % <SyntaxDescription> | |
125 % | |
126 % Test that the norm method works for a vector of AOs as input. | |
127 % | |
128 % </SyntaxDescription> | |
129 | |
130 try | |
131 % <SyntaxCode> | |
132 atvec = [at4, at4, at4]; | |
133 out = norm(atvec); | |
134 % </SyntaxCode> | |
135 stest = true; | |
136 catch err | |
137 disp(err.message) | |
138 stest = false; | |
139 end | |
140 | |
141 % <AlgoDescription> | |
142 % | |
143 % 1) Check that the number of elements in 'out' is the same as in 'atvec' | |
144 % 2) Check that each output AO contains the correct data. | |
145 % | |
146 % </AlgoDescription> | |
147 | |
148 atest = true; | |
149 if stest | |
150 % <AlgoCode> | |
151 % Check we have the correct number of outputs | |
152 if ~isequal(size(out), size(atvec)), atest = false; end | |
153 % Check each output against the norm of the input | |
154 for kk=1:numel(out) | |
155 if ~isequal(norm(atvec(kk).data.getY), out(kk).data.getY) | |
156 atest = false; | |
157 break; | |
158 end | |
159 end | |
160 % </AlgoCode> | |
161 else | |
162 atest = false; | |
163 end | |
164 | |
165 % Return a result structure | |
166 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
167 end % END UTP_02 | |
168 | |
169 %% UTP_03 | |
170 | |
171 % <TestDescription> | |
172 % | |
173 % Tests that the norm method works with a matrix of AOs as input. | |
174 % | |
175 % </TestDescription> | |
176 function result = utp_03 | |
177 | |
178 % <SyntaxDescription> | |
179 % | |
180 % Test that the norm method works for a matrix of AOs as input. | |
181 % | |
182 % </SyntaxDescription> | |
183 | |
184 try | |
185 % <SyntaxCode> | |
186 atmat = [at4 at4 at4; at4 at4 at4]; | |
187 out = norm(atmat); | |
188 % </SyntaxCode> | |
189 stest = true; | |
190 catch err | |
191 disp(err.message) | |
192 stest = false; | |
193 end | |
194 | |
195 % <AlgoDescription> | |
196 % | |
197 % 1) Check that the number of elements in 'out' is the same as in 'atmat' | |
198 % 2) Check that each output AO contains the correct data. | |
199 % | |
200 % </AlgoDescription> | |
201 | |
202 atest = true; | |
203 if stest | |
204 % <AlgoCode> | |
205 % Check we have the correct number of outputs | |
206 if ~isequal(size(out), size(atmat)), atest = false; end | |
207 % Check each output against the norm of the input | |
208 for kk=1:numel(out) | |
209 if ~isequal(norm(atmat(kk).data.getY), out(kk).data.getY) | |
210 atest = false; | |
211 break; | |
212 end | |
213 end | |
214 % </AlgoCode> | |
215 else | |
216 atest = false; | |
217 end | |
218 | |
219 % Return a result structure | |
220 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
221 end % END UTP_03 | |
222 | |
223 %% UTP_04 | |
224 | |
225 % <TestDescription> | |
226 % | |
227 % Tests that the norm method works with a list of AOs as input. | |
228 % | |
229 % </TestDescription> | |
230 function result = utp_04 | |
231 | |
232 % <SyntaxDescription> | |
233 % | |
234 % Test that the norm method works for a list of AOs as input. | |
235 % | |
236 % </SyntaxDescription> | |
237 | |
238 try | |
239 % <SyntaxCode> | |
240 out = norm(at4, at4, at4); | |
241 % </SyntaxCode> | |
242 stest = true; | |
243 catch err | |
244 disp(err.message) | |
245 stest = false; | |
246 end | |
247 | |
248 % <AlgoDescription> | |
249 % | |
250 % 1) Check that the number of elements in 'out' is the same as in | |
251 % input. | |
252 % 2) Check that each output AO contains the correct data. | |
253 % | |
254 % </AlgoDescription> | |
255 | |
256 atest = true; | |
257 if stest | |
258 % <AlgoCode> | |
259 % Check we have the correct number of outputs | |
260 if numel(out) ~= 3, atest = false; end | |
261 % Check each output against the norm of the input | |
262 if ~isequal(norm(at4.data.getY), out(1).data.getY), atest = false; end | |
263 if ~isequal(norm(at4.data.getY), out(2).data.getY), atest = false; end | |
264 if ~isequal(norm(at4.data.getY), out(3).data.getY), atest = false; end | |
265 % </AlgoCode> | |
266 else | |
267 atest = false; | |
268 end | |
269 | |
270 % Return a result structure | |
271 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
272 end % END UTP_04 | |
273 | |
274 %% UTP_05 | |
275 | |
276 % <TestDescription> | |
277 % | |
278 % Tests that the norm method works with a mix of different shaped AOs as | |
279 % input. | |
280 % | |
281 % </TestDescription> | |
282 function result = utp_05 | |
283 | |
284 % <SyntaxDescription> | |
285 % | |
286 % Test that the norm method works with an input of matrices and vectors | |
287 % and single AOs. | |
288 % | |
289 % </SyntaxDescription> | |
290 | |
291 try | |
292 % <SyntaxCode> | |
293 atmat = [at4 at4; at4 at4]; | |
294 atvec = [at4 at4]; | |
295 out = norm(at4,atvec,at4,atmat,at4); | |
296 % </SyntaxCode> | |
297 stest = true; | |
298 catch err | |
299 disp(err.message) | |
300 stest = false; | |
301 end | |
302 | |
303 % <AlgoDescription> | |
304 % | |
305 % 1) Check that the number of elements in 'out' is the same as in | |
306 % input. | |
307 % 2) Check that each output AO contains the correct data. | |
308 % | |
309 % </AlgoDescription> | |
310 | |
311 atest = true; | |
312 if stest | |
313 % <AlgoCode> | |
314 % Check we have the correct number of outputs | |
315 if numel(out) ~= (3+numel(atmat)+numel(atvec)), atest = false; end | |
316 % Check the first input | |
317 nout = 1; | |
318 if ~isequal(norm(at4.data.getY), out(nout).data.getY), atest = false; end | |
319 nout = nout+1; | |
320 % Check the elements of the input vector | |
321 for jj=1:numel(atvec) | |
322 if ~isequal(norm(atvec(jj).data.getY), out(nout).data.getY), atest = false; end | |
323 nout = nout+1; | |
324 end | |
325 % Check the 3rd input | |
326 if ~isequal(norm(at4.data.getY), out(nout).data.getY), atest = false; end | |
327 nout = nout+1; | |
328 % Check the elements of the input matrix | |
329 for jj=1:numel(atmat) | |
330 if ~isequal(norm(atmat(jj).data.getY), out(nout).data.getY), atest = false; end | |
331 nout = nout+1; | |
332 end | |
333 % Check the last input | |
334 if ~isequal(norm(at4.data.getY), out(nout).data.getY), atest = false; end | |
335 % </AlgoCode> | |
336 else | |
337 atest = false; | |
338 end | |
339 | |
340 % Return a result structure | |
341 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
342 end % END UTP_05 | |
343 | |
344 %% UTP_06 | |
345 | |
346 % <TestDescription> | |
347 % | |
348 % Tests that the norm method properly applies history. | |
349 % | |
350 % </TestDescription> | |
351 function result = utp_06 | |
352 | |
353 % <SyntaxDescription> | |
354 % | |
355 % Test that the result of applying the norm method can be processed back | |
356 % to an m-file. | |
357 % | |
358 % </SyntaxDescription> | |
359 | |
360 try | |
361 % <SyntaxCode> | |
362 out = norm(at4); | |
363 mout = rebuild(out); | |
364 % </SyntaxCode> | |
365 stest = true; | |
366 catch err | |
367 disp(err.message) | |
368 stest = false; | |
369 end | |
370 | |
371 % <AlgoDescription> | |
372 % | |
373 % 1) Check that the last entry in the history of 'out' corresponds to | |
374 % 'norm'. | |
375 % 2) Check that the re-built object is the same object as 'out'. | |
376 % | |
377 % </AlgoDescription> | |
378 | |
379 atest = true; | |
380 if stest | |
381 % <AlgoCode> | |
382 % Check the last step in the history of 'out' | |
383 if ~strcmp(out.hist.methodInfo.mname, 'norm'), atest = false; end | |
384 % Check the re-built object | |
385 if ~eq(mout, out, ple2), atest = false; end | |
386 % </AlgoCode> | |
387 else | |
388 atest = false; | |
389 end | |
390 | |
391 % Return a result structure | |
392 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
393 end % END UTP_06 | |
394 | |
395 %% UTP_07 | |
396 | |
397 % <TestDescription> | |
398 % | |
399 % Tests that the norm method can modify the input AO. | |
400 % | |
401 % </TestDescription> | |
402 function result = utp_07 | |
403 | |
404 % <SyntaxDescription> | |
405 % | |
406 % Test that the norm method can modify the input AO by calling with no | |
407 % output and that the method doesn't change the input of the function | |
408 % notation (with a equal sign). | |
409 % | |
410 % </SyntaxDescription> | |
411 | |
412 try | |
413 % <SyntaxCode> | |
414 % copy at4 to work with | |
415 ain = ao(at4); | |
416 % modify ain | |
417 aout = ain.norm(); | |
418 ain.norm(); | |
419 % </SyntaxCode> | |
420 stest = true; | |
421 catch err | |
422 disp(err.message) | |
423 stest = false; | |
424 end | |
425 | |
426 % <AlgoDescription> | |
427 % | |
428 % 1) Check that 'at4' and 'ain' are now different. | |
429 % 2) Check that 'ain' is norm(at4). | |
430 % | |
431 % </AlgoDescription> | |
432 | |
433 atest = true; | |
434 if stest | |
435 % <AlgoCode> | |
436 % Check that norm modified the input by comparing to the copy | |
437 if eq(ao(at4), ain, ple1), atest = false; end | |
438 % Check that norm doesn't modified the input for the function notation | |
439 if ~eq(aout, ain, ple1), atest = false; end | |
440 % Check that the modified input is the norm value of the copy | |
441 if ~isequal(norm(at4.data.getY), ain.data.getY), atest = false; end | |
442 % </AlgoCode> | |
443 else | |
444 atest = false; | |
445 end | |
446 | |
447 % Return a result structure | |
448 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
449 end % END UTP_07 | |
450 | |
451 %% UTP_08 | |
452 | |
453 % <TestDescription> | |
454 % | |
455 % Control the method with a plist. | |
456 % | |
457 % </TestDescription> | |
458 function result = utp_08 | |
459 | |
460 % <SyntaxDescription> | |
461 % | |
462 % Test that the norm method can modify the single axis controlled by the | |
463 % plist and the resuld can be processed back to an m-file. | |
464 % | |
465 % </SyntaxDescription> | |
466 | |
467 try | |
468 % <SyntaxCode> | |
469 pl2 = plist('option', 2); | |
470 pl1 = plist('option', 1); | |
471 plinf = plist('option', inf); | |
472 plfro = plist('option', 'fro'); | |
473 out1 = norm(at4, pl2); | |
474 out2 = norm(at4, pl1); | |
475 out3 = norm(at4, plinf); | |
476 out4 = norm(at4, plfro); | |
477 mout1 = rebuild(out1); | |
478 mout2 = rebuild(out2); | |
479 mout3 = rebuild(out3); | |
480 mout4 = rebuild(out4); | |
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 norm method applies with different options | |
491 % 2) Check that the re-built objects are the same object as 'out[1..4]'. | |
492 % | |
493 % </AlgoDescription> | |
494 | |
495 atest = true; | |
496 if stest | |
497 % <AlgoCode> | |
498 % Check each output against the norm of the input | |
499 if ~isequal(norm(at4.data.getY, 2), out1.data.getY), atest = false; end | |
500 if ~isequal(norm(at4.data.getY, 1), out2.data.getY), atest = false; end | |
501 if ~isequal(norm(at4.data.getY, inf), out3.data.getY), atest = false; end | |
502 if ~isequal(norm(at4.data.getY, 'fro'), out4.data.getY), atest = false; end | |
503 % Check the re-built object | |
504 if ~eq(mout1, out1, ple2), atest = false; end | |
505 if ~eq(mout2, out2, ple2), atest = false; end | |
506 if ~eq(mout3, out3, ple2), atest = false; end | |
507 if ~eq(mout4, out4, ple2), atest = false; end | |
508 % </AlgoCode> | |
509 else | |
510 atest = false; | |
511 end | |
512 | |
513 % Return a result structure | |
514 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
515 end % END UTP_08 | |
516 | |
517 %% UTP_09 | |
518 | |
519 % <TestDescription> | |
520 % | |
521 % Control the method with a plist. | |
522 % | |
523 % </TestDescription> | |
524 function result = utp_09 | |
525 | |
526 % <SyntaxDescription> | |
527 % | |
528 % Test that the norm method keeps the data shape of the input object. The | |
529 % input AO must be an AO with row data and an AO with column data. | |
530 % | |
531 % </SyntaxDescription> | |
532 | |
533 try | |
534 % <SyntaxCode> | |
535 out1 = norm(at4); | |
536 out2 = norm(at4); | |
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 shpe of the data doesn't change. | |
547 % | |
548 % </AlgoDescription> | |
549 | |
550 atest = true; | |
551 if stest | |
552 % <AlgoCode> | |
553 % Check the shape of the output data | |
554 if size(out1.data.y) ~= size(norm(at4.data.y)), atest = false; end | |
555 if size(out2.data.y) ~= size(norm(at4.data.y)), atest = false; end | |
556 % </AlgoCode> | |
557 else | |
558 atest = false; | |
559 end | |
560 | |
561 % Return a result structure | |
562 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
563 end % END UTP_09 | |
564 | |
565 end |