Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_index.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_INDEX a set of UTPs for the ao/index method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_index.m,v 1.6 2009/08/07 10:28:36 hewitson Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The index method of the ao class index into a AO vector or matrix. This | |
11 % properly captures the history. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_index(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'index'; | |
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] = get_test_objects_ao; | |
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 history is working | |
41 results = [results utp_06]; % Test the modify call works | |
42 results = [results utp_07]; % Test with plist | |
43 results = [results utp_08]; % Test select more objects with an index | |
44 | |
45 results = [results utp_11(mthd, at1, ple1, plist('i', 1))]; % 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 ~= 2, atest = false; end | |
114 % Check key | |
115 if ~io(3).plists.isparam('i'), atest = false; end | |
116 if ~io(3).plists.isparam('j'), atest = false; end | |
117 % Check default value | |
118 if ~isEmptyDouble(io(3).plists.find('i')), atest = false; end | |
119 if ~isEmptyDouble(io(3).plists.find('j')), atest = false; end | |
120 % Check options | |
121 if ~isequal(io(3).plists.getOptionsForParam('i'), {[]}), atest = false; end | |
122 if ~isequal(io(3).plists.getOptionsForParam('j'), {[]}), atest = false; end | |
123 end | |
124 % </AlgoCode> | |
125 else | |
126 atest = false; | |
127 end | |
128 | |
129 % Return a result structure | |
130 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
131 end % END UTP_01 | |
132 | |
133 %% UTP_02 | |
134 | |
135 % <TestDescription> | |
136 % | |
137 % Tests that the index method works with a vector of AOs as input. | |
138 % | |
139 % </TestDescription> | |
140 function result = utp_02 | |
141 | |
142 % <SyntaxDescription> | |
143 % | |
144 % Test that the index method works for a vector of AOs as input. The | |
145 % following indexing should work: | |
146 % I = [ 1 2 3 ] or (I/J) = [(1,1), (1,2), (1,3)] | |
147 % | |
148 % </SyntaxDescription> | |
149 | |
150 try | |
151 % <SyntaxCode> | |
152 objvec = [at1, at2, at3]; | |
153 out1 = objvec.index(1); | |
154 out2 = objvec.index(3); | |
155 out3 = objvec.index(1,2); | |
156 % </SyntaxCode> | |
157 stest = true; | |
158 catch err | |
159 disp(err.message) | |
160 stest = false; | |
161 end | |
162 | |
163 % <AlgoDescription> | |
164 % | |
165 % 1) Check that the index method selects the correct object. | |
166 % | |
167 % </AlgoDescription> | |
168 | |
169 atest = true; | |
170 if stest | |
171 % <AlgoCode> | |
172 if ~eq(out1, at1, ple3), atest = false; end | |
173 if ~eq(out2, at3, ple3), atest = false; end | |
174 if ~eq(out3, at2, ple3), 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 index 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 index method works for a matrix of AOs as input. The | |
196 % following indexing should work: | |
197 % I = [ 1 3 5 ] or (I/J) = [(1,1), (1,2), (1,3)] | |
198 % [ 2 4 6 ] [(2,1), (2,2), (2,3)] | |
199 % </SyntaxDescription> | |
200 | |
201 try | |
202 % <SyntaxCode> | |
203 objmat = [at1, at2, at3; ... | |
204 at3, at1, at2]; | |
205 out1 = objmat.index(5); | |
206 out2 = objmat.index(4); | |
207 out3 = objmat.index(1,2); | |
208 out4 = objmat.index(2,1); | |
209 out5 = objmat.index(2,2); | |
210 % </SyntaxCode> | |
211 stest = true; | |
212 catch err | |
213 disp(err.message) | |
214 stest = false; | |
215 end | |
216 | |
217 % <AlgoDescription> | |
218 % | |
219 % 1) Check that the index method selects the correct object. | |
220 % | |
221 % </AlgoDescription> | |
222 | |
223 atest = true; | |
224 if stest | |
225 % <AlgoCode> | |
226 if ~eq(out1, at3, ple3), atest = false; end | |
227 if ~eq(out2, at1, ple3), atest = false; end | |
228 if ~eq(out3, at2, ple3), atest = false; end | |
229 if ~eq(out4, at3, ple3), atest = false; end | |
230 if ~eq(out5, at1, ple3), atest = false; end | |
231 % </AlgoCode> | |
232 else | |
233 atest = false; | |
234 end | |
235 | |
236 % Return a result structure | |
237 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
238 end % END UTP_03 | |
239 | |
240 %% UTP_04 | |
241 | |
242 % <TestDescription> | |
243 % | |
244 % Tests that the index method works with a list of AOs as input. | |
245 % | |
246 % </TestDescription> | |
247 function result = utp_04 | |
248 | |
249 % <SyntaxDescription> | |
250 % | |
251 % The index method doesn't work for a list of AOs as input. | |
252 % | |
253 % </SyntaxDescription> | |
254 | |
255 try | |
256 % <SyntaxCode> | |
257 out = index(at1,at2,at3, 4); | |
258 % </SyntaxCode> | |
259 stest = false; | |
260 catch | |
261 stest = true; | |
262 end | |
263 | |
264 % <AlgoDescription> | |
265 % | |
266 % 1) Nothing to test. | |
267 % | |
268 % </AlgoDescription> | |
269 | |
270 atest = true; | |
271 if stest | |
272 % <AlgoCode> | |
273 % </AlgoCode> | |
274 else | |
275 atest = false; | |
276 end | |
277 | |
278 % Return a result structure | |
279 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
280 end % END UTP_04 | |
281 | |
282 %% UTP_05 | |
283 | |
284 % <TestDescription> | |
285 % | |
286 % Tests that the index method properly applies history. | |
287 % | |
288 % </TestDescription> | |
289 function result = utp_05 | |
290 | |
291 % <SyntaxDescription> | |
292 % | |
293 % Test that the result of index have an additional history step. | |
294 % | |
295 % </SyntaxDescription> | |
296 | |
297 try | |
298 % <SyntaxCode> | |
299 i = 2; | |
300 j = 3; | |
301 objmat = [at1, at2, at3; ... | |
302 at3, at1, at2]; | |
303 out = index(objmat, i, j); | |
304 % </SyntaxCode> | |
305 stest = true; | |
306 catch err | |
307 disp(err.message) | |
308 stest = false; | |
309 end | |
310 | |
311 % <AlgoDescription> | |
312 % | |
313 % 1) Check that the last entry in the history of 'out' corresponds | |
314 % to 'index'. | |
315 % | |
316 % </AlgoDescription> | |
317 | |
318 atest = true; | |
319 if stest | |
320 % <AlgoCode> | |
321 % Check the last step in the history of 'out' | |
322 if ~strcmp(out.hist.methodInfo.mname, 'index'), atest = false; end | |
323 % Check that the history-plist contains the used indices. | |
324 pl = out.hist.plistUsed; | |
325 if pl.find('i') ~= i, atest = false; end | |
326 if pl.find('j') ~= j, atest = false; end | |
327 % </AlgoCode> | |
328 else | |
329 atest = false; | |
330 end | |
331 | |
332 % Return a result structure | |
333 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
334 end % END UTP_05 | |
335 | |
336 %% UTP_06 | |
337 | |
338 % <TestDescription> | |
339 % | |
340 % Tests that the index method works for the modifier command. | |
341 % | |
342 % </TestDescription> | |
343 function result = utp_06 | |
344 | |
345 % <SyntaxDescription> | |
346 % | |
347 % Tests that the index method works for the modifier command. | |
348 % | |
349 % </SyntaxDescription> | |
350 | |
351 try | |
352 % <SyntaxCode> | |
353 i = 1; | |
354 j = 1; | |
355 objmat = [at1, at2, at3; ... | |
356 at3, at1, at2]; | |
357 out1 = index(objmat, i, j); | |
358 out2 = objmat.index(i,j); | |
359 % </SyntaxCode> | |
360 stest = true; | |
361 catch err | |
362 disp(err.message) | |
363 stest = false; | |
364 end | |
365 | |
366 % <AlgoDescription> | |
367 % | |
368 % 1) Check that the history-plist contains the used indices. | |
369 % 2) Check that the index method selects the correct object | |
370 % | |
371 % </AlgoDescription> | |
372 | |
373 atest = true; | |
374 if stest | |
375 % <AlgoCode> | |
376 % Check that the history-plist contains the used indices. | |
377 pl = out1.hist.plistUsed; | |
378 if pl.find('i') ~= i, atest = false; end | |
379 if pl.find('j') ~= j, atest = false; end | |
380 % Check that the index method selects the correct object | |
381 if ~eq(out1, at1, ple3), atest = false; end | |
382 % Check that the history-plist contains the used indices. | |
383 pl = out2.hist.plistUsed; | |
384 if pl.find('i') ~= i, atest = false; end | |
385 if pl.find('j') ~= j, atest = false; end | |
386 % Check that the index method selects the correct object | |
387 if ~eq(out2, at1, ple3), atest = false; end | |
388 % </AlgoCode> | |
389 else | |
390 atest = false; | |
391 end | |
392 | |
393 % Return a result structure | |
394 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
395 end % END UTP_06 | |
396 | |
397 %% UTP_07 | |
398 | |
399 % <TestDescription> | |
400 % | |
401 % Control the method with a plist. | |
402 % | |
403 % </TestDescription> | |
404 function result = utp_07 | |
405 | |
406 % <SyntaxDescription> | |
407 % | |
408 % Test that the index method can be controled with a plist. | |
409 % | |
410 % </SyntaxDescription> | |
411 | |
412 try | |
413 % <SyntaxCode> | |
414 i1 = 6; | |
415 i2 = 1; | |
416 j2 = 3; | |
417 objmat = [at1, at2, at3; ... | |
418 at3, at1, at2]; | |
419 pl1 = plist('i', i1); | |
420 pl2 = plist('i', i2, 'j', j2); | |
421 out1 = index(objmat, pl1); | |
422 out2 = index(objmat, pl2); | |
423 % </SyntaxCode> | |
424 stest = true; | |
425 catch err | |
426 disp(err.message) | |
427 stest = false; | |
428 end | |
429 | |
430 % <AlgoDescription> | |
431 % | |
432 % 1) Check that the history-plist contains the used indices. | |
433 % 2) Check that the index method selects the correct object | |
434 % | |
435 % </AlgoDescription> | |
436 | |
437 atest = true; | |
438 if stest | |
439 % <AlgoCode> | |
440 % Check that the history-plist contains the used indices. | |
441 pl = out1.hist.plistUsed; | |
442 if ~isequal(pl.find('i'), i1), atest = false; end | |
443 if ~isequal(pl.find('j'), []), atest = false; end | |
444 % Check that the index method selects the correct object | |
445 if ~eq(out1, at2, ple3), atest = false; end | |
446 % Check that the history-plist contains the used indices. | |
447 pl = out2.hist.plistUsed; | |
448 if ~isequal(pl.find('i'), i2), atest = false; end | |
449 if ~isequal(pl.find('j'), j2), atest = false; end | |
450 % Check that the index method selects the correct object | |
451 if ~eq(out2, at3, ple3), 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 that the index method selects more objects if I have more indices. | |
466 % | |
467 % </TestDescription> | |
468 function result = utp_08 | |
469 | |
470 % <SyntaxDescription> | |
471 % | |
472 % Test that the index method selects more objects if I have more indices. | |
473 % | |
474 % </SyntaxDescription> | |
475 | |
476 try | |
477 % <SyntaxCode> | |
478 i = [2 6]; | |
479 objmat = [at1, at2, at3; ... | |
480 at3, at1, at2]; | |
481 pl = plist('i', i); | |
482 out1 = objmat.index(i); | |
483 out2 = objmat.index(pl); | |
484 % </SyntaxCode> | |
485 stest = true; | |
486 catch err | |
487 disp(err.message) | |
488 stest = false; | |
489 end | |
490 | |
491 % <AlgoDescription> | |
492 % | |
493 % 1) Check that the history-plist contains the used indices. | |
494 % 2) Check that the index method selects the correct object | |
495 % | |
496 % </AlgoDescription> | |
497 | |
498 atest = true; | |
499 if stest | |
500 % <AlgoCode> | |
501 % Check that the history-plist contains the used indices. | |
502 pl = out1(1).hist.plistUsed; | |
503 if ~isequal(pl.find('i'), i), atest = false; end | |
504 if ~isequal(pl.find('j'), []), atest = false; end | |
505 % Check that the index method selects the correct object | |
506 if ~eq(out1(1), at3, ple3), atest = false; end | |
507 if ~eq(out1(2), at2, ple3), atest = false; end | |
508 % Check that the history-plist contains the used indices. | |
509 pl = out2(2).hist.plistUsed; | |
510 if ~isequal(pl.find('i'), i), atest = false; end | |
511 if ~isequal(pl.find('j'), []), atest = false; end | |
512 % Check that the index method selects the correct object | |
513 if ~eq(out2(1), at3, ple3), atest = false; end | |
514 if ~eq(out2(2), at2, ple3), atest = false; end | |
515 % </AlgoCode> | |
516 else | |
517 atest = false; | |
518 end | |
519 | |
520 % Return a result structure | |
521 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
522 end % END UTP_08 | |
523 | |
524 end |