Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/timespan/utp_timespan_setEndT.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_TIMESPAN_SETENDT a set of UTPs for the timespan/setEndT method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_timespan_setEndT.m,v 1.6 2011/04/19 18:14:02 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The setEndT method of the timespan class sets the name property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_timespan_setEndT(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'timespan'; | |
21 mthd = 'setEndT'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test TIMESPAN objects | |
29 [ts1, ts2, ts3, ts4, ts5, ts6, tsv, tsm] = get_test_objects_timespan; | |
30 | |
31 % Exception list for the UTPs: | |
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
33 | |
34 % Run the tests | |
35 results = [results utp_01]; % getInfo call | |
36 results = [results utp_02]; % Vector input | |
37 results = [results utp_03]; % Matrix input | |
38 results = [results utp_04]; % List input | |
39 results = [results utp_05]; % Test with mixed input | |
40 results = [results utp_06]; % Test history is working | |
41 results = [results utp_07]; % Test the modify call works | |
42 results = [results utp_08]; % Set the property with a plist | |
43 results = [results utp_09]; % Test output of the data | |
44 results = [results utp_10]; % Use different inputs (char, time-objects, double) | |
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 ~= 1, atest = false; end | |
113 % Check key | |
114 if ~io(3).plists.isparam('endt'), atest = false; end | |
115 % Check default value | |
116 if ~isEmptyChar(io(3).plists.find('endt')), atest = false; end | |
117 % Check options | |
118 if ~isequal(io(3).plists.getOptionsForParam('endt'), {''}), atest = false; end | |
119 end | |
120 % </AlgoCode> | |
121 else | |
122 atest = false; | |
123 end | |
124 | |
125 % Return a result structure | |
126 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
127 end % END UTP_01 | |
128 | |
129 %% UTP_02 | |
130 | |
131 % <TestDescription> | |
132 % | |
133 % Tests that the setEndT method works with a vector of TIMESPAN objects as input. | |
134 % | |
135 % </TestDescription> | |
136 function result = utp_02 | |
137 | |
138 % <SyntaxDescription> | |
139 % | |
140 % Test that the setEndT method works for a vector of TIMESPAN objects as input. | |
141 % | |
142 % </SyntaxDescription> | |
143 | |
144 try | |
145 % <SyntaxCode> | |
146 out = setEndT(tsv, time(12345)); | |
147 % </SyntaxCode> | |
148 stest = true; | |
149 catch err | |
150 disp(err.message) | |
151 stest = false; | |
152 end | |
153 | |
154 % <AlgoDescription> | |
155 % | |
156 % 1) Check that the number of elements in 'out' is the same as in 'tsv' | |
157 % 2) Check that each output contains the correct data. | |
158 % | |
159 % </AlgoDescription> | |
160 | |
161 atest = true; | |
162 if stest | |
163 % <AlgoCode> | |
164 % Check we have the correct number of outputs | |
165 if ~isequal(size(out), size(tsv)), atest = false; end | |
166 % Check name field of each output | |
167 for kk=1:numel(out) | |
168 if ~eq(out(kk).endT, time(12345), ple1), atest = false; break; end | |
169 end | |
170 % </AlgoCode> | |
171 else | |
172 atest = false; | |
173 end | |
174 | |
175 % Return a result structure | |
176 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
177 end % END UTP_02 | |
178 | |
179 %% UTP_03 | |
180 | |
181 % <TestDescription> | |
182 % | |
183 % Tests that the setEndT method works with a matrix of TIMESPAN objects as input. | |
184 % | |
185 % </TestDescription> | |
186 function result = utp_03 | |
187 | |
188 % <SyntaxDescription> | |
189 % | |
190 % Test that the setEndT method works for a matrix of TIMESPAN objects as input. | |
191 % | |
192 % </SyntaxDescription> | |
193 | |
194 try | |
195 % <SyntaxCode> | |
196 out = setEndT(tsm, time(12345)); | |
197 % </SyntaxCode> | |
198 stest = true; | |
199 catch err | |
200 disp(err.message) | |
201 stest = false; | |
202 end | |
203 | |
204 % <AlgoDescription> | |
205 % | |
206 % 1) Check that the number of elements in 'out' is the same as in 'tsm' | |
207 % 2) Check that each output contains the correct data. | |
208 % | |
209 % </AlgoDescription> | |
210 | |
211 atest = true; | |
212 if stest | |
213 % <AlgoCode> | |
214 % Check we have the correct number of outputs | |
215 if ~isequal(size(out), size(tsm)), atest = false; end | |
216 % Check name field of each output | |
217 for kk=1:numel(out) | |
218 if ~eq(out(kk).endT, time(12345), ple1), atest = false; break; end | |
219 end | |
220 % </AlgoCode> | |
221 else | |
222 atest = false; | |
223 end | |
224 | |
225 % Return a result structure | |
226 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
227 end % END UTP_03 | |
228 | |
229 %% UTP_04 | |
230 | |
231 % <TestDescription> | |
232 % | |
233 % Tests that the setEndT method works with a list of TIMESPAN objects as input. | |
234 % | |
235 % </TestDescription> | |
236 function result = utp_04 | |
237 | |
238 % <SyntaxDescription> | |
239 % | |
240 % Test that the setEndT method works for a list of TIMESPAN objects as input. | |
241 % | |
242 % </SyntaxDescription> | |
243 | |
244 try | |
245 % <SyntaxCode> | |
246 out = setEndT(ts5,ts4,ts3, time(12345)); | |
247 % </SyntaxCode> | |
248 stest = true; | |
249 catch err | |
250 disp(err.message) | |
251 stest = false; | |
252 end | |
253 | |
254 % <AlgoDescription> | |
255 % | |
256 % 1) Check that the number of elements in 'out' is the same as in | |
257 % input. | |
258 % 2) Check that each output contains the correct data. | |
259 % | |
260 % </AlgoDescription> | |
261 | |
262 atest = true; | |
263 if stest | |
264 % <AlgoCode> | |
265 % Check we have the correct number of outputs | |
266 if numel(out) ~= 3, atest = false; end | |
267 % Check each output against the input | |
268 if ~eq(out(1).endT, time(12345), ple1), atest = false; end | |
269 if ~eq(out(2).endT, time(12345), ple1), atest = false; end | |
270 if ~eq(out(3).endT, time(12345), ple1), atest = false; end | |
271 % </AlgoCode> | |
272 else | |
273 atest = false; | |
274 end | |
275 | |
276 % Return a result structure | |
277 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
278 end % END UTP_04 | |
279 | |
280 %% UTP_05 | |
281 | |
282 % <TestDescription> | |
283 % | |
284 % Tests that the setEndT method works with a mix of different shaped TIMESPAN | |
285 % objects as input. | |
286 % | |
287 % </TestDescription> | |
288 function result = utp_05 | |
289 | |
290 % <SyntaxDescription> | |
291 % | |
292 % Test that the setEndT method works with an input of matrices and vectors | |
293 % and single TIMESPAN objects. | |
294 % | |
295 % </SyntaxDescription> | |
296 | |
297 try | |
298 % <SyntaxCode> | |
299 out = setEndT(ts5,tsv,ts4,tsm,ts3, time(12345)); | |
300 % </SyntaxCode> | |
301 stest = true; | |
302 catch err | |
303 disp(err.message) | |
304 stest = false; | |
305 end | |
306 | |
307 % <AlgoDescription> | |
308 % | |
309 % 1) Check that the number of elements in 'out' is the same as in | |
310 % input. | |
311 % 2) Check that each output contains the correct data. | |
312 % | |
313 % </AlgoDescription> | |
314 | |
315 atest = true; | |
316 if stest | |
317 % <AlgoCode> | |
318 % Check we have the correct number of outputs | |
319 if numel(out) ~= (3+numel(tsm)+numel(tsv)), atest = false; end | |
320 for kk=1:numel(out) | |
321 if ~eq(out(kk).endT, time(12345), ple1), atest = false; break; end | |
322 end | |
323 % </AlgoCode> | |
324 else | |
325 atest = false; | |
326 end | |
327 | |
328 % Return a result structure | |
329 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
330 end % END UTP_05 | |
331 | |
332 %% UTP_06 | |
333 | |
334 % <TestDescription> | |
335 % | |
336 % Tests that the setEndT method properly applies history and that the | |
337 % option 'internal' suppresses the history. | |
338 % | |
339 % </TestDescription> | |
340 function result = utp_06 | |
341 | |
342 % <SyntaxDescription> | |
343 % | |
344 % Test that the result of applying the setEndT method can be processed back | |
345 % to an m-file. | |
346 % | |
347 % </SyntaxDescription> | |
348 | |
349 try | |
350 % <SyntaxCode> | |
351 out1 = setEndT(timespan(ts5), time(12345)); | |
352 out2 = testCallerIsMethod(@setEndT, timespan(ts5), time(12345)); | |
353 mout1 = rebuild(out1); | |
354 mout2 = rebuild(out2); | |
355 % </SyntaxCode> | |
356 stest = true; | |
357 catch err | |
358 disp(err.message) | |
359 stest = false; | |
360 end | |
361 | |
362 % <AlgoDescription> | |
363 % | |
364 % 1) Check that the last entry in the history of 'out1' corresponds to | |
365 % 'setEndT'. | |
366 % 2) Check that the last entry in the history of 'out2' NOT corresponds to | |
367 % 'setEndT'. | |
368 % 3) Check that the method rebuild produces the same object as 'out'. | |
369 % | |
370 % </AlgoDescription> | |
371 | |
372 atest = true; | |
373 if stest | |
374 % <AlgoCode> | |
375 % Check the last step in the history of 'out1' | |
376 if ~(strcmp(out1.hist.methodInfo.mname, 'setEndT') && ... | |
377 eq(out1.hist.plistUsed, plist('endT', time(12345)), ple1)) | |
378 atest = false; | |
379 end | |
380 % Check the last step in the history of 'out2' | |
381 if eq(out2.hist.plistUsed, plist('endT', time(12345)), ple1) | |
382 atest = false; | |
383 end | |
384 % Check the rebuilt object | |
385 if ~eq(mout1, out1, ple2), atest = false; end | |
386 if ~eq(mout2, timespan(ts5), ple2), atest = false; end | |
387 % </AlgoCode> | |
388 else | |
389 atest = false; | |
390 end | |
391 | |
392 % Return a result structure | |
393 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
394 end % END UTP_06 | |
395 | |
396 %% UTP_07 | |
397 | |
398 % <TestDescription> | |
399 % | |
400 % Tests that the setEndT method can modify the input TIMESPAN object. | |
401 % | |
402 % </TestDescription> | |
403 function result = utp_07 | |
404 | |
405 % <SyntaxDescription> | |
406 % | |
407 % Test that the setEndT method can modify the input TIMESPAN object | |
408 % by calling with no output. | |
409 % | |
410 % </SyntaxDescription> | |
411 | |
412 try | |
413 % <SyntaxCode> | |
414 % copy ts5 to work with | |
415 ain = timespan(ts5); | |
416 % modify ain | |
417 aout = ain.setEndT(time(12345)); | |
418 ain.setEndT(time(12345)); | |
419 % </SyntaxCode> | |
420 stest = true; | |
421 catch err | |
422 disp(err.message) | |
423 stest = false; | |
424 end | |
425 | |
426 % <AlgoDescription> | |
427 % | |
428 % 1) Check that 'ts5' and 'ain' are now different. | |
429 % 2) Check that 'ain' has the correct name field | |
430 % | |
431 % </AlgoDescription> | |
432 | |
433 atest = true; | |
434 if stest | |
435 % <AlgoCode> | |
436 % Check that setEndT modified the input by comparing to the copy | |
437 if eq(timespan(ts5), ain, ple1), atest = false; end | |
438 % Check that setEndT doesn't modified the input for the function notation | |
439 if ~eq(aout, ain, ple1), atest = false; end | |
440 % Check that the modified object contains the changed value | |
441 if ~eq(ain.endT, time(12345), ple1), atest = false; end | |
442 % </AlgoCode> | |
443 else | |
444 atest = false; | |
445 end | |
446 | |
447 % Return a result structure | |
448 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
449 end % END UTP_07 | |
450 | |
451 %% UTP_08 | |
452 | |
453 % <TestDescription> | |
454 % | |
455 % Tests that the setEndT method can set the property with a plist. | |
456 % | |
457 % </TestDescription> | |
458 function result = utp_08 | |
459 | |
460 % <SyntaxDescription> | |
461 % | |
462 % Test that the setEndT method can modify the property 'endT' | |
463 % with a value in a plist. | |
464 % | |
465 % </SyntaxDescription> | |
466 | |
467 try | |
468 % <SyntaxCode> | |
469 pl = plist('endT', time(12345)); | |
470 out = ts5.setEndT(pl); | |
471 mout = rebuild(out); | |
472 % </SyntaxCode> | |
473 stest = true; | |
474 catch err | |
475 disp(err.message) | |
476 stest = false; | |
477 end | |
478 | |
479 % <AlgoDescription> | |
480 % | |
481 % 1) Check that 'ain' has the correct name field | |
482 % 2) Check that the method rebuild produces the same object as 'out'. | |
483 % | |
484 % </AlgoDescription> | |
485 | |
486 atest = true; | |
487 if stest | |
488 % <AlgoCode> | |
489 % Check the field 'endT' | |
490 if ~eq(out.endT, time(12345), ple1), atest = false; end | |
491 % Check the rebuilt object | |
492 if ~eq(mout, out, ple2), atest = false; end | |
493 % </AlgoCode> | |
494 else | |
495 atest = false; | |
496 end | |
497 | |
498 % Return a result structure | |
499 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
500 end % END UTP_08 | |
501 | |
502 %% UTP_09 | |
503 | |
504 % <TestDescription> | |
505 % | |
506 % Check that the setEndT method pass back the output objects to a list of | |
507 % output variables or to a single variable. | |
508 % | |
509 % </TestDescription> | |
510 function result = utp_09 | |
511 | |
512 % <SyntaxDescription> | |
513 % | |
514 % Call the method with a list of output variables and with a single output | |
515 % variable. Additionaly check that the rebuild method works on the output. | |
516 % | |
517 % </SyntaxDescription> | |
518 | |
519 try | |
520 % <SyntaxCode> | |
521 [o1, o2] = setEndT(ts5, ts2, time(12345)); | |
522 o3 = setEndT(ts5, ts2, time(12345)); | |
523 mout1 = rebuild(o1); | |
524 mout2 = rebuild(o2); | |
525 mout3 = rebuild(o3); | |
526 % </SyntaxCode> | |
527 stest = true; | |
528 catch err | |
529 disp(err.message) | |
530 stest = false; | |
531 end | |
532 | |
533 % <AlgoDescription> | |
534 % | |
535 % 1) Check that the output contains the right number of objects | |
536 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
537 % | |
538 % </AlgoDescription> | |
539 | |
540 atest = true; | |
541 if stest | |
542 % <AlgoCode> | |
543 % Check the number of outputs | |
544 if numel(o1) ~=1, atest = false; end | |
545 if numel(o2) ~=1, atest = false; end | |
546 if numel(o3) ~=2, atest = false; end | |
547 % Check the rebuilding of the object | |
548 if ~eq(o1, mout1, ple2), atest = false; end | |
549 if ~eq(o2, mout2, ple2), atest = false; end | |
550 if ~eq(o3, mout3, ple2), atest = false; end | |
551 % </AlgoCode> | |
552 else | |
553 atest = false; | |
554 end | |
555 | |
556 % Return a result structure | |
557 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
558 end % END UTP_09 | |
559 | |
560 %% UTP_10 | |
561 | |
562 % <TestDescription> | |
563 % | |
564 % Check that the setEndT method accept different inputs. | |
565 % | |
566 % </TestDescription> | |
567 function result = utp_10 | |
568 | |
569 % <SyntaxDescription> | |
570 % | |
571 % Test that the setEndT method accept input of double, char and | |
572 % time-objects. | |
573 % | |
574 % </SyntaxDescription> | |
575 | |
576 try | |
577 % <SyntaxCode> | |
578 o1 = setEndT(ts5, time(54321)); | |
579 o2 = setEndT(ts5, '14:00:00'); | |
580 o3 = setEndT(ts5, 54321); | |
581 mout1 = rebuild(o1); | |
582 mout2 = rebuild(o2); | |
583 mout3 = rebuild(o3); | |
584 % </SyntaxCode> | |
585 stest = true; | |
586 catch err | |
587 disp(err.message) | |
588 stest = false; | |
589 end | |
590 | |
591 % <AlgoDescription> | |
592 % | |
593 % 1) Check the output | |
594 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
595 % | |
596 % </AlgoDescription> | |
597 | |
598 atest = true; | |
599 if stest | |
600 % <AlgoCode> | |
601 % Check the number of outputs | |
602 if ~eq(o1.endT, time(54321), ple1), atest = false; end | |
603 if ~eq(o2.endT, time('14:00:00'), ple1), atest = false; end | |
604 if ~eq(o3.endT, time(54321), ple1), atest = false; end | |
605 % Check the rebuilding of the object | |
606 if ~eq(o1, mout1, ple2), atest = false; end | |
607 if ~eq(o2, mout2, ple2), atest = false; end | |
608 if ~eq(o3, mout3, ple2), atest = false; end | |
609 % </AlgoCode> | |
610 else | |
611 atest = false; | |
612 end | |
613 | |
614 % Return a result structure | |
615 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
616 end % END UTP_10 | |
617 | |
618 end |