comparison testing/utp_1.1/utps/ao/utp_ao_creator.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_CREATED a set of UTPs for the ao/creator method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_creator.m,v 1.4 2009/07/28 13:17:23 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The creator method of the ao extract the creator(s)/modifier from
11 % the history. Depending to the input parameter returns this method all
12 % creator/modifier or only the last creator/modifier.
13 %
14 % </MethodDescription>
15
16 function results = utp_ao_creator(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'ao';
23 mthd = 'creator';
24
25 results = [];
26 disp('******************************************************');
27 disp(['**** Running UTPs for ' class '/' mthd]);
28 disp('******************************************************');
29
30 % Test AOs
31 [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao;
32
33 % Exception list for the UTPs:
34 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
35
36 % Run the tests
37 results = [results utp_01]; % getInfo call
38 results = [results utp_02]; % Vector input
39 results = [results utp_03]; % Matrix input
40 results = [results utp_04]; % List input
41 results = [results utp_05]; % Test with mixed input
42 results = [results utp_06]; % Test history is working
43 results = [results utp_07]; % Test the modify call works
44 results = [results utp_08]; % Test with different creator/modifier
45 results = [results utp_09]; % Test negative case for the option 'all'
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 ~= 1, atest = false; end
114 % Check key
115 if ~io(3).plists.isparam('option'), atest = false; end
116 % Check default value
117 if ~isEmptyChar(io(3).plists.find('option')), atest = false; end
118 % Check options
119 if ~isequal(io(3).plists.getOptionsForParam('option'), {''}), 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 creator 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 creator method works for a vector of AOs as input.
142 %
143 % </SyntaxDescription>
144
145 try
146 % <SyntaxCode>
147 out = creator(atvec);
148 % </SyntaxCode>
149 stest = true;
150 catch err
151 disp(err.message)
152 stest = false;
153 end
154
155 % <AlgoDescription>
156 %
157 % 1) Check that the number of elements in 'out' is the same as in 'atvec'
158 % 2) Check that each output contains the correct data.
159 %
160 % </AlgoDescription>
161
162 atest = true;
163 if stest
164 % <AlgoCode>
165 % Check we have the correct number of outputs
166 if numel(out) ~= numel(atvec), atest = false; end
167 % Check the creator
168 curr_creator = provenance();
169 for kk=1:numel(out)
170 if ~strcmp(out{kk}, curr_creator.creator), atest = false; break; end
171 end
172 % </AlgoCode>
173 else
174 atest = false;
175 end
176
177 % Return a result structure
178 result = utp_prepare_result(atest, stest, dbstack, mfilename);
179 end % END UTP_02
180
181 %% UTP_03
182
183 % <TestDescription>
184 %
185 % Tests that the creator method works with a matrix of AOs as input.
186 %
187 % </TestDescription>
188 function result = utp_03
189
190 % <SyntaxDescription>
191 %
192 % Test that the creator method works for a matrix of AOs as input.
193 %
194 % </SyntaxDescription>
195
196 try
197 % <SyntaxCode>
198 out = creator(atmat);
199 % </SyntaxCode>
200 stest = true;
201 catch err
202 disp(err.message)
203 stest = false;
204 end
205
206 % <AlgoDescription>
207 %
208 % 1) Check that the number of elements in 'out' is the same as in 'atmat'
209 % 2) Check that each output contains the correct data.
210 %
211 % </AlgoDescription>
212
213 atest = true;
214 if stest
215 % <AlgoCode>
216 % Check we have the correct number of outputs
217 if numel(out) ~= numel(atmat), atest = false; end
218 % Check creator
219 curr_creator = provenance();
220 for kk=1:numel(out)
221 if ~strcmp(out{kk}, curr_creator.creator), atest = false; break; end
222 end
223 % </AlgoCode>
224 else
225 atest = false;
226 end
227
228 % Return a result structure
229 result = utp_prepare_result(atest, stest, dbstack, mfilename);
230 end % END UTP_03
231
232 %% UTP_04
233
234 % <TestDescription>
235 %
236 % Tests that the creator method works with a list of AOs as input.
237 %
238 % </TestDescription>
239 function result = utp_04
240
241 % <SyntaxDescription>
242 %
243 % The creator method doesn't work for a list of AOs as input.
244 %
245 % </SyntaxDescription>
246
247 % <SyntaxCode>
248 try
249 creator(at1,at2,at3);
250 stest = false;
251 catch
252 stest = true;
253 end
254 % </SyntaxCode>
255
256 % <AlgoDescription>
257 %
258 % 1) Nothing to test.
259 %
260 % </AlgoDescription>
261
262 atest = true;
263 if stest
264 % <AlgoCode>
265 % </AlgoCode>
266 else
267 atest = false;
268 end
269
270 % Return a result structure
271 result = utp_prepare_result(atest, stest, dbstack, mfilename);
272 end % END UTP_04
273
274 %% UTP_05
275
276 % <TestDescription>
277 %
278 % Tests that the creator method works with a mix of different shaped
279 % AOs as input.
280 %
281 % </TestDescription>
282 function result = utp_05
283
284 % <SyntaxDescription>
285 %
286 % The creator method doesn't work with different shaped input objects.
287 %
288 % </SyntaxDescription>
289
290 % <SyntaxCode>
291 try
292 creator(at1,atvec,at2,atmat,at3);
293 stest = false;
294 catch
295 stest = true;
296 end
297 % </SyntaxCode>
298
299 % <AlgoDescription>
300 %
301 % 1) Nothing to test
302 %
303 % </AlgoDescription>
304
305 atest = true;
306 if stest
307 % <AlgoCode>
308 % </AlgoCode>
309 else
310 atest = false;
311 end
312
313 % Return a result structure
314 result = utp_prepare_result(atest, stest, dbstack, mfilename);
315 end % END UTP_05
316
317 %% UTP_06
318
319 % <TestDescription>
320 %
321 % Tests that the creator method properly applies history
322 %
323 % </TestDescription>
324 function result = utp_06
325
326 % <SyntaxDescription>
327 %
328 % This method doesn't change the input object, thus no history is added
329 % to the object.
330 %
331 % </SyntaxDescription>
332
333 try
334 % <SyntaxCode>
335 % </SyntaxCode>
336 stest = true;
337 catch err
338 disp(err.message)
339 stest = false;
340 end
341
342 % <AlgoDescription>
343 %
344 % 1) Nothing to check.
345 %
346 % </AlgoDescription>
347
348 atest = true;
349 if stest
350 % <AlgoCode>
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_06
359
360 %% UTP_07
361
362 % <TestDescription>
363 %
364 % Tests that the creator method can be used with the modify command.
365 %
366 % </TestDescription>
367 function result = utp_07
368
369 % <SyntaxDescription>
370 %
371 % Tests that the creator method can be used with the modify command.
372 %
373 % </SyntaxDescription>
374
375 try
376 % <SyntaxCode>
377 out1 = at3.creator;
378 out2 = atmat.creator;
379 % </SyntaxCode>
380 stest = true;
381 catch err
382 disp(err.message)
383 stest = false;
384 end
385
386 % <AlgoDescription>
387 %
388 % 1) Check the single object
389 % 2) Check the matrix object
390 %
391 % </AlgoDescription>
392
393 atest = true;
394 if stest
395 % <AlgoCode>
396 curr_creator = provenance();
397 % Check the single object
398 if ~strcmp(out1, curr_creator.creator), atest = false; end
399 % For a single object must be the the output a char string
400 if ~ischar(out1), atest = false; end
401 % Check the matrix
402 for kk = 1:numel(out2)
403 if ~strcmp(out2{kk}, curr_creator.creator), atest = false; end
404 end
405 % </AlgoCode>
406 else
407 atest = false;
408 end
409
410 % Return a result structure
411 result = utp_prepare_result(atest, stest, dbstack, mfilename);
412 end % END UTP_07
413
414 %% UTP_08
415
416 % <TestDescription>
417 %
418 % Tests that the creator method retruns all creator(s)/modifier(s) which
419 % are in the history.
420 %
421 % </TestDescription>
422 function result = utp_08
423
424 % <SyntaxDescription>
425 %
426 % Test that the creator method uses the option 'all' direct or in a
427 % plist. The test file must have the modifier 'first', 'second' and
428 % 'third'
429 %
430 % </SyntaxDescription>
431
432 try
433 % <SyntaxCode>
434 % Read object with different modifier
435 at = ao('test_ao_diff_creator.xml');
436 out1 = at.creator;
437 out2 = at.creator('all');
438 out3 = at.creator(plist('option', 'all'));
439 % </SyntaxCode>
440 stest = true;
441 catch err
442 disp(err.message)
443 stest = false;
444 end
445
446 % <AlgoDescription>
447 %
448 % 1) Check that out1 contains only one creator
449 % 2) Check that out2 contain more creator/modifier
450 %
451 % </AlgoDescription>
452
453 atest = true;
454 if stest
455 % <AlgoCode>
456 if ~ischar(out1), atest = false; end
457 if ~strmatch('fist', out2), atest = false; end
458 if ~strmatch('second', out2), atest = false; end
459 if ~strmatch('third', out2), atest = false; end
460 if ~strmatch('fist', out3), atest = false; end
461 if ~strmatch('second', out3), atest = false; end
462 if ~strmatch('third', out3), atest = false; end
463 % </AlgoCode>
464 else
465 atest = false;
466 end
467
468 % Return a result structure
469 result = utp_prepare_result(atest, stest, dbstack, mfilename);
470 end % END UTP_08
471
472 %% UTP_09
473
474 % <TestDescription>
475 %
476 % Tests the negative case for the option 'all'.
477 %
478 % </TestDescription>
479 function result = utp_09
480
481 % <SyntaxDescription>
482 %
483 % Test that the creator method throws an error if the option 'all' is
484 % used in connection with a matrix/vector of AOs.
485 %
486 % </SyntaxDescription>
487
488 try
489 % <SyntaxCode>
490 atmat.creator('all');
491 stest = false;
492 % </SyntaxCode>
493 catch
494 stest = true;
495 end
496
497 % <AlgoDescription>
498 %
499 % 1) Nothing to test.
500 %
501 % </AlgoDescription>
502
503 atest = true;
504 if stest
505 % <AlgoCode>
506 % </AlgoCode>
507 else
508 atest = false;
509 end
510
511 % Return a result structure
512 result = utp_prepare_result(atest, stest, dbstack, mfilename);
513 end % END UTP_09
514
515 end