comparison testing/utp_1.1/utps/miir/utp_miir_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_MIIR_BSUBMIT a set of UTPs for the miir/bsubmit method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_miir_bsubmit.m,v 1.14 2010/08/18 09:25:55 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The bsubmit method of the miir 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_miir_bsubmit(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'miir';
23 mthd = 'bsubmit';
24
25 results = [];
26 disp('******************************************************');
27 disp(['**** Running UTPs for ' class '/' mthd]);
28 disp('******************************************************');
29
30 [iir1,iir2,iir3,iir4,iir5,iir6,iirv,iirm] = get_test_objects_miir;
31 plForAutoTest = plist('no dialog', true, 'use selector', false);
32
33 conn = utpGetConnection();
34 try
35
36 sinfo.conn = conn;
37 sinfo.experiment_title = 'utp_miir_bsubmit: submit miir';
38 sinfo.experiment_description = 'utp_miir_bsubmit: description';
39 sinfo.analysis_description = '<utp_miir_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 MIIR 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 MIIR objects as
189 % input.
190 %
191 % </SyntaxDescription>
192
193 try
194 % <SyntaxCode>
195 [ids, cids] = bsubmit(iirv, 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), ids(4));
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(iirv), atest = false; end
218 if numel(robjs2) ~= numel(iirv), atest = false; end
219 if numel(robjs3) ~= numel(iirv), atest = false; end
220 % Check the retrieved object against the submitted
221 if ~eq(iirv, [robjs1{:}]), atest = false; end
222 if ~eq(iirv, [robjs2{:}]), atest = false; end
223 if ~eq(iirv, [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 MIIR 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 MIIR objects
246 % as input.
247 %
248 % </SyntaxDescription>
249
250 try
251 % <SyntaxCode>
252 [ids, cids] = bsubmit(iirm, 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(iirm), atest = false; end
275 if numel(robjs2) ~= numel(iirm), atest = false; end
276 if numel(robjs3) ~= numel(iirm), atest = false; end
277 % Check the retrieved object against the submitted
278 if ~eq(iirm, reshape([robjs1{:}], size(iirm))), atest = false; end
279 if ~eq(iirm, reshape([robjs2{:}], size(iirm))), atest = false; end
280 if ~eq(iirm, reshape([robjs3{:}], size(iirm))), 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 MIIR 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 MIIR 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(iir1, 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}, iir1), 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}, iir1), 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}, iir1), atest = false; end
347 if ~eq(robjs3{2}, iir), atest = false; end
348 if ~eq(robjs3{3}, pl), 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 MIIR
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 MIIR 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, iirm, iir, iirv, 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(iirm) + numel(iirv), atest = false; end
401 if numel(robjs2) ~= 2 + numel(iirm) + numel(iirv), atest = false; end
402 % Check the retrieved object against the submitted
403 % Check robjs1
404 if ~eq(robjs1{1}, iirm(1)), atest = false; end
405 if ~eq(robjs1{2}, iirm(2)), atest = false; end
406 if ~eq(robjs1{3}, iirm(3)), atest = false; end
407 if ~eq(robjs1{4}, iirm(4)), atest = false; end
408 if ~eq(robjs1{5}, iirm(5)), atest = false; end
409 if ~eq(robjs1{6}, iirm(6)), atest = false; end
410 if ~eq(robjs1{7}, iir), atest = false; end
411 if ~eq(robjs1{8}, iirv(1)), atest = false; end
412 if ~eq(robjs1{9}, iirv(2)), atest = false; end
413 if ~eq(robjs1{10}, iirv(3)), atest = false; end
414 if ~eq(robjs1{11}, iirv(4)), atest = false; end
415 if ~eq(robjs1{12}, pl), atest = false; end
416 % Check robjs2
417 if ~isequalwithequalnans(robjs1, robjs2), atest = false; end
418 % </AlgoCode>
419 else
420 atest = false;
421 end
422
423 % Return a result structure
424 result = utp_prepare_result(atest, stest, dbstack, mfilename);
425 end % END UTP_05
426
427 %% UTP_06
428
429 % <TestDescription>
430 %
431 % Tthe bsubmit method properly applies history.
432 %
433 % </TestDescription>
434 function result = utp_06
435
436 % <SyntaxDescription>
437 %
438 % Tthe bsubmit method properly applies history.
439 %
440 % </SyntaxDescription>
441
442 try
443 % <SyntaxCode>
444 % </SyntaxCode>
445 stest = true;
446 catch err
447 disp(err.message)
448 stest = false;
449 end
450
451 % <AlgoDescription>
452 %
453 % 1) Nothing to test.
454 %
455 % </AlgoDescription>
456
457 atest = true;
458 if stest
459 % <AlgoCode>
460 % </AlgoCode>
461 else
462 atest = false;
463 end
464
465 % Return a result structure
466 result = utp_prepare_result(atest, stest, dbstack, mfilename);
467 end % END UTP_06
468
469 %% UTP_07
470
471 % <TestDescription>
472 %
473 % Check that the bsubmit method pass back the output objects to a list of
474 % output variables or to a single variable.
475 %
476 % </TestDescription>
477 function result = utp_07
478
479 % <SyntaxDescription>
480 %
481 % Call the method with a list of output variables and with a single
482 % output variable. Additionaly check that the rebuild method works on
483 % the output.
484 %
485 % </SyntaxDescription>
486
487 try
488 % <SyntaxCode>
489 [ids, cids] = bsubmit(iir1, iir2, sinfo, plForAutoTest);
490
491 [o1, o2] = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
492 o3 = ltpda_uo.retrieve(conn, 'binary', 'Collection', cids);
493 % </SyntaxCode>
494 stest = true;
495 catch err
496 disp(err.message)
497 stest = false;
498 end
499
500 % <AlgoDescription>
501 %
502 % 1) Check that the output contains the right number of objects
503 %
504 % </AlgoDescription>
505
506 atest = true;
507 if stest
508 % <AlgoCode>
509 % Check the number of outputs
510 if numel(o1) ~=1, atest = false; end
511 if numel(o2) ~=1, atest = false; end
512 if numel(o3) ~=2, atest = false; end
513 % Check the output
514 if ~eq(o1, iir1), atest = false; end
515 if ~eq(o2, iir2), atest = false; end
516 if ~eq(o3{1}, iir1), atest = false; end
517 if ~eq(o3{2}, iir2), atest = false; end
518 % </AlgoCode>
519 else
520 atest = false;
521 end
522
523 % Return a result structure
524 result = utp_prepare_result(atest, stest, dbstack, mfilename);
525 end % END UTP_07
526
527 end