Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/rational/utp_rational_created.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/created method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_rational_created.m,v 1.2 2009/07/27 19:28:59 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The created method of the rational returns a time object of the last | |
11 % modification. For this uses the created method the 'proctime' property of | |
12 % the last history step and computs from this value a timeobject. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_rational_created(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'rational'; | |
23 mthd = 'created'; | |
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 empty object | |
45 | |
46 disp('Done.'); | |
47 disp('******************************************************'); | |
48 | |
49 elseif nargin == 1 % Check for UTP functions | |
50 if strcmp(varargin{1}, 'isutp') | |
51 results = 1; | |
52 else | |
53 results = 0; | |
54 end | |
55 else | |
56 error('### Incorrect inputs') | |
57 end | |
58 | |
59 %% UTP_01 | |
60 | |
61 % <TestDescription> | |
62 % | |
63 % Tests that the getInfo call works for this method. | |
64 % | |
65 % </TestDescription> | |
66 function result = utp_01 | |
67 | |
68 | |
69 % <SyntaxDescription> | |
70 % | |
71 % Test that the getInfo call works for no sets, all sets, and each set | |
72 % individually. | |
73 % | |
74 % </SyntaxDescription> | |
75 | |
76 try | |
77 % <SyntaxCode> | |
78 % Call for no sets | |
79 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
80 % Call for all sets | |
81 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
82 % Call for each set | |
83 for kk=1:numel(io(2).sets) | |
84 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
85 end | |
86 % </SyntaxCode> | |
87 stest = true; | |
88 catch err | |
89 disp(err.message) | |
90 stest = false; | |
91 end | |
92 | |
93 % <AlgoDescription> | |
94 % | |
95 % 1) Check that getInfo call returned an minfo object in all cases. | |
96 % 2) Check that all plists have the correct parameters. | |
97 % | |
98 % </AlgoDescription> | |
99 | |
100 atest = true; | |
101 if stest | |
102 % <AlgoCode> | |
103 % check we have minfo objects | |
104 if isa(io, 'minfo') | |
105 %%% SET 'None' | |
106 if ~isempty(io(1).sets), atest = false; end | |
107 if ~isempty(io(1).plists), atest = false; end | |
108 %%% Check all Sets | |
109 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
110 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
111 %%%%%%%%%% SET 'Default' | |
112 if io(3).plists.nparams ~= 0, atest = false; end | |
113 % Check key | |
114 % Check default value | |
115 % Check options | |
116 end | |
117 % </AlgoCode> | |
118 else | |
119 atest = false; | |
120 end | |
121 | |
122 % Return a result structure | |
123 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
124 end % END UTP_01 | |
125 | |
126 %% UTP_02 | |
127 | |
128 % <TestDescription> | |
129 % | |
130 % Tests that the created method works with a vector of RATIONAL objects as | |
131 % input. | |
132 % | |
133 % </TestDescription> | |
134 function result = utp_02 | |
135 | |
136 % <SyntaxDescription> | |
137 % | |
138 % Test that the created method works for a vector of RATIONAL objects as | |
139 % input. | |
140 % | |
141 % </SyntaxDescription> | |
142 | |
143 try | |
144 % <SyntaxCode> | |
145 out = created(rav); | |
146 % </SyntaxCode> | |
147 stest = true; | |
148 catch err | |
149 disp(err.message) | |
150 stest = false; | |
151 end | |
152 | |
153 % <AlgoDescription> | |
154 % | |
155 % 1) Check that the number of elements in 'out' is the same as in 'rav' | |
156 % 2) Check that each output contains the correct data. | |
157 % | |
158 % </AlgoDescription> | |
159 | |
160 atest = true; | |
161 if stest | |
162 % <AlgoCode> | |
163 % Check that the output is a time object | |
164 if ~isa(out, 'time'), atest = false; end | |
165 % Check we have the correct number of outputs | |
166 if ~isequal(size(out), size(rav)), atest = false; end | |
167 % Check the time-object | |
168 for kk=1:numel(out) | |
169 if out(kk).utc_epoch_milli ~= rav(kk).hist.proctime, atest = false; break; end | |
170 end | |
171 % </AlgoCode> | |
172 else | |
173 atest = false; | |
174 end | |
175 | |
176 % Return a result structure | |
177 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
178 end % END UTP_02 | |
179 | |
180 %% UTP_03 | |
181 | |
182 % <TestDescription> | |
183 % | |
184 % Tests that the created method works with a matrix of RATIONAL objects as | |
185 % input. | |
186 % | |
187 % </TestDescription> | |
188 function result = utp_03 | |
189 | |
190 % <SyntaxDescription> | |
191 % | |
192 % Test that the created method works for a matrix of RATIONAL objects as | |
193 % input. | |
194 % | |
195 % </SyntaxDescription> | |
196 | |
197 try | |
198 % <SyntaxCode> | |
199 out = created(ram); | |
200 % </SyntaxCode> | |
201 stest = true; | |
202 catch err | |
203 disp(err.message) | |
204 stest = false; | |
205 end | |
206 | |
207 % <AlgoDescription> | |
208 % | |
209 % 1) Check that the number of elements in 'out' is the same as in 'ram' | |
210 % 2) Check that each output contains the correct data. | |
211 % | |
212 % </AlgoDescription> | |
213 | |
214 atest = true; | |
215 if stest | |
216 % <AlgoCode> | |
217 % Check that the output is a time object | |
218 if ~isa(out, 'time'), atest = false; end | |
219 % Check we have the correct number of outputs | |
220 if ~isequal(size(out), size(ram)), atest = false; end | |
221 % Check time-object | |
222 for kk=1:numel(out) | |
223 if out(kk).utc_epoch_milli ~= ram(kk).hist.proctime, atest = false; break; end | |
224 end | |
225 % </AlgoCode> | |
226 else | |
227 atest = false; | |
228 end | |
229 | |
230 % Return a result structure | |
231 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
232 end % END UTP_03 | |
233 | |
234 %% UTP_04 | |
235 | |
236 % <TestDescription> | |
237 % | |
238 % Tests that the created method works with a list of RATIONAL objects as | |
239 % input. | |
240 % | |
241 % </TestDescription> | |
242 function result = utp_04 | |
243 | |
244 % <SyntaxDescription> | |
245 % | |
246 % Test that the created method works for a list of RATIONAL objects as | |
247 % input. | |
248 % | |
249 % </SyntaxDescription> | |
250 | |
251 try | |
252 % <SyntaxCode> | |
253 out = created(ra1,ra2,ra3); | |
254 % </SyntaxCode> | |
255 stest = true; | |
256 catch err | |
257 disp(err.message) | |
258 stest = false; | |
259 end | |
260 | |
261 % <AlgoDescription> | |
262 % | |
263 % 1) Check that the number of elements in 'out' is the same as in | |
264 % input. | |
265 % 2) Check that each output contains the correct data. | |
266 % | |
267 % </AlgoDescription> | |
268 | |
269 atest = true; | |
270 if stest | |
271 % <AlgoCode> | |
272 % Check that the output is a time object | |
273 if ~isa(out, 'time'), atest = false; end | |
274 % Check we have the correct number of outputs | |
275 if numel(out) ~= 3, atest = false; end | |
276 % Check each output against the input | |
277 if out(1).utc_epoch_milli ~= ra1.hist.proctime, atest = false; end | |
278 if out(2).utc_epoch_milli ~= ra2.hist.proctime, atest = false; end | |
279 if out(3).utc_epoch_milli ~= ra3.hist.proctime, atest = false; end | |
280 % </AlgoCode> | |
281 else | |
282 atest = false; | |
283 end | |
284 | |
285 % Return a result structure | |
286 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
287 end % END UTP_04 | |
288 | |
289 %% UTP_05 | |
290 | |
291 % <TestDescription> | |
292 % | |
293 % Tests that the created method works with a mix of different shaped | |
294 % RATIONAL objects as input. | |
295 % | |
296 % </TestDescription> | |
297 function result = utp_05 | |
298 | |
299 % <SyntaxDescription> | |
300 % | |
301 % Test that the created method works with an input of matrices and | |
302 % vectors and single RATIONAL objects. | |
303 % | |
304 % </SyntaxDescription> | |
305 | |
306 try | |
307 % <SyntaxCode> | |
308 out = created(ra1,rav,ra2,ram,ra3); | |
309 % </SyntaxCode> | |
310 stest = true; | |
311 catch err | |
312 disp(err.message) | |
313 stest = false; | |
314 end | |
315 | |
316 % <AlgoDescription> | |
317 % | |
318 % 1) Check that the number of elements in 'out' is the same as in | |
319 % input. | |
320 % 2) Check that each output contains the correct data. | |
321 % | |
322 % </AlgoDescription> | |
323 | |
324 atest = true; | |
325 rain = [ra1,reshape(rav,1,[]),ra2,reshape(ram,1,[]),ra3]; | |
326 if stest | |
327 % <AlgoCode> | |
328 % Check that the output is a time object | |
329 if ~isa(out, 'time'), atest = false; end | |
330 % Check we have the correct number of outputs | |
331 if numel(out) ~= (3+numel(ram)+numel(rav)), atest = false; end | |
332 for kk=1:numel(out) | |
333 if out(kk).utc_epoch_milli ~= rain(kk).hist.proctime, atest = false; break; end | |
334 end | |
335 % </AlgoCode> | |
336 else | |
337 atest = false; | |
338 end | |
339 | |
340 % Return a result structure | |
341 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
342 end % END UTP_05 | |
343 | |
344 %% UTP_06 | |
345 | |
346 % <TestDescription> | |
347 % | |
348 % Tests that the created method properly applies history | |
349 % | |
350 % </TestDescription> | |
351 function result = utp_06 | |
352 | |
353 % <SyntaxDescription> | |
354 % | |
355 % This method doesn't change the input object, thus no history is added | |
356 % to the object. | |
357 % | |
358 % </SyntaxDescription> | |
359 | |
360 try | |
361 % <SyntaxCode> | |
362 % </SyntaxCode> | |
363 stest = true; | |
364 catch err | |
365 disp(err.message) | |
366 stest = false; | |
367 end | |
368 | |
369 % <AlgoDescription> | |
370 % | |
371 % 1) Nothing to check. | |
372 % | |
373 % </AlgoDescription> | |
374 | |
375 atest = true; | |
376 if stest | |
377 % <AlgoCode> | |
378 % </AlgoCode> | |
379 else | |
380 atest = false; | |
381 end | |
382 | |
383 % Return a result structure | |
384 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
385 end % END UTP_06 | |
386 | |
387 %% UTP_07 | |
388 | |
389 % <TestDescription> | |
390 % | |
391 % Tests that the created method can be used with the modify command. | |
392 % | |
393 % </TestDescription> | |
394 function result = utp_07 | |
395 | |
396 % <SyntaxDescription> | |
397 % | |
398 % Tests that the created method can be used with the modify command. | |
399 % | |
400 % </SyntaxDescription> | |
401 | |
402 try | |
403 % <SyntaxCode> | |
404 out1 = ra3.created; | |
405 out2 = ram.created; | |
406 % </SyntaxCode> | |
407 stest = true; | |
408 catch err | |
409 disp(err.message) | |
410 stest = false; | |
411 end | |
412 | |
413 % <AlgoDescription> | |
414 % | |
415 % 1) Check the single object | |
416 % 2) Check the matrix object | |
417 % | |
418 % </AlgoDescription> | |
419 | |
420 atest = true; | |
421 if stest | |
422 % <AlgoCode> | |
423 % Check the single object | |
424 if out1.utc_epoch_milli ~= ra3.hist.proctime, atest = false; end | |
425 % Check the matrix | |
426 for kk = 1:numel(out2) | |
427 if out2(kk).utc_epoch_milli ~= ram(kk).hist.proctime, atest = false; end | |
428 end | |
429 % </AlgoCode> | |
430 else | |
431 atest = false; | |
432 end | |
433 | |
434 % Return a result structure | |
435 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
436 end % END UTP_07 | |
437 | |
438 %% UTP_08 | |
439 | |
440 % <TestDescription> | |
441 % | |
442 % Tests that the created method retruns always a well defined time object | |
443 % even for an empty input object. | |
444 % | |
445 % </TestDescription> | |
446 function result = utp_08 | |
447 | |
448 % <SyntaxDescription> | |
449 % | |
450 % Test that the created method with an empty 'RATIONAL object | |
451 % | |
452 % </SyntaxDescription> | |
453 | |
454 try | |
455 % <SyntaxCode> | |
456 ra = rational(); | |
457 out = ra.created; | |
458 % </SyntaxCode> | |
459 stest = true; | |
460 catch err | |
461 disp(err.message) | |
462 stest = false; | |
463 end | |
464 | |
465 % <AlgoDescription> | |
466 % | |
467 % 1) Check that the output is a time object with a ell defined time. | |
468 % | |
469 % </AlgoDescription> | |
470 | |
471 atest = true; | |
472 if stest | |
473 % <AlgoCode> | |
474 if ~isa(out, 'time'), atest = false; end | |
475 if isnan(out.utc_epoch_milli), atest = false; end | |
476 % </AlgoCode> | |
477 else | |
478 atest = false; | |
479 end | |
480 | |
481 % Return a result structure | |
482 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
483 end % END UTP_08 | |
484 | |
485 end |