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