Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_setZ.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_SETZ a set of UTPs for the ao/setZ method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_setZ.m,v 1.11 2011/04/19 18:14:01 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The setZ method of the ao class sets the 'z' property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_setZ(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'setZ'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test AOs | |
29 % pl = plist('type', 'xyzdata', 'xvals', randn(12,1), 'yvals', randn(15,1), 'zvals', randn(15,12)); | |
30 % at7 = ao(pl); | |
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]; % Set the property with a plist | |
44 % results = [results utp_09]; % Test output of the data | |
45 % results = [results utp_11(mthd, at1, ple1, plist('z', ))]; % Test plotinfo doesn't disappear | |
46 | |
47 disp('Done.'); | |
48 disp('******************************************************'); | |
49 | |
50 elseif nargin == 1 % Check for UTP functions | |
51 if strcmp(varargin{1}, 'isutp') | |
52 results = 1; | |
53 else | |
54 results = 0; | |
55 end | |
56 else | |
57 error('### Incorrect inputs') | |
58 end | |
59 | |
60 %% UTP_01 | |
61 | |
62 % <TestDescription> | |
63 % | |
64 % Tests that the getInfo call works for this method. | |
65 % | |
66 % </TestDescription> | |
67 function result = utp_01 | |
68 | |
69 | |
70 % <SyntaxDescription> | |
71 % | |
72 % Test that the getInfo call works for no sets, all sets, and each set | |
73 % individually. | |
74 % | |
75 % </SyntaxDescription> | |
76 | |
77 try | |
78 % <SyntaxCode> | |
79 % Call for no sets | |
80 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
81 % Call for all sets | |
82 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
83 % Call for each set | |
84 for kk=1:numel(io(2).sets) | |
85 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
86 end | |
87 % </SyntaxCode> | |
88 stest = true; | |
89 catch err | |
90 disp(err.message) | |
91 stest = false; | |
92 end | |
93 | |
94 % <AlgoDescription> | |
95 % | |
96 % 1) Check that getInfo call returned an minfo object in all cases. | |
97 % 2) Check that all plists have the correct parameters. | |
98 % | |
99 % </AlgoDescription> | |
100 | |
101 atest = true; | |
102 if stest | |
103 % <AlgoCode> | |
104 % check we have minfo objects | |
105 if isa(io, 'minfo') | |
106 %%% SET 'None' | |
107 if ~isempty(io(1).sets), atest = false; end | |
108 if ~isempty(io(1).plists), atest = false; end | |
109 %%% Check all Sets | |
110 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
111 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
112 %%%%%%%%%% SET 'Default' | |
113 if io(3).plists.nparams ~= 1, atest = false; end | |
114 % Check key | |
115 if ~io(3).plists.isparam('z'), atest = false; end | |
116 % Check default value | |
117 if ~isEmptyDouble(io(3).plists.find('z')), atest = false; end | |
118 % Check options | |
119 if ~isequal(io(3).plists.getOptionsForParam('z'), {[]}), atest = false; end | |
120 % </AlgoCode> | |
121 end | |
122 else | |
123 atest = false; | |
124 end | |
125 | |
126 % Return a result structure | |
127 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
128 end % END UTP_01 | |
129 | |
130 %% UTP_02 | |
131 | |
132 % <TestDescription> | |
133 % | |
134 % Tests that the setZ method works with a vector of AOs as input. | |
135 % | |
136 % </TestDescription> | |
137 function result = utp_02 | |
138 | |
139 % <SyntaxDescription> | |
140 % | |
141 % Test that the setZ method works for a vector of AOs as input. | |
142 % | |
143 % </SyntaxDescription> | |
144 | |
145 try | |
146 % <SyntaxCode> | |
147 in = randn(12); | |
148 avec = [at7, at7, at7, at7]; | |
149 out = setZ(avec, in); | |
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 'avec' | |
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(avec)), atest = false; end | |
169 % Check 'z' field of each output | |
170 for kk=1:numel(out) | |
171 if ~isequal(out(kk).data.z, in), atest = false; break; end | |
172 end | |
173 % </AlgoCode> | |
174 else | |
175 atest = false; | |
176 end | |
177 | |
178 % Return a result structure | |
179 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
180 end % END UTP_02 | |
181 | |
182 %% UTP_03 | |
183 | |
184 % <TestDescription> | |
185 % | |
186 % Tests that the setZ method works with a matrix of AOs as input. | |
187 % | |
188 % </TestDescription> | |
189 function result = utp_03 | |
190 | |
191 % <SyntaxDescription> | |
192 % | |
193 % Test that the setZ method works for a matrix of AOs as input. | |
194 % | |
195 % </SyntaxDescription> | |
196 | |
197 try | |
198 % <SyntaxCode> | |
199 in = randn(12); | |
200 amat = [at7, at7, at7; at7, at7, at7]; | |
201 out = setZ(amat, in); | |
202 % </SyntaxCode> | |
203 stest = true; | |
204 catch err | |
205 disp(err.message) | |
206 stest = false; | |
207 end | |
208 | |
209 % <AlgoDescription> | |
210 % | |
211 % 1) Check that the number of elements in 'out' is the same as in 'amat' | |
212 % 2) Check that each output AO contains the correct data. | |
213 % | |
214 % </AlgoDescription> | |
215 | |
216 atest = true; | |
217 if stest | |
218 % <AlgoCode> | |
219 % Check we have the correct number of outputs | |
220 if ~isequal(size(out), size(amat)), atest = false; end | |
221 % Check 'z' field of each output | |
222 for kk=1:numel(out) | |
223 if ~isequal(out(kk).data.z, in), atest = false; break; end | |
224 end | |
225 % </AlgoCode> | |
226 else | |
227 atest = false; | |
228 end | |
229 | |
230 % Return a result structure | |
231 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
232 end % END UTP_03 | |
233 | |
234 %% UTP_04 | |
235 | |
236 % <TestDescription> | |
237 % | |
238 % Tests that the setZ method works with a list of AOs as input. | |
239 % | |
240 % </TestDescription> | |
241 function result = utp_04 | |
242 | |
243 % <SyntaxDescription> | |
244 % | |
245 % Test that the setZ method works for a list of AOs as input. | |
246 % | |
247 % </SyntaxDescription> | |
248 | |
249 try | |
250 % <SyntaxCode> | |
251 in = randn(12); | |
252 out = setZ(at7,at7,at7, in); | |
253 % </SyntaxCode> | |
254 stest = true; | |
255 catch err | |
256 disp(err.message) | |
257 stest = false; | |
258 end | |
259 | |
260 % <AlgoDescription> | |
261 % | |
262 % 1) Check that the number of elements in 'out' is the same as in | |
263 % input. | |
264 % 2) Check that each output AO contains the correct data. | |
265 % | |
266 % </AlgoDescription> | |
267 | |
268 atest = true; | |
269 if stest | |
270 % <AlgoCode> | |
271 % Check we have the correct number of outputs | |
272 if numel(out) ~= 3, atest = false; end | |
273 % Check each output against the input | |
274 if ~isequal(out(1).data.z, in), atest = false; end | |
275 if ~isequal(out(2).data.z, in), atest = false; end | |
276 if ~isequal(out(3).data.z, in), atest = false; end | |
277 % </AlgoCode> | |
278 else | |
279 atest = false; | |
280 end | |
281 | |
282 % Return a result structure | |
283 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
284 end % END UTP_04 | |
285 | |
286 %% UTP_05 | |
287 | |
288 % <TestDescription> | |
289 % | |
290 % Tests that the setZ method works with a mix of different shaped AOs as | |
291 % input. | |
292 % | |
293 % </TestDescription> | |
294 function result = utp_05 | |
295 | |
296 % <SyntaxDescription> | |
297 % | |
298 % Test that the setZ method works with an input of matrices and vectors | |
299 % and single AOs. | |
300 % | |
301 % </SyntaxDescription> | |
302 | |
303 try | |
304 % <SyntaxCode> | |
305 in = randn(12); | |
306 avec = [at7, at7, at7, at7]; | |
307 amat = [at7, at7, at7; at7, at7, at7]; | |
308 out = setZ(at7,avec,at7,amat,at7, in); | |
309 % </SyntaxCode> | |
310 stest = true; | |
311 catch err | |
312 disp(err.message) | |
313 stest = false; | |
314 end | |
315 | |
316 % <AlgoDescription> | |
317 % | |
318 % 1) Check that the number of elements in 'out' is the same as in | |
319 % input. | |
320 % 2) Check that each output AO contains the correct data. | |
321 % | |
322 % </AlgoDescription> | |
323 | |
324 atest = true; | |
325 if stest | |
326 % <AlgoCode> | |
327 % Check we have the correct number of outputs | |
328 if numel(out) ~= (3+numel(amat)+numel(avec)), atest = false; end | |
329 for kk=1:numel(out) | |
330 if ~isequal(out(kk).data.z, in), atest = false; break; end | |
331 end | |
332 % </AlgoCode> | |
333 else | |
334 atest = false; | |
335 end | |
336 | |
337 % Return a result structure | |
338 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
339 end % END UTP_05 | |
340 | |
341 %% UTP_06 | |
342 | |
343 % <TestDescription> | |
344 % | |
345 % Tests that the setZ method properly applies history and that the | |
346 % option 'internal' suppresses the history. | |
347 % | |
348 % </TestDescription> | |
349 function result = utp_06 | |
350 | |
351 % <SyntaxDescription> | |
352 % | |
353 % Test that the result of applying the setZ method can be processed back | |
354 % to an m-file. | |
355 % | |
356 % </SyntaxDescription> | |
357 | |
358 try | |
359 % <SyntaxCode> | |
360 in = randn(12); | |
361 out1 = setZ(at7, in); | |
362 out2 = testCallerIsMethod(@setZ, at7, in); | |
363 mout1 = rebuild (out1); | |
364 mout2 = rebuild (out2); | |
365 % </SyntaxCode> | |
366 stest = true; | |
367 catch err | |
368 disp(err.message) | |
369 stest = false; | |
370 end | |
371 | |
372 % <AlgoDescription> | |
373 % | |
374 % 1) Check that the last entry in the history of 'out1' corresponds to | |
375 % 'setZ'. | |
376 % 1) Check that the last entry in the history of 'out2' NOT corresponds to | |
377 % 'setZ'. | |
378 % 2) Check that the re-built object is the same object as 'out'. | |
379 % | |
380 % </AlgoDescription> | |
381 | |
382 atest = true; | |
383 if stest | |
384 % <AlgoCode> | |
385 % Check the last step in the history of 'out1' | |
386 if ~strcmp(out1.hist.methodInfo.mname, 'setZ'), atest = false; end | |
387 % Check the last step in the history of 'out2' | |
388 if strcmp(out2.hist.methodInfo.mname, 'setZ'), atest = false; end | |
389 % Check the re-built object | |
390 if ~eq(mout1, out1, ple2), atest = false; end | |
391 e = ple1.find('EXCEPTIONS'); | |
392 ple = plist('EXCEPTIONS', [e {'z'}]); | |
393 if ~eq(mout2, out2, ple), atest = false; end | |
394 % </AlgoCode> | |
395 else | |
396 atest = false; | |
397 end | |
398 | |
399 % Return a result structure | |
400 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
401 end % END UTP_06 | |
402 | |
403 %% UTP_07 | |
404 | |
405 % <TestDescription> | |
406 % | |
407 % Tests that the setZ method can modify the input AO. | |
408 % | |
409 % </TestDescription> | |
410 function result = utp_07 | |
411 | |
412 % <SyntaxDescription> | |
413 % | |
414 % Test that the setZ method can modify the input AO by calling with no | |
415 % output. | |
416 % | |
417 % </SyntaxDescription> | |
418 | |
419 try | |
420 % <SyntaxCode> | |
421 % copy at7 to work with | |
422 in = randn(12); | |
423 ain = ao(at7); | |
424 % modify ain | |
425 aout = ain.setZ(in); | |
426 ain.setZ(in); | |
427 % </SyntaxCode> | |
428 stest = true; | |
429 catch err | |
430 disp(err.message) | |
431 stest = false; | |
432 end | |
433 | |
434 % <AlgoDescription> | |
435 % | |
436 % 1) Check that 'at7' and 'ain' are now different. | |
437 % 2) Check that 'ain' has the correct 'z' field | |
438 % | |
439 % </AlgoDescription> | |
440 | |
441 atest = true; | |
442 if stest | |
443 % <AlgoCode> | |
444 % Check that setZ modified the input by comparing to the copy | |
445 if eq(ao(at7), ain, ple1), atest = false; end | |
446 % Check that setZ doesn't modified the input for the function notation | |
447 if ~eq(aout, ain, ple1), atest = false; end | |
448 % Check that the modified object contains the changed value | |
449 if ~isequal(ain.data.z, in), atest = false; end | |
450 % </AlgoCode> | |
451 else | |
452 atest = false; | |
453 end | |
454 | |
455 % Return a result structure | |
456 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
457 end % END UTP_07 | |
458 | |
459 %% UTP_08 | |
460 | |
461 % <TestDescription> | |
462 % | |
463 % Tests that the setZ method can set the property with a plist. | |
464 % | |
465 % </TestDescription> | |
466 function result = utp_08 | |
467 | |
468 % <SyntaxDescription> | |
469 % | |
470 % Test that the setZ method can modify the property 'z' | |
471 % with a value in a plist. | |
472 % | |
473 % </SyntaxDescription> | |
474 | |
475 try | |
476 % <SyntaxCode> | |
477 in = randn(12); | |
478 pl = plist('z', in); | |
479 out = at7.setZ(pl); | |
480 mout = rebuild(out); | |
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 'ain' has the correct z field | |
491 % 2) Check that the re-built object is the same object as 'out'. | |
492 % | |
493 % </AlgoDescription> | |
494 | |
495 atest = true; | |
496 if stest | |
497 % <AlgoCode> | |
498 % Check the field 'z' | |
499 if ~isequal(out.data.z, in), atest = false; end | |
500 % Check the re-built object | |
501 if ~eq(mout, out, ple2), atest = false; end | |
502 % </AlgoCode> | |
503 else | |
504 atest = false; | |
505 end | |
506 | |
507 % Return a result structure | |
508 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
509 end % END UTP_08 | |
510 | |
511 %% UTP_09 | |
512 | |
513 % <TestDescription> | |
514 % | |
515 % Check that the setZ method pass back the output objects to a list of | |
516 % output variables or to a single variable. | |
517 % | |
518 % </TestDescription> | |
519 function result = utp_09 | |
520 | |
521 % <SyntaxDescription> | |
522 % | |
523 % Call the method with a list of output variables and with a single output | |
524 % variable. Additionaly check that the rebuild method works on the output. | |
525 % | |
526 % </SyntaxDescription> | |
527 | |
528 try | |
529 % <SyntaxCode> | |
530 [o1, o2] = setZ(at7, at7, randn(12)); | |
531 o3 = setZ(at7, at7, randn(12)); | |
532 mout1 = rebuild(o1); | |
533 mout2 = rebuild(o2); | |
534 mout3 = rebuild(o3); | |
535 % </SyntaxCode> | |
536 stest = true; | |
537 catch err | |
538 disp(err.message) | |
539 stest = false; | |
540 end | |
541 | |
542 % <AlgoDescription> | |
543 % | |
544 % 1) Check that the output contains the right number of objects | |
545 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
546 % | |
547 % </AlgoDescription> | |
548 | |
549 atest = true; | |
550 if stest | |
551 % <AlgoCode> | |
552 % Check the number of outputs | |
553 if numel(o1) ~=1, atest = false; end | |
554 if numel(o2) ~=1, atest = false; end | |
555 if numel(o3) ~=2, atest = false; end | |
556 % Check the rebuilding of the object | |
557 if ~eq(o1, mout1, ple2), atest = false; end | |
558 if ~eq(o2, mout2, ple2), atest = false; end | |
559 if ~eq(o3, mout3, ple2), atest = false; end | |
560 % </AlgoCode> | |
561 else | |
562 atest = false; | |
563 end | |
564 | |
565 % Return a result structure | |
566 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
567 end % END UTP_09 | |
568 | |
569 end |