Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_search.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_SEARCH a set of UTPs for the ao/search method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_search.m,v 1.6 2010/09/01 13:58:17 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The search method of the ao class selects AOs that match the given name. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_search(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'search'; | |
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 output of the data | |
43 | |
44 disp('Done.'); | |
45 disp('******************************************************'); | |
46 | |
47 elseif nargin == 1 % Check for UTP functions | |
48 if strcmp(varargin{1}, 'isutp') | |
49 results = 1; | |
50 else | |
51 results = 0; | |
52 end | |
53 else | |
54 error('### Incorrect inputs') | |
55 end | |
56 | |
57 %% UTP_01 | |
58 | |
59 % <TestDescription> | |
60 % | |
61 % Tests that the getInfo call works for this method. | |
62 % | |
63 % </TestDescription> | |
64 function result = utp_01 | |
65 | |
66 | |
67 % <SyntaxDescription> | |
68 % | |
69 % Test that the getInfo call works for no sets, all sets, and each set | |
70 % individually. | |
71 % | |
72 % </SyntaxDescription> | |
73 | |
74 try | |
75 % <SyntaxCode> | |
76 % Call for no sets | |
77 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
78 % Call for all sets | |
79 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
80 % Call for each set | |
81 for kk=1:numel(io(2).sets) | |
82 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
83 end | |
84 % </SyntaxCode> | |
85 stest = true; | |
86 catch err | |
87 disp(err.message) | |
88 stest = false; | |
89 end | |
90 | |
91 % <AlgoDescription> | |
92 % | |
93 % 1) Check that getInfo call returned an minfo object in all cases. | |
94 % 2) Check that all plists have the correct parameters. | |
95 % | |
96 % </AlgoDescription> | |
97 | |
98 atest = true; | |
99 if stest | |
100 % <AlgoCode> | |
101 % check we have minfo objects | |
102 if isa(io, 'minfo') | |
103 %%% SET 'None' | |
104 if ~isempty(io(1).sets), atest = false; end | |
105 if ~isempty(io(1).plists), atest = false; end | |
106 %%% Check all Sets | |
107 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
108 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
109 %%%%%%%%%% SET 'Default' | |
110 if io(3).plists.nparams ~= 2, atest = false; end | |
111 % Check key | |
112 if ~io(3).plists.isparam('regexp'), atest = false; end | |
113 if ~io(3).plists.isparam('exact'), atest = false; end | |
114 % Check default value | |
115 if ~isEmptyChar(io(3).plists.find('regexp')), atest = false; end | |
116 if ~isequal(io(3).plists.find('exact'), false), atest = false; end | |
117 % Check options | |
118 if ~isequal(io(3).plists.getOptionsForParam('regexp'), {''}), atest = false; end | |
119 if ~isequal(io(3).plists.getOptionsForParam('exact'), {false, true}), atest = false; end | |
120 end | |
121 % </AlgoCode> | |
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 search 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 search method works for a vector of AOs as input. | |
142 % | |
143 % </SyntaxDescription> | |
144 | |
145 try | |
146 % <SyntaxCode> | |
147 % Get all AOs with the regular expression '.*' | |
148 out1 = search(atvec, '.*'); | |
149 % Get only the AO with the name 'at5' | |
150 out2 = search(atvec, 'at5'); | |
151 % </SyntaxCode> | |
152 stest = true; | |
153 catch err | |
154 disp(err.message) | |
155 stest = false; | |
156 end | |
157 | |
158 % <AlgoDescription> | |
159 % | |
160 % 1) Check that the number of elements in 'out1' are the same as in 'atvec' | |
161 % 2) Check that the number of elements in 'out2' | |
162 % 3) Check that each output AO contains the correct data. | |
163 % | |
164 % </AlgoDescription> | |
165 | |
166 atest = true; | |
167 if stest | |
168 % <AlgoCode> | |
169 % Check we have the correct number of outputs | |
170 if ~isequal(size(out1), size(atvec)), atest = false; end | |
171 if numel(out2) ~= 1, atest = false; end | |
172 % Check the output except the history because the output have | |
173 % one additionally history step | |
174 if ~eq(out1, atvec, 'hist', 'UUID'), atest = false; end | |
175 if ~eq(out2, at5, 'hist', 'UUID'), atest = false; end | |
176 % </AlgoCode> | |
177 else | |
178 atest = false; | |
179 end | |
180 | |
181 % Return a result structure | |
182 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
183 end % END UTP_02 | |
184 | |
185 %% UTP_03 | |
186 | |
187 % <TestDescription> | |
188 % | |
189 % Tests that the search method works with a matrix of AOs as input. | |
190 % | |
191 % </TestDescription> | |
192 function result = utp_03 | |
193 | |
194 % <SyntaxDescription> | |
195 % | |
196 % Test that the search method works for a matrix of AOs as input. | |
197 % | |
198 % </SyntaxDescription> | |
199 | |
200 try | |
201 % <SyntaxCode> | |
202 % Get all AOs with the regular expression '.*' | |
203 out1 = search(atmat, '.*'); | |
204 % Get only the AO with the name 'at5' | |
205 out2 = search(atmat, 'at5'); | |
206 % </SyntaxCode % </SyntaxCode> | |
207 stest = true; | |
208 catch err | |
209 disp(err.message) | |
210 stest = false; | |
211 end | |
212 | |
213 % <AlgoDescription> | |
214 % | |
215 % 1) Check that the number of elements in 'out1' are the same as in 'atmat' | |
216 % 2) Check that the number of elements in 'out2' | |
217 % 3) Check that each output AO contains the correct data. | |
218 % | |
219 % </AlgoDescription> | |
220 | |
221 atest = true; | |
222 if stest | |
223 % <AlgoCode> | |
224 % Check we have the correct number of outputs | |
225 if ~isequal(numel(out1), numel(atmat)), atest = false; end | |
226 if numel(out2) ~= 1, atest = false; end | |
227 % Check the output except the history because the output have | |
228 % one additionally history step | |
229 if ~eq(reshape(out1, size(atmat)), atmat, 'hist', 'UUID'), atest = false; end | |
230 if ~eq(out2, at5, 'hist', 'UUID'), 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 search method works with a list of AOs as input. | |
245 % | |
246 % </TestDescription> | |
247 function result = utp_04 | |
248 | |
249 % <SyntaxDescription> | |
250 % | |
251 % Test that the search method works for a list of AOs as input. | |
252 % | |
253 % </SyntaxDescription> | |
254 | |
255 try | |
256 % <SyntaxCode> | |
257 % Get all AOs with the regular expression '.*' | |
258 out1 = search(at1,at2,at3, '.*'); | |
259 % Get only the AO with the name 'at5' | |
260 out2 = search(at1,at2,at3, 'at3'); | |
261 % </SyntaxCode> | |
262 stest = true; | |
263 catch err | |
264 disp(err.message) | |
265 stest = false; | |
266 end | |
267 | |
268 % <AlgoDescription> | |
269 % | |
270 % 1) Check that the number of elements in 'out1' are the same as the input | |
271 % 2) Check that the number of elements in 'out2' | |
272 % 3) Check that each output AO contains the correct data. | |
273 % | |
274 % </AlgoDescription> | |
275 | |
276 atest = true; | |
277 if stest | |
278 % <AlgoCode> | |
279 % Check we have the correct number of outputs | |
280 if numel(out1) ~= 3, atest = false; end | |
281 if numel(out2) ~= 1, atest = false; end | |
282 % Check the output except the history because the output have | |
283 % one additionally history step | |
284 if ~eq(out1, [at1, at2, at3], 'hist', 'UUID'), atest = false; end | |
285 if ~eq(out2, at3, 'hist', 'UUID'), atest = false; end | |
286 % </AlgoCode> | |
287 else | |
288 atest = false; | |
289 end | |
290 | |
291 % Return a result structure | |
292 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
293 end % END UTP_04 | |
294 | |
295 %% UTP_05 | |
296 | |
297 % <TestDescription> | |
298 % | |
299 % Tests that the search method works with a mix of different shaped AOs as | |
300 % input. | |
301 % | |
302 % </TestDescription> | |
303 function result = utp_05 | |
304 | |
305 % <SyntaxDescription> | |
306 % | |
307 % Test that the search method works with an input of matrices and vectors | |
308 % and single AOs. | |
309 % | |
310 % </SyntaxDescription> | |
311 | |
312 try | |
313 % <SyntaxCode> | |
314 % Get all AOs with the regular expression '.*' | |
315 out1 = search(at1,atvec,at2,atmat,at3, '.*'); | |
316 % Get only the AO with the name 'at5' | |
317 out2 = search(at1,atvec,at2,atmat,at3, 'at3'); | |
318 % Negative test with the name 'foo' | |
319 out3 = search(at1,atvec,at2,atmat,at3, 'foo'); | |
320 % </SyntaxCode> | |
321 stest = true; | |
322 catch err | |
323 disp(err.message) | |
324 stest = false; | |
325 end | |
326 | |
327 % <AlgoDescription> | |
328 % | |
329 % 1) Check that the number of elements in 'out1' are the same as the input | |
330 % 2) Check that the number of elements in 'out2' | |
331 % 3) Check that 'out3' doesn't contain an AO | |
332 % 4) Check that each output AO contains the correct data. | |
333 % | |
334 % </AlgoDescription> | |
335 | |
336 atest = true; | |
337 aoin = [at1,reshape(atvec,1,[]),at2,reshape(atmat,1,[]),at3]; | |
338 if stest | |
339 % <AlgoCode> | |
340 % Check we have the correct number of outputs | |
341 if numel(out1) ~= 3+numel(atvec)+numel(atmat), atest = false; end | |
342 if numel(out2) ~= 2, atest = false; end | |
343 if numel(out3) ~= 0, atest = false; end | |
344 % Check the output except the history because the output have | |
345 % one additionally history step | |
346 if ~eq(out1, aoin, 'hist', 'UUID'), atest = false; end | |
347 if ~eq(out2, [at3, at3], 'hist', 'UUID'), atest = false; end | |
348 if ~isempty(out3), atest = false; end | |
349 % </AlgoCode> | |
350 else | |
351 atest = false; | |
352 end | |
353 | |
354 % Return a result structure | |
355 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
356 end % END UTP_05 | |
357 | |
358 %% UTP_06 | |
359 | |
360 % <TestDescription> | |
361 % | |
362 % Tests that the search method properly applies history. | |
363 % | |
364 % </TestDescription> | |
365 function result = utp_06 | |
366 | |
367 % <SyntaxDescription> | |
368 % | |
369 % Test that the result of applying the search method can be processed back. | |
370 % | |
371 % </SyntaxDescription> | |
372 | |
373 try | |
374 % <SyntaxCode> | |
375 out1 = search(atmat, 'at[45]'); | |
376 out2 = search(atmat, plist('regexp', 'at[45]', 'exact', false)); | |
377 out3 = search(atmat, plist('regexp', 'at4', 'exact', true)); | |
378 mout1 = rebuild(out1); | |
379 mout2 = rebuild(out2); | |
380 mout3 = rebuild(out3); | |
381 % </SyntaxCode> | |
382 stest = true; | |
383 catch err | |
384 disp(err.message) | |
385 stest = false; | |
386 end | |
387 | |
388 % <AlgoDescription> | |
389 % | |
390 % 1) Check that the last entry in the history of 'out' corresponds to | |
391 % 'search'. | |
392 % 2) Check that the re-built object is the same object as the input. | |
393 % | |
394 % </AlgoDescription> | |
395 | |
396 atest = true; | |
397 if stest | |
398 % <AlgoCode> | |
399 % Check the last step in the history of 'out' | |
400 if ~strcmp(out1(1).hist.methodInfo.mname, 'search'), atest = false; end | |
401 if ~strcmp(out1(2).hist.methodInfo.mname, 'search'), atest = false; end | |
402 if ~strcmp(out2(1).hist.methodInfo.mname, 'search'), atest = false; end | |
403 if ~strcmp(out2(2).hist.methodInfo.mname, 'search'), atest = false; end | |
404 if ~strcmp(out3.hist.methodInfo.mname, 'search'), atest = false; end | |
405 % The rebuilt object must be the same as 'out' | |
406 if ~eq(mout1, out1, ple2), atest = false; end | |
407 if ~eq(mout2, out2, ple2), atest = false; end | |
408 if ~eq(mout3, out3, ple2), atest = false; end | |
409 % </AlgoCode> | |
410 else | |
411 atest = false; | |
412 end | |
413 | |
414 % Return a result structure | |
415 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
416 end % END UTP_06 | |
417 | |
418 %% UTP_07 | |
419 | |
420 % <TestDescription> | |
421 % | |
422 % Tests that the modifier call for the search method doesn't work. | |
423 % | |
424 % </TestDescription> | |
425 function result = utp_07 | |
426 | |
427 % <SyntaxDescription> | |
428 % | |
429 % Tests that the modifier call for the search method doesn't work. | |
430 % | |
431 % </SyntaxDescription> | |
432 | |
433 try | |
434 % <SyntaxCode> | |
435 atvec.search('at2'); | |
436 % </SyntaxCode> | |
437 stest = false; | |
438 catch err | |
439 disp(err.message) | |
440 stest = true; | |
441 end | |
442 | |
443 % <AlgoDescription> | |
444 % | |
445 % </AlgoDescription> | |
446 | |
447 atest = true; | |
448 if stest | |
449 % <AlgoCode> | |
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 % Check that the search method pass back the output objects to a list of | |
464 % output variables or to a single variable. | |
465 % | |
466 % </TestDescription> | |
467 function result = utp_08 | |
468 | |
469 % <SyntaxDescription> | |
470 % | |
471 % Call the method with a list of output variables and with a single output | |
472 % variable. Additionaly check that the rebuild method works on the output. | |
473 % | |
474 % </SyntaxDescription> | |
475 | |
476 try | |
477 % <SyntaxCode> | |
478 [o1, o2] = search(at5, at6, 'at'); | |
479 o3 = search(at5, at6, 'at'); | |
480 mout1 = rebuild(o1); | |
481 mout2 = rebuild(o2); | |
482 mout3 = rebuild(o3); | |
483 % </SyntaxCode> | |
484 stest = true; | |
485 catch err | |
486 disp(err.message) | |
487 stest = false; | |
488 end | |
489 | |
490 % <AlgoDescription> | |
491 % | |
492 % 1) Check that the output contains the right number of objects | |
493 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
494 % | |
495 % </AlgoDescription> | |
496 | |
497 atest = true; | |
498 if stest | |
499 % <AlgoCode> | |
500 % Check the number of outputs | |
501 if numel(o1) ~=1, atest = false; end | |
502 if numel(o2) ~=1, atest = false; end | |
503 if numel(o3) ~=2, atest = false; end | |
504 % Check the rebuilding of the object | |
505 if ~eq(o1, mout1, ple2), atest = false; end | |
506 if ~eq(o2, mout2, ple2), atest = false; end | |
507 if ~eq(o3, mout3, 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 end |