comparison testing/utp_1.1/utps/rational/utp_rational_submit.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_RATIONAL_SUBMIT a set of UTPs for the rational/submit method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_rational_submit.m,v 1.13 2010/08/18 09:25:56 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The bsubmit method of the rational class submits a collection of objects
11 % in XML form to an LTPDA Repository. The type of the objects are
12 % independent.
13 %
14 % </MethodDescription>
15
16 function results = utp_rational_submit(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'rational';
23 mthd = 'submit';
24
25 results = [];
26 disp('******************************************************');
27 disp(['**** Running UTPs for ' class '/' mthd]);
28 disp('******************************************************');
29
30 [ra1,ra2,ra3,rav,ram] = get_test_objects_rational;
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_rational_submit: submit rational';
38 sinfo.experiment_description = 'utp_rational_submit: description';
39 sinfo.analysis_description = '<utp_rational_submit>';
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 ~= 16, 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 if ~io(3).plists.isparam('binary'), atest = false; end
151 % Check default value
152 if ~isequal(io(3).plists.find('hostname'), hosts{1}), atest = false; end
153 if ~isEmptyChar(io(3).plists.find('database')), atest = false; end
154 if ~isEmptyChar(io(3).plists.find('username')), atest = false; end
155 if ~isEmptyChar(io(3).plists.find('password')), atest = false; end
156 if ~isEmptyChar(io(3).plists.find('experiment title')), atest = false; end
157 if ~isEmptyChar(io(3).plists.find('experiment description')), atest = false; end
158 if ~isEmptyChar(io(3).plists.find('analysis description')), atest = false; end
159 if ~isEmptyChar(io(3).plists.find('quantity')), atest = false; end
160 if ~isEmptyChar(io(3).plists.find('keywords')), atest = false; end
161 if ~isEmptyChar(io(3).plists.find('reference ids')), atest = false; end
162 if ~isEmptyChar(io(3).plists.find('additional comments')), atest = false; end
163 if ~isEmptyChar(io(3).plists.find('additional authors')), atest = false; end
164 if ~isequal(io(3).plists.find('no dialog'), false), atest = false; end
165 if ~isequal(io(3).plists.find('use selector'), true), atest = false; end
166 if ~isEmptyChar(io(3).plists.find('sinfo filename')), atest = false; end
167 if ~isequal(io(3).plists.find('binary'), false), atest = false; end
168 end
169 % </AlgoCode>
170 else
171 atest = false;
172 end
173
174 % Return a result structure
175 result = utp_prepare_result(atest, stest, dbstack, mfilename);
176 end % END UTP_01
177
178 %% UTP_02
179
180 % <TestDescription>
181 %
182 % Tests that the submit method works with a vector of RATIONAL objects as
183 % input.
184 %
185 % </TestDescription>
186 function result = utp_02
187
188 % <SyntaxDescription>
189 %
190 % Test that the submit method works for a vector of RATIONAL objects as
191 % input.
192 %
193 % </SyntaxDescription>
194
195 try
196 % <SyntaxCode>
197 [ids, cids] = submit(rav, sinfo, plForAutoTest);
198 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
199 robjs2 = ltpda_uo.retrieve(conn, ids);
200 robjs3 = ltpda_uo.retrieve(conn, ids(1), ids(2), ids(3));
201 % </SyntaxCode>
202 stest = true;
203 catch err
204 disp(err.message)
205 stest = false;
206 end
207
208 % <AlgoDescription>
209 %
210 % 1) Check the number of retrieved objects.
211 % 2) Check that the retrieved object is the same as the submitted
212 %
213 % </AlgoDescription>
214
215 atest = true;
216 if stest
217 % <AlgoCode>
218 % Check we have the correct number of outputs
219 if numel(robjs1) ~= numel(rav), atest = false; end
220 if numel(robjs2) ~= numel(rav), atest = false; end
221 if numel(robjs3) ~= numel(rav), atest = false; end
222 % Check the retrieved object against the submitted
223 if ~eq(rav, [robjs1{:}]), atest = false; end
224 if ~eq(rav, [robjs2{:}]), atest = false; end
225 if ~eq(rav, [robjs3{:}]), atest = false; end
226 % </AlgoCode>
227 else
228 atest = false;
229 end
230
231 % Return a result structure
232 result = utp_prepare_result(atest, stest, dbstack, mfilename);
233 end % END UTP_02
234
235 %% UTP_03
236
237 % <TestDescription>
238 %
239 % Tests that the submit method works with a matrix of RATIONAL objects as
240 % input.
241 %
242 % </TestDescription>
243 function result = utp_03
244
245 % <SyntaxDescription>
246 %
247 % Tests that the submit method works with a matrix of RATIONAL objects
248 % as input.
249 %
250 % </SyntaxDescription>
251
252 try
253 % <SyntaxCode>
254 [ids, cids] = submit(ram, sinfo, plForAutoTest);
255 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
256 robjs2 = ltpda_uo.retrieve(conn, ids);
257 robjs3 = ltpda_uo.retrieve(conn, ids(1), ids(2), ids(3), ids(4), ids(5), ids(6));
258 % </SyntaxCode>
259 stest = true;
260 catch err
261 disp(err.message)
262 stest = false;
263 end
264
265 % <AlgoDescription>
266 %
267 % 1) Check the number of retrieved objects.
268 % 2) Check that the retrieved object is the same as the submitted
269 %
270 % </AlgoDescription>
271
272 atest = true;
273 if stest
274 % <AlgoCode>
275 % Check we have the correct number of outputs
276 if numel(robjs1) ~= numel(ram), atest = false; end
277 if numel(robjs2) ~= numel(ram), atest = false; end
278 if numel(robjs3) ~= numel(ram), atest = false; end
279 % Check the retrieved object against the submitted
280 if ~eq(ram, reshape([robjs1{:}], size(ram))), atest = false; end
281 if ~eq(ram, reshape([robjs2{:}], size(ram))), atest = false; end
282 if ~eq(ram, reshape([robjs3{:}], size(ram))), atest = false; end
283 % </AlgoCode>
284 else
285 atest = false;
286 end
287
288 % Return a result structure
289 result = utp_prepare_result(atest, stest, dbstack, mfilename);
290 end % END UTP_03
291
292 %% UTP_04
293
294 % <TestDescription>
295 %
296 % Tests that the submit method works with a list of RATIONAL objects as
297 % input.
298 %
299 % </TestDescription>
300 function result = utp_04
301
302 % <SyntaxDescription>
303 %
304 % Tests that the submit method works with a list of RATIONAL objects as
305 % input. Use for this a mix of different object types.
306 %
307 % </SyntaxDescription>
308
309 try
310 % <SyntaxCode>
311 pl = plist('key1', 'val', 'key2', 2);
312 iir = miir(plist('type', 'highpass'));
313 [ids, cids] = submit(ra1, pl, iir, sinfo, plForAutoTest);
314 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
315 robjs2 = ltpda_uo.retrieve(conn, ids);
316 robjs3 = ltpda_uo.retrieve(conn, ids(1), ids(2), ids(3));
317 % </SyntaxCode>
318 stest = true;
319 catch err
320 disp(err.message)
321 stest = false;
322 end
323
324 % <AlgoDescription>
325 %
326 % 1) Check the number of retrieved objects.
327 % 2) Check that the retrieved object is the same as the submitted
328 %
329 % </AlgoDescription>
330
331 atest = true;
332 if stest
333 % <AlgoCode>
334 % Check we have the correct number of outputs
335 if numel(robjs1) ~= 3, atest = false; end
336 if numel(robjs2) ~= 3, atest = false; end
337 if numel(robjs3) ~= 3, atest = false; end
338 % Check the retrieved object against the submitted
339 % Check robjs1
340 if ~eq(robjs1{1}, ra1), atest = false; end
341 if ~eq(robjs1{3}, pl), atest = false; end
342 if ~eq(robjs1{2}, iir), atest = false; end
343 % Check robjs2
344 if ~eq(robjs2{1}, ra1), atest = false; end
345 if ~eq(robjs2{3}, pl), atest = false; end
346 if ~eq(robjs2{2}, iir), atest = false; end
347 % Check robjs3
348 if ~eq(robjs3{1}, ra1), atest = false; end
349 if ~eq(robjs3{3}, pl), atest = false; end
350 if ~eq(robjs3{2}, iir), atest = false; end
351 % </AlgoCode>
352 else
353 atest = false;
354 end
355
356 % Return a result structure
357 result = utp_prepare_result(atest, stest, dbstack, mfilename);
358 end % END UTP_04
359
360 %% UTP_05
361
362 % <TestDescription>
363 %
364 % Tests that the abs method works with a mix of different shaped RATIONAL
365 % objects as input.
366 %
367 % </TestDescription>
368 function result = utp_05
369
370 % <SyntaxDescription>
371 %
372 % Tests that the submit method works with a list of RATIONAL objects as
373 % input. Use for this a mix of different object types.
374 %
375 % </SyntaxDescription>
376
377 try
378 % <SyntaxCode>
379 pl = plist('key1', 'val', 'key2', 2);
380 iir = miir(plist('type', 'highpass'));
381 [ids, cids] = submit(pl, ram, iir, rav, sinfo, plForAutoTest);
382 robjs1 = ltpda_uo.retrieve(conn, 'Collection', cids);
383 robjs2 = ltpda_uo.retrieve(conn, ids);
384 % </SyntaxCode>
385 stest = true;
386 catch err
387 disp(err.message)
388 stest = false;
389 end
390
391 % <AlgoDescription>
392 %
393 % 1) Check the number of retrieved objects.
394 % 2) Check that the retrieved object is the same as the submitted
395 %
396 % </AlgoDescription>
397
398 atest = true;
399 if stest
400 % <AlgoCode>
401 % Check we have the correct number of outputs
402 if numel(robjs1) ~= 2 + numel(ram) + numel(rav), atest = false; end
403 if numel(robjs2) ~= 2 + numel(ram) + numel(rav), atest = false; end
404 % Check the retrieved object against the submitted
405 % Check robjs1
406 if ~eq(robjs1{1}, ram(1)), atest = false; end
407 if ~eq(robjs1{2}, ram(2)), atest = false; end
408 if ~eq(robjs1{3}, ram(3)), atest = false; end
409 if ~eq(robjs1{4}, ram(4)), atest = false; end
410 if ~eq(robjs1{5}, ram(5)), atest = false; end
411 if ~eq(robjs1{6}, ram(6)), atest = false; end
412 if ~eq(robjs1{7}, iir), atest = false; end
413 if ~eq(robjs1{8}, rav(1)), atest = false; end
414 if ~eq(robjs1{9}, rav(2)), atest = false; end
415 if ~eq(robjs1{10}, rav(3)), atest = false; end
416 if ~eq(robjs1{11}, pl), atest = false; end
417 % Check robjs2
418 if ~isequalwithequalnans(robjs1, robjs2), atest = false; end
419 % </AlgoCode>
420 else
421 atest = false;
422 end
423
424 % Return a result structure
425 result = utp_prepare_result(atest, stest, dbstack, mfilename);
426 end % END UTP_05
427
428 %% UTP_06
429
430 % <TestDescription>
431 %
432 % Tthe submit method properly applies history.
433 %
434 % </TestDescription>
435 function result = utp_06
436
437 % <SyntaxDescription>
438 %
439 % Tthe submit method properly applies history.
440 %
441 % </SyntaxDescription>
442
443 try
444 % <SyntaxCode>
445 % </SyntaxCode>
446 stest = true;
447 catch err
448 disp(err.message)
449 stest = false;
450 end
451
452 % <AlgoDescription>
453 %
454 % 1) Nothing to test.
455 %
456 % </AlgoDescription>
457
458 atest = true;
459 if stest
460 % <AlgoCode>
461 % </AlgoCode>
462 else
463 atest = false;
464 end
465
466 % Return a result structure
467 result = utp_prepare_result(atest, stest, dbstack, mfilename);
468 end % END UTP_06
469
470 %% UTP_07
471
472 % <TestDescription>
473 %
474 % Check that the submit method pass back the output objects to a list of
475 % output variables or to a single variable.
476 %
477 % </TestDescription>
478 function result = utp_07
479
480 % <SyntaxDescription>
481 %
482 % Call the method with a list of output variables and with a single
483 % output variable. Additionaly check that the rebuild method works on
484 % the output.
485 %
486 % </SyntaxDescription>
487
488 try
489 % <SyntaxCode>
490 [ids, cids] = submit(ra1, ra2, sinfo, plForAutoTest);
491
492 [o1, o2] = ltpda_uo.retrieve(conn, 'Collection', cids);
493 o3 = ltpda_uo.retrieve(conn, 'Collection', cids);
494 % </SyntaxCode>
495 stest = true;
496 catch err
497 disp(err.message)
498 stest = false;
499 end
500
501 % <AlgoDescription>
502 %
503 % 1) Check that the output contains the right number of objects
504 %
505 % </AlgoDescription>
506
507 atest = true;
508 if stest
509 % <AlgoCode>
510 % Check the number of outputs
511 if numel(o1) ~=1, atest = false; end
512 if numel(o2) ~=1, atest = false; end
513 if numel(o3) ~=2, atest = false; end
514 % Check the output
515 if ~eq(o1, ra1), atest = false; end
516 if ~eq(o2, ra2), atest = false; end
517 if ~eq(o3{1}, ra1), atest = false; end
518 if ~eq(o3{2}, ra2), atest = false; end
519 % </AlgoCode>
520 else
521 atest = false;
522 end
523
524 % Return a result structure
525 result = utp_prepare_result(atest, stest, dbstack, mfilename);
526 end % END UTP_07
527
528 end