Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_mtimes.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_MTIMES a set of UTPs for the ao/mtimes method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_mtimes.m,v 1.7 2011/02/17 21:19:03 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The mtimes method of the ao class computes the matrix product of the y data | |
11 % of the two inputs. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_mtimes(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'mtimes'; | |
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 ~= 0, atest = false; end | |
113 % Check key | |
114 % Check default value | |
115 % Check options | |
116 end | |
117 % </AlgoCode> | |
118 else | |
119 atest = false; | |
120 end | |
121 | |
122 % Return a result structure | |
123 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
124 end % END UTP_01 | |
125 | |
126 %% UTP_02 | |
127 | |
128 % <TestDescription> | |
129 % | |
130 % Tests that the mtimes method works with a vector of AOs as input. | |
131 % | |
132 % </TestDescription> | |
133 function result = utp_02 | |
134 | |
135 % <SyntaxDescription> | |
136 % | |
137 % Test that the mtimes method works for a vector of AOs as input. | |
138 % | |
139 % </SyntaxDescription> | |
140 | |
141 try | |
142 % <SyntaxCode> | |
143 % We need a vector of AOs all the same size. | |
144 % The shape of the data shouldn't have an effect to the algorithm. | |
145 avec = [at1 ao(3) ao(1)]; | |
146 out = mtimes(avec); | |
147 % </SyntaxCode> | |
148 stest = true; | |
149 catch err | |
150 disp(err.message) | |
151 stest = false; | |
152 end | |
153 | |
154 % <AlgoDescription> | |
155 % | |
156 % 1) Check that the number of elements in 'out' is 1 | |
157 % 2) Check that each output AO contains the correct data. | |
158 % 3) Check the y-units | |
159 % | |
160 % </AlgoDescription> | |
161 | |
162 atest = true; | |
163 if stest | |
164 % <AlgoCode> | |
165 % Check we have the one output | |
166 if numel(out) ~= 1, atest = false; end | |
167 % Check the output against the matrix product of the inputs | |
168 s = avec(1).data.getY; | |
169 for jj=2:numel(avec) | |
170 s = s * avec(jj).data.getY; | |
171 end | |
172 if ~isequal(s, out.data.getY), atest = false; end | |
173 % Check the y-units | |
174 if ~eq(out.yunits, at1.yunits), 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 mtimes 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 mtimes 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 = mtimes(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 % 3) Check that the output have the yunits of the AO which contains a yunits | |
216 % | |
217 % </AlgoDescription> | |
218 | |
219 atest = true; | |
220 if stest | |
221 % <AlgoCode> | |
222 % Check we have the correct number of outputs | |
223 if numel(out) ~= 1, atest = false; end | |
224 % Check the output against the matrix product of the inputs | |
225 s = amat(1).data.getY; | |
226 for kk=2:numel(amat) | |
227 s = s * amat(kk).data.getY; | |
228 end | |
229 if ~isequal(s, out.data.getY), atest = false; end | |
230 % Check the units | |
231 if ~eq(out.yunits, at4.yunits), atest = false; 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 mtimes 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 mtimes method works for a list of AOs as input. | |
253 % | |
254 % </SyntaxDescription> | |
255 | |
256 try | |
257 % <SyntaxCode> | |
258 out = mtimes(at1,ao(7),ao(4)); | |
259 % </SyntaxCode> | |
260 stest = true; | |
261 catch err | |
262 disp(err.message) | |
263 stest = false; | |
264 end | |
265 | |
266 % <AlgoDescription> | |
267 % | |
268 % 1) Check that the number of elements in 'out' is 1. | |
269 % 2) Check that each output AO contains the correct data. | |
270 % 3) Check the y-units | |
271 % | |
272 % </AlgoDescription> | |
273 | |
274 atest = true; | |
275 if stest | |
276 % <AlgoCode> | |
277 % Check we have the correct number of outputs | |
278 if numel(out) ~= 1, atest = false; end | |
279 % Check the output against the matrix product of the inputs | |
280 s = at1.data.getY * 7 * 4; | |
281 if ~isequal(s, out.data.getY), atest = false; end | |
282 % Check the units | |
283 if ~eq(out.yunits, at1.yunits), atest = false; end | |
284 % </AlgoCode> | |
285 else | |
286 atest = false; | |
287 end | |
288 | |
289 % Return a result structure | |
290 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
291 end % END UTP_04 | |
292 | |
293 %% UTP_05 | |
294 | |
295 % <TestDescription> | |
296 % | |
297 % Tests that the mtimes method works with a mix of different shaped AOs as | |
298 % input. | |
299 % | |
300 % </TestDescription> | |
301 function result = utp_05 | |
302 | |
303 % <SyntaxDescription> | |
304 % | |
305 % Test that the mtimes method works with an input of matrices and vectors | |
306 % and single AOs. | |
307 % | |
308 % </SyntaxDescription> | |
309 | |
310 try | |
311 % <SyntaxCode> | |
312 % We need a vector of AOs all the same size | |
313 avec = [ao(1) ao(2) ao(3)]; | |
314 % We need a matrix of AOs all the same size | |
315 amat = [ao(4) ao(5) ao(6); ao(7) ao(8) ao(9)]; | |
316 % Compute matrix product | |
317 out = mtimes(at5,avec,ao(10),amat,ao(11)); | |
318 % </SyntaxCode> | |
319 stest = true; | |
320 catch err | |
321 disp(err.message) | |
322 stest = false; | |
323 end | |
324 | |
325 % <AlgoDescription> | |
326 % | |
327 % 1) Check that the number of elements in 'out' is 1. | |
328 % 2) Check that each output AO contains the correct data. | |
329 % | |
330 % </AlgoDescription> | |
331 | |
332 atest = true; | |
333 if stest | |
334 % <AlgoCode> | |
335 % Check we have the correct number of outputs | |
336 if numel(out) ~= 1, atest = false; end | |
337 % Check the matrix product of all the inputs | |
338 s = at5.data.getY; | |
339 for jj=1:numel(avec) | |
340 s = s * avec(jj).data.getY; | |
341 end | |
342 s = s * 10; | |
343 for jj=1:numel(amat) | |
344 s = s * amat(jj).data.getY; | |
345 end | |
346 s = s * 11; | |
347 if ~isequal(s, out.data.getY), atest = false; end | |
348 % </AlgoCode> | |
349 else | |
350 atest = false; | |
351 end | |
352 | |
353 % Return a result structure | |
354 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
355 end % END UTP_05 | |
356 | |
357 %% UTP_06 | |
358 | |
359 % <TestDescription> | |
360 % | |
361 % Tests that the mtimes method properly applies history. | |
362 % | |
363 % </TestDescription> | |
364 function result = utp_06 | |
365 | |
366 % <SyntaxDescription> | |
367 % | |
368 % Test that the result of applying the mtimes method can be processed back | |
369 % with the rebuild method. | |
370 % | |
371 % </SyntaxDescription> | |
372 | |
373 try | |
374 % <SyntaxCode> | |
375 out = mtimes(ao([3;4]),ao([5 8])); | |
376 mout = rebuild(out); | |
377 % </SyntaxCode> | |
378 stest = true; | |
379 catch err | |
380 disp(err.message) | |
381 stest = false; | |
382 end | |
383 | |
384 % <AlgoDescription> | |
385 % | |
386 % 1) Check that the last entry in the history of 'out' corresponds to | |
387 % 'mtimes'. | |
388 % 2) Check that the rebuilt object is the same object as 'out'. | |
389 % | |
390 % </AlgoDescription> | |
391 | |
392 atest = true; | |
393 if stest | |
394 % <AlgoCode> | |
395 % Check the last step in the history of 'out' | |
396 if ~strcmp(out.hist.methodInfo.mname, 'mtimes'), atest = false; end | |
397 % Check the rebuilt object | |
398 if ~eq(mout, out, ple2), atest = false; end | |
399 % </AlgoCode> | |
400 % delete test file | |
401 else | |
402 atest = false; | |
403 end | |
404 | |
405 % Return a result structure | |
406 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
407 end % END UTP_06 | |
408 | |
409 %% UTP_07 | |
410 | |
411 % <TestDescription> | |
412 % | |
413 % Tests that the mtimes method can not be used as a modifier method. | |
414 % | |
415 % </TestDescription> | |
416 function result = utp_07 | |
417 | |
418 % <SyntaxDescription> | |
419 % | |
420 % Tests that the mtimes method can not be used as a modifier method. The | |
421 % command should fail. | |
422 % | |
423 % </SyntaxDescription> | |
424 | |
425 try | |
426 % <SyntaxCode> | |
427 % copy at1 to work with | |
428 ain = ao(at1); | |
429 % modify ain | |
430 aout = ain.mtimes(5); | |
431 ain * 5; | |
432 stest = false; | |
433 % </SyntaxCode> | |
434 catch err | |
435 disp(err.message) | |
436 stest = true; | |
437 end | |
438 | |
439 % <AlgoDescription> | |
440 % | |
441 % 1) Nothing to test. | |
442 % | |
443 % </AlgoDescription> | |
444 | |
445 atest = true; | |
446 if stest | |
447 % <AlgoCode> | |
448 % </AlgoCode> | |
449 else | |
450 atest = false; | |
451 end | |
452 | |
453 % Return a result structure | |
454 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
455 end % END UTP_07 | |
456 | |
457 %% UTP_08 | |
458 | |
459 % <TestDescription> | |
460 % | |
461 % Test the shape of the output. | |
462 % | |
463 % </TestDescription> | |
464 function result = utp_08 | |
465 | |
466 % <SyntaxDescription> | |
467 % | |
468 % Test that the mtimes method keeps the data shape of the input object. The | |
469 % input AO must be an AO with row data and an AO with column data. | |
470 % | |
471 % </SyntaxDescription> | |
472 | |
473 try | |
474 % <SyntaxCode> | |
475 out1 = at5 * 5; | |
476 out2 = 5 * at5; | |
477 out3 = at6 * 5; | |
478 out4 = 5 * at6; | |
479 % </SyntaxCode> | |
480 stest = true; | |
481 catch err | |
482 disp(err.message) | |
483 stest = false; | |
484 end | |
485 | |
486 % <AlgoDescription> | |
487 % | |
488 % 1) Check that the shpe of the data doesn't change. | |
489 % | |
490 % </AlgoDescription> | |
491 | |
492 atest = true; | |
493 if stest | |
494 % <AlgoCode> | |
495 % Check the shape of the output data | |
496 if size(out1.data.y, 1) ~= size(at5.data.y, 1), atest = false; end | |
497 if size(out2.data.y, 1) ~= size(at5.data.y, 1), atest = false; end | |
498 if size(out3.data.y, 2) ~= size(at6.data.y, 2), atest = false; end | |
499 if size(out4.data.y, 2) ~= size(at6.data.y, 2), atest = false; end | |
500 % Check y-units | |
501 if ~eq(out1.yunits, at5.yunits), atest = false; end | |
502 if ~eq(out2.yunits, at5.yunits), atest = false; end | |
503 if ~eq(out3.yunits, at6.yunits), atest = false; end | |
504 if ~eq(out4.yunits, at6.yunits), atest = false; end | |
505 % </AlgoCode> | |
506 else | |
507 atest = false; | |
508 end | |
509 | |
510 % Return a result structure | |
511 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
512 end % END UTP_08 | |
513 | |
514 %% UTP_09 | |
515 | |
516 % <TestDescription> | |
517 % | |
518 % Test the method with all data objects. | |
519 % | |
520 % </TestDescription> | |
521 function result = utp_09 | |
522 | |
523 % <SyntaxDescription> | |
524 % | |
525 % Test that the mtimes method works with cdata-, fsdata-, tsdata-, and xydata | |
526 % objects | |
527 % | |
528 % </SyntaxDescription> | |
529 | |
530 try | |
531 % <SyntaxCode> | |
532 out11 = at1 * 5; | |
533 out12 = 5 * at1; | |
534 out21 = at2 * 5; | |
535 out22 = 5 * at2; | |
536 out31 = at3 * 5; | |
537 out32 = 5 * at3; | |
538 out41 = at4 * 5; | |
539 out42 = 5 * at4; | |
540 % </SyntaxCode> | |
541 stest = true; | |
542 catch err | |
543 disp(err.message) | |
544 stest = false; | |
545 end | |
546 | |
547 % <AlgoDescription> | |
548 % | |
549 % 1) Check that the shpe of the data doesn't change. | |
550 % 2) Check that re-building of output is the same as the output | |
551 % | |
552 % </AlgoDescription> | |
553 | |
554 atest = true; | |
555 if stest | |
556 % <AlgoCode> | |
557 % Check the shape of the output data | |
558 if ~isequal(mtimes(at1.y, 5), out11.y), atest = false; end | |
559 if ~isequal(mtimes(at1.y, 5), out12.y), atest = false; end | |
560 if ~isequal(mtimes(at2.y, 5), out21.y), atest = false; end | |
561 if ~isequal(mtimes(at2.y, 5), out22.y), atest = false; end | |
562 if ~isequal(mtimes(at3.y, 5), out31.y), atest = false; end | |
563 if ~isequal(mtimes(at3.y, 5), out32.y), atest = false; end | |
564 if ~isequal(mtimes(at4.y, 5), out41.y), atest = false; end | |
565 if ~isequal(mtimes(at4.y, 5), out42.y), atest = false; end | |
566 % Check the rebuilding | |
567 if ~eq(rebuild(out11), out11, ple2), atest = false; end | |
568 if ~eq(rebuild(out12), out12, ple2), atest = false; end | |
569 if ~eq(rebuild(out21), out21, ple2), atest = false; end | |
570 if ~eq(rebuild(out22), out22, ple2), atest = false; end | |
571 if ~eq(rebuild(out31), out31, ple2), atest = false; end | |
572 if ~eq(rebuild(out32), out32, ple2), atest = false; end | |
573 if ~eq(rebuild(out41), out41, ple2), atest = false; end | |
574 if ~eq(rebuild(out42), out42, ple2), atest = false; end | |
575 % </AlgoCode> | |
576 else | |
577 atest = false; | |
578 end | |
579 | |
580 % Return a result structure | |
581 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
582 end % END UTP_09 | |
583 | |
584 end |