Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/parfrac/utp_parfrac_bsubmit.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_PARFRAC_BSUBMIT a set of UTPs for the parfrac/bsubmit method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_parfrac_bsubmit.m,v 1.13 2010/08/18 09:25:55 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The bsubmit method of the parfrac class submits a collection of objects | |
11 % in binary form to an LTPDA Repository. The type of the objects are | |
12 % independent. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_parfrac_bsubmit(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'parfrac'; | |
23 mthd = 'bsubmit'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 [pf1,pf2,pf3,pfv,pfm] = get_test_objects_parfrac; | |
31 plForAutoTest = plist('no dialog', true, 'use selector', false); | |
32 | |
33 try | |
34 conn = utpGetConnection(); | |
35 | |
36 sinfo.conn = conn; | |
37 sinfo.experiment_title = 'utp_parfrac_bsubmit: submit parfrac'; | |
38 sinfo.experiment_description = 'utp_parfrac_bsubmit: description'; | |
39 sinfo.analysis_description = '<utp_parfrac_bsubmit>'; | |
40 sinfo.quantity = 'none'; | |
41 sinfo.keywords = 'none'; | |
42 sinfo.reference_ids = ''; | |
43 sinfo.additional_comments = 'none'; | |
44 sinfo.additional_authors = 'no one'; | |
45 | |
46 % Exception list for the UTPs: | |
47 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
48 | |
49 % Run the tests | |
50 results = [results utp_01]; % getInfo call | |
51 results = [results utp_02]; % Vector input | |
52 results = [results utp_03]; % Matrix input | |
53 results = [results utp_04]; % List input | |
54 results = [results utp_05]; % Test with mixed input | |
55 results = [results utp_06]; % Test history is working | |
56 results = [results utp_07]; % Test output of the data | |
57 catch | |
58 end | |
59 | |
60 % Close connection | |
61 utpCloseConnection(conn) | |
62 | |
63 disp('Done.'); | |
64 disp('******************************************************'); | |
65 | |
66 elseif nargin == 1 % Check for UTP functions | |
67 if strcmp(varargin{1}, 'isutp') | |
68 results = 1; | |
69 elseif strcmpi(varargin{1}, 'needs repository') | |
70 results = 2; | |
71 else | |
72 results = 0; | |
73 end | |
74 else | |
75 error('### Incorrect inputs') | |
76 end | |
77 | |
78 %% UTP_01 | |
79 | |
80 % <TestDescription> | |
81 % | |
82 % Tests that the getInfo call works for this method. | |
83 % | |
84 % </TestDescription> | |
85 function result = utp_01 | |
86 | |
87 | |
88 % <SyntaxDescription> | |
89 % | |
90 % Test that the getInfo call works for no sets, all sets, and each set | |
91 % individually. | |
92 % | |
93 % </SyntaxDescription> | |
94 | |
95 try | |
96 % <SyntaxCode> | |
97 % Call for no sets | |
98 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
99 % Call for all sets | |
100 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
101 % Call for each set | |
102 for kk=1:numel(io(2).sets) | |
103 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
104 end | |
105 % </SyntaxCode> | |
106 stest = true; | |
107 catch err | |
108 disp(err.message) | |
109 stest = false; | |
110 end | |
111 | |
112 % <AlgoDescription> | |
113 % | |
114 % 1) Check that getInfo call returned an minfo object in all cases. | |
115 % 2) Check that all plists have the correct parameters. | |
116 % | |
117 % </AlgoDescription> | |
118 | |
119 atest = true; | |
120 if stest | |
121 % <AlgoCode> | |
122 % check we have minfo objects | |
123 if isa(io, 'minfo') | |
124 prefs = getappdata(0, 'LTPDApreferences'); | |
125 hosts = utils.helper.jArrayList2CellArray(prefs.getRepoPrefs.getHostnames()); | |
126 % SET 'None' | |
127 if ~isempty(io(1).sets), atest = false; end | |
128 if ~isempty(io(1).plists), atest = false; end | |
129 % Check all Sets | |
130 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
131 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
132 % SET 'Default' | |
133 % Check key | |
134 if io(3).plists.nparams ~= 15, atest = false; end | |
135 if ~io(3).plists.isparam('hostname'), atest = false; end | |
136 if ~io(3).plists.isparam('database'), atest = false; end | |
137 if ~io(3).plists.isparam('username'), atest = false; end | |
138 if ~io(3).plists.isparam('password'), atest = false; end | |
139 if ~io(3).plists.isparam('experiment title'), atest = false; end | |
140 if ~io(3).plists.isparam('experiment description'), atest = false; end | |
141 if ~io(3).plists.isparam('analysis description'), atest = false; end | |
142 if ~io(3).plists.isparam('quantity'), atest = false; end | |
143 if ~io(3).plists.isparam('keywords'), atest = false; end | |
144 if ~io(3).plists.isparam('reference ids'), atest = false; end | |
145 if ~io(3).plists.isparam('additional comments'), atest = false; end | |
146 if ~io(3).plists.isparam('additional authors'), atest = false; end | |
147 if ~io(3).plists.isparam('no dialog'), atest = false; end | |
148 if ~io(3).plists.isparam('use selector'), atest = false; end | |
149 if ~io(3).plists.isparam('sinfo filename'), atest = false; end | |
150 % Check default value | |
151 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end | |
152 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end | |
153 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end | |
154 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end | |
155 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end | |
156 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end | |
157 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end | |
158 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end | |
159 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end | |
160 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end | |
161 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end | |
162 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end | |
163 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end | |
164 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end | |
165 if ~isEmptyChar(io(3).plists.find('sinfo filename')), atest = false; end | |
166 end | |
167 % </AlgoCode> | |
168 else | |
169 atest = false; | |
170 end | |
171 | |
172 % Return a result structure | |
173 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
174 end % END UTP_01 | |
175 | |
176 %% UTP_02 | |
177 | |
178 % <TestDescription> | |
179 % | |
180 % Tests that the bsubmit method works with a vector of PARFRAC objects as | |
181 % input. | |
182 % | |
183 % </TestDescription> | |
184 function result = utp_02 | |
185 | |
186 % <SyntaxDescription> | |
187 % | |
188 % Test that the bsubmit method works for a vector of PARFRAC objects as | |
189 % input. | |
190 % | |
191 % </SyntaxDescription> | |
192 | |
193 try | |
194 % <SyntaxCode> | |
195 [ids, cids] = bsubmit(pfv, sinfo, plForAutoTest); | |
196 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
197 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
198 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3)); | |
199 % </SyntaxCode> | |
200 stest = true; | |
201 catch err | |
202 disp(err.message) | |
203 stest = false; | |
204 end | |
205 | |
206 % <AlgoDescription> | |
207 % | |
208 % 1) Check the number of retrieved objects. | |
209 % 2) Check that the retrieved object is the same as the submitted | |
210 % | |
211 % </AlgoDescription> | |
212 | |
213 atest = true; | |
214 if stest | |
215 % <AlgoCode> | |
216 % Check we have the correct number of outputs | |
217 if numel(robjs1) ~= numel(pfv), atest = false; end | |
218 if numel(robjs2) ~= numel(pfv), atest = false; end | |
219 if numel(robjs3) ~= numel(pfv), atest = false; end | |
220 % Check the retrieved object against the submitted | |
221 if ~eq(pfv, [robjs1{:}]), atest = false; end | |
222 if ~eq(pfv, [robjs2{:}]), atest = false; end | |
223 if ~eq(pfv, [robjs3{:}]), atest = false; end | |
224 % </AlgoCode> | |
225 else | |
226 atest = false; | |
227 end | |
228 | |
229 % Return a result structure | |
230 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
231 end % END UTP_02 | |
232 | |
233 %% UTP_03 | |
234 | |
235 % <TestDescription> | |
236 % | |
237 % Tests that the bsubmit method works with a matrix of PARFRAC objects as | |
238 % input. | |
239 % | |
240 % </TestDescription> | |
241 function result = utp_03 | |
242 | |
243 % <SyntaxDescription> | |
244 % | |
245 % Tests that the bsubmit method works with a matrix of PARFRAC objects | |
246 % as input. | |
247 % | |
248 % </SyntaxDescription> | |
249 | |
250 try | |
251 % <SyntaxCode> | |
252 [ids, cids] = bsubmit(pfm, sinfo, plForAutoTest); | |
253 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
254 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
255 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3), ids(4), ids(5), ids(6)); | |
256 % </SyntaxCode> | |
257 stest = true; | |
258 catch err | |
259 disp(err.message) | |
260 stest = false; | |
261 end | |
262 | |
263 % <AlgoDescription> | |
264 % | |
265 % 1) Check the number of retrieved objects. | |
266 % 2) Check that the retrieved object is the same as the submitted | |
267 % | |
268 % </AlgoDescription> | |
269 | |
270 atest = true; | |
271 if stest | |
272 % <AlgoCode> | |
273 % Check we have the correct number of outputs | |
274 if numel(robjs1) ~= numel(pfm), atest = false; end | |
275 if numel(robjs2) ~= numel(pfm), atest = false; end | |
276 if numel(robjs3) ~= numel(pfm), atest = false; end | |
277 % Check the retrieved object against the submitted | |
278 if ~eq(pfm, reshape([robjs1{:}], size(pfm))), atest = false; end | |
279 if ~eq(pfm, reshape([robjs2{:}], size(pfm))), atest = false; end | |
280 if ~eq(pfm, reshape([robjs3{:}], size(pfm))), atest = false; end | |
281 % </AlgoCode> | |
282 else | |
283 atest = false; | |
284 end | |
285 | |
286 % Return a result structure | |
287 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
288 end % END UTP_03 | |
289 | |
290 %% UTP_04 | |
291 | |
292 % <TestDescription> | |
293 % | |
294 % Tests that the bsubmit method works with a list of PARFRAC objects as | |
295 % input. | |
296 % | |
297 % </TestDescription> | |
298 function result = utp_04 | |
299 | |
300 % <SyntaxDescription> | |
301 % | |
302 % Tests that the bsubmit method works with a list of PARFRAC objects as | |
303 % input. Use for this a mix of different object types. | |
304 % | |
305 % </SyntaxDescription> | |
306 | |
307 try | |
308 % <SyntaxCode> | |
309 pl = plist('key1', 'val', 'key2', 2); | |
310 iir = miir(plist('type', 'highpass')); | |
311 [ids, cids] = bsubmit(pf1, pl, iir, sinfo, plForAutoTest); | |
312 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
313 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
314 robjs3 = ltpda_uo.retrieve(conn, 'binary', ids(1), ids(2), ids(3)); | |
315 % </SyntaxCode> | |
316 stest = true; | |
317 catch err | |
318 disp(err.message) | |
319 stest = false; | |
320 end | |
321 | |
322 % <AlgoDescription> | |
323 % | |
324 % 1) Check the number of retrieved objects. | |
325 % 2) Check that the retrieved object is the same as the submitted | |
326 % | |
327 % </AlgoDescription> | |
328 | |
329 atest = true; | |
330 if stest | |
331 % <AlgoCode> | |
332 % Check we have the correct number of outputs | |
333 if numel(robjs1) ~= 3, atest = false; end | |
334 if numel(robjs2) ~= 3, atest = false; end | |
335 if numel(robjs3) ~= 3, atest = false; end | |
336 % Check the retrieved object against the submitted | |
337 % Check robjs1 | |
338 if ~eq(robjs1{1}, pf1), atest = false; end | |
339 if ~eq(robjs1{3}, pl), atest = false; end | |
340 if ~eq(robjs1{2}, iir), atest = false; end | |
341 % Check robjs2 | |
342 if ~eq(robjs2{1}, pf1), atest = false; end | |
343 if ~eq(robjs2{3}, pl), atest = false; end | |
344 if ~eq(robjs2{2}, iir), atest = false; end | |
345 % Check robjs3 | |
346 if ~eq(robjs3{1}, pf1), atest = false; end | |
347 if ~eq(robjs3{3}, pl), atest = false; end | |
348 if ~eq(robjs3{2}, iir), 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_04 | |
357 | |
358 %% UTP_05 | |
359 | |
360 % <TestDescription> | |
361 % | |
362 % Tests that the abs method works with a mix of different shaped PARFRAC | |
363 % objects as input. | |
364 % | |
365 % </TestDescription> | |
366 function result = utp_05 | |
367 | |
368 % <SyntaxDescription> | |
369 % | |
370 % Tests that the bsubmit method works with a list of PARFRAC objects as | |
371 % input. Use for this a mix of different object types. | |
372 % | |
373 % </SyntaxDescription> | |
374 | |
375 try | |
376 % <SyntaxCode> | |
377 pl = plist('key1', 'val', 'key2', 2); | |
378 iir = miir(plist('type', 'highpass')); | |
379 [ids, cids] = bsubmit(pl, pfm, iir, pfv, sinfo, plForAutoTest); | |
380 robjs1 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
381 robjs2 = ltpda_uo.retrieve(conn, 'binary', ids); | |
382 % </SyntaxCode> | |
383 stest = true; | |
384 catch err | |
385 disp(err.message) | |
386 stest = false; | |
387 end | |
388 | |
389 % <AlgoDescription> | |
390 % | |
391 % 1) Check the number of retrieved objects. | |
392 % 2) Check that the retrieved object is the same as the submitted | |
393 % | |
394 % </AlgoDescription> | |
395 | |
396 atest = true; | |
397 if stest | |
398 % <AlgoCode> | |
399 % Check we have the correct number of outputs | |
400 if numel(robjs1) ~= 2 + numel(pfm) + numel(pfv), atest = false; end | |
401 if numel(robjs2) ~= 2 + numel(pfm) + numel(pfv), atest = false; end | |
402 % Check the retrieved object against the submitted | |
403 % Check robjs1 | |
404 if ~eq(robjs1{1}, pfm(1)), atest = false; end | |
405 if ~eq(robjs1{2}, pfm(2)), atest = false; end | |
406 if ~eq(robjs1{3}, pfm(3)), atest = false; end | |
407 if ~eq(robjs1{4}, pfm(4)), atest = false; end | |
408 if ~eq(robjs1{5}, pfm(5)), atest = false; end | |
409 if ~eq(robjs1{6}, pfm(6)), atest = false; end | |
410 if ~eq(robjs1{7}, iir), atest = false; end | |
411 if ~eq(robjs1{8}, pfv(1)), atest = false; end | |
412 if ~eq(robjs1{9}, pfv(2)), atest = false; end | |
413 if ~eq(robjs1{10}, pfv(3)), atest = false; end | |
414 if ~eq(robjs1{11}, pl), atest = false; end | |
415 % Check robjs2 | |
416 if ~isequalwithequalnans(robjs1, robjs2), atest = false; end | |
417 % </AlgoCode> | |
418 else | |
419 atest = false; | |
420 end | |
421 | |
422 % Return a result structure | |
423 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
424 end % END UTP_05 | |
425 | |
426 %% UTP_06 | |
427 | |
428 % <TestDescription> | |
429 % | |
430 % Tthe bsubmit method properly applies history. | |
431 % | |
432 % </TestDescription> | |
433 function result = utp_06 | |
434 | |
435 % <SyntaxDescription> | |
436 % | |
437 % Tthe bsubmit method properly applies history. | |
438 % | |
439 % </SyntaxDescription> | |
440 | |
441 try | |
442 % <SyntaxCode> | |
443 % </SyntaxCode> | |
444 stest = true; | |
445 catch err | |
446 disp(err.message) | |
447 stest = false; | |
448 end | |
449 | |
450 % <AlgoDescription> | |
451 % | |
452 % 1) Nothing to test. | |
453 % | |
454 % </AlgoDescription> | |
455 | |
456 atest = true; | |
457 if stest | |
458 % <AlgoCode> | |
459 % </AlgoCode> | |
460 else | |
461 atest = false; | |
462 end | |
463 | |
464 % Return a result structure | |
465 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
466 end % END UTP_06 | |
467 | |
468 %% UTP_07 | |
469 | |
470 % <TestDescription> | |
471 % | |
472 % Check that the bsubmit method pass back the output objects to a list of | |
473 % output variables or to a single variable. | |
474 % | |
475 % </TestDescription> | |
476 function result = utp_07 | |
477 | |
478 % <SyntaxDescription> | |
479 % | |
480 % Call the method with a list of output variables and with a single | |
481 % output variable. Additionaly check that the rebuild method works on | |
482 % the output. | |
483 % | |
484 % </SyntaxDescription> | |
485 | |
486 try | |
487 % <SyntaxCode> | |
488 [ids, cids] = bsubmit(pf1, pf2, sinfo, plForAutoTest); | |
489 | |
490 [o1, o2] = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
491 o3 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids); | |
492 % </SyntaxCode> | |
493 stest = true; | |
494 catch err | |
495 disp(err.message) | |
496 stest = false; | |
497 end | |
498 | |
499 % <AlgoDescription> | |
500 % | |
501 % 1) Check that the output contains the right number of objects | |
502 % | |
503 % </AlgoDescription> | |
504 | |
505 atest = true; | |
506 if stest | |
507 % <AlgoCode> | |
508 % Check the number of outputs | |
509 if numel(o1) ~=1, atest = false; end | |
510 if numel(o2) ~=1, atest = false; end | |
511 if numel(o3) ~=2, atest = false; end | |
512 % Check the output | |
513 if ~eq(o1, pf1), atest = false; end | |
514 if ~eq(o2, pf2), atest = false; end | |
515 if ~eq(o3{1}, pf1), atest = false; end | |
516 if ~eq(o3{2}, pf2), atest = false; end | |
517 % </AlgoCode> | |
518 else | |
519 atest = false; | |
520 end | |
521 | |
522 % Return a result structure | |
523 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
524 end % END UTP_07 | |
525 | |
526 end |