comparison testing/utp_1.1/utps/timespan/utp_timespan_setName.m @ 45:a59cdb8aaf31 database-connection-manager

Merge
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 19:07:22 +0100
parents 409a22968d5e
children
comparison
equal deleted inserted replaced
42:f90d4f666cc7 45:a59cdb8aaf31
1 % UTP_TIMESPAN_SETNAME a set of UTPs for the timespan/setName method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_timespan_setName.m,v 1.6 2011/04/19 18:14:02 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The setName method of the timespan class sets the name property.
11 %
12 % </MethodDescription>
13
14 function results = utp_timespan_setName(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'timespan';
21 mthd = 'setName';
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
45 disp('Done.');
46 disp('******************************************************');
47
48 elseif nargin == 1 % Check for UTP functions
49 if strcmp(varargin{1}, 'isutp')
50 results = 1;
51 else
52 results = 0;
53 end
54 else
55 error('### Incorrect inputs')
56 end
57
58 %% UTP_01
59
60 % <TestDescription>
61 %
62 % Tests that the getInfo call works for this method.
63 %
64 % </TestDescription>
65 function result = utp_01
66
67
68 % <SyntaxDescription>
69 %
70 % Test that the getInfo call works for no sets, all sets, and each set
71 % individually.
72 %
73 % </SyntaxDescription>
74
75 try
76 % <SyntaxCode>
77 % Call for no sets
78 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
79 % Call for all sets
80 io(2) = eval([class '.getInfo(''' mthd ''')']);
81 % Call for each set
82 for kk=1:numel(io(2).sets)
83 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
84 end
85 % </SyntaxCode>
86 stest = true;
87 catch err
88 disp(err.message)
89 stest = false;
90 end
91
92 % <AlgoDescription>
93 %
94 % 1) Check that getInfo call returned an minfo object in all cases.
95 % 2) Check that all plists have the correct parameters.
96 %
97 % </AlgoDescription>
98
99 atest = true;
100 if stest
101 % <AlgoCode>
102 % check we have minfo objects
103 if isa(io, 'minfo')
104 %%% SET 'None'
105 if ~isempty(io(1).sets), atest = false; end
106 if ~isempty(io(1).plists), atest = false; end
107 %%% Check all Sets
108 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
109 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
110 %%%%%%%%%% SET 'Default'
111 if io(3).plists.nparams ~= 1, atest = false; end
112 % Check key
113 if ~io(3).plists.isparam('name'), atest = false; end
114 % Check default value
115 if ~isEmptyChar(io(3).plists.find('name')), atest = false; end
116 % Check options
117 if ~isequal(io(3).plists.getOptionsForParam('name'), {''}), atest = false; end
118 end
119 % </AlgoCode>
120 else
121 atest = false;
122 end
123
124 % Return a result structure
125 result = utp_prepare_result(atest, stest, dbstack, mfilename);
126 end % END UTP_01
127
128 %% UTP_02
129
130 % <TestDescription>
131 %
132 % Tests that the setName method works with a vector of TIMESPAN objects as input.
133 %
134 % </TestDescription>
135 function result = utp_02
136
137 % <SyntaxDescription>
138 %
139 % Test that the setName method works for a vector of TIMESPAN objects as input.
140 %
141 % </SyntaxDescription>
142
143 try
144 % <SyntaxCode>
145 out = setName(tsv, 'my name');
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 'tsv'
156 % 2) Check that each output contains the correct data.
157 %
158 % </AlgoDescription>
159
160 atest = true;
161 if stest
162 % <AlgoCode>
163 % Check we have the correct number of outputs
164 if ~isequal(size(out), size(tsv)), atest = false; end
165 % Check name field of each output
166 for kk=1:numel(out)
167 if ~strcmp(out(kk).name, 'my name'), atest = false; break; 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_02
177
178 %% UTP_03
179
180 % <TestDescription>
181 %
182 % Tests that the setName method works with a matrix of TIMESPAN objects as input.
183 %
184 % </TestDescription>
185 function result = utp_03
186
187 % <SyntaxDescription>
188 %
189 % Test that the setName method works for a matrix of TIMESPAN objects as input.
190 %
191 % </SyntaxDescription>
192
193 try
194 % <SyntaxCode>
195 out = setName(tsm, 'my name');
196 % </SyntaxCode>
197 stest = true;
198 catch err
199 disp(err.message)
200 stest = false;
201 end
202
203 % <AlgoDescription>
204 %
205 % 1) Check that the number of elements in 'out' is the same as in 'tsm'
206 % 2) Check that each output contains the correct data.
207 %
208 % </AlgoDescription>
209
210 atest = true;
211 if stest
212 % <AlgoCode>
213 % Check we have the correct number of outputs
214 if ~isequal(size(out), size(tsm)), atest = false; end
215 % Check name field of each output
216 for kk=1:numel(out)
217 if ~strcmp(out(kk).name, 'my name'), atest = false; break; end
218 end
219 % </AlgoCode>
220 else
221 atest = false;
222 end
223
224 % Return a result structure
225 result = utp_prepare_result(atest, stest, dbstack, mfilename);
226 end % END UTP_03
227
228 %% UTP_04
229
230 % <TestDescription>
231 %
232 % Tests that the setName method works with a list of TIMESPAN objects as input.
233 %
234 % </TestDescription>
235 function result = utp_04
236
237 % <SyntaxDescription>
238 %
239 % Test that the setName method works for a list of TIMESPAN objects as input.
240 %
241 % </SyntaxDescription>
242
243 try
244 % <SyntaxCode>
245 out = setName(ts5,ts4,ts3, 'my name');
246 % </SyntaxCode>
247 stest = true;
248 catch err
249 disp(err.message)
250 stest = false;
251 end
252
253 % <AlgoDescription>
254 %
255 % 1) Check that the number of elements in 'out' is the same as in
256 % input.
257 % 2) Check that each output contains the correct data.
258 %
259 % </AlgoDescription>
260
261 atest = true;
262 if stest
263 % <AlgoCode>
264 % Check we have the correct number of outputs
265 if numel(out) ~= 3, atest = false; end
266 % Check each output against the input
267 if ~strcmp(out(1).name, 'my name'), atest = false; end
268 if ~strcmp(out(2).name, 'my name'), atest = false; end
269 if ~strcmp(out(3).name, 'my name'), atest = false; end
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 setName method works with a mix of different shaped TIMESPAN
284 % objects as input.
285 %
286 % </TestDescription>
287 function result = utp_05
288
289 % <SyntaxDescription>
290 %
291 % Test that the setName method works with an input of matrices and vectors
292 % and single TIMESPAN objects.
293 %
294 % </SyntaxDescription>
295
296 try
297 % <SyntaxCode>
298 out = setName(ts5,tsv,ts4,tsm,ts3, 'my name');
299 % </SyntaxCode>
300 stest = true;
301 catch err
302 disp(err.message)
303 stest = false;
304 end
305
306 % <AlgoDescription>
307 %
308 % 1) Check that the number of elements in 'out' is the same as in
309 % input.
310 % 2) Check that each output contains the correct data.
311 %
312 % </AlgoDescription>
313
314 atest = true;
315 if stest
316 % <AlgoCode>
317 % Check we have the correct number of outputs
318 if numel(out) ~= (3+numel(tsm)+numel(tsv)), atest = false; end
319 for kk=1:numel(out)
320 if ~strcmp(out(kk).name, 'my name'), atest = false; break; end
321 end
322 % </AlgoCode>
323 else
324 atest = false;
325 end
326
327 % Return a result structure
328 result = utp_prepare_result(atest, stest, dbstack, mfilename);
329 end % END UTP_05
330
331 %% UTP_06
332
333 % <TestDescription>
334 %
335 % Tests that the setName method properly applies history and that the
336 % option 'internal' suppresses the history.
337 %
338 % </TestDescription>
339 function result = utp_06
340
341 % <SyntaxDescription>
342 %
343 % Test that the result of applying the setName method can be processed back
344 % to an m-file.
345 %
346 % </SyntaxDescription>
347
348 try
349 % <SyntaxCode>
350 out1 = setName(timespan(ts5), 'my name');
351 out2 = testCallerIsMethod(@setName, timespan(ts5), 'my name');
352 mout1 = rebuild(out1);
353 mout2 = rebuild(out2);
354 % </SyntaxCode>
355 stest = true;
356 catch err
357 disp(err.message)
358 stest = false;
359 end
360
361 % <AlgoDescription>
362 %
363 % 1) Check that the last entry in the history of 'out1' corresponds to
364 % 'setName'.
365 % 2) Check that the last entry in the history of 'out2' NOT corresponds to
366 % 'setName'.
367 % 3) Check that the method rebuild produces the same object as 'out'.
368 %
369 % </AlgoDescription>
370
371 atest = true;
372 if stest
373 % <AlgoCode>
374 % Check the last step in the history of 'out1'
375 if ~(strcmp(out1.hist.methodInfo.mname, 'setName') && ...
376 eq(out1.hist.plistUsed, plist('name', 'my name'), ple1))
377 atest = false;
378 end
379 % Check the last step in the history of 'out2'
380 if eq(out2.hist.plistUsed, plist('name', 'my name'), ple1)
381 atest = false;
382 end
383 % Check the rebuilt object
384 if ~eq(mout1, out1, ple2), atest = false; end
385 e = ple2.find('EXCEPTIONS');
386 ple = plist('EXCEPTIONS', [e {'name'}]);
387 if ~eq(mout2, out2, ple), atest = false; end
388 % </AlgoCode>
389 else
390 atest = false;
391 end
392
393 % Return a result structure
394 result = utp_prepare_result(atest, stest, dbstack, mfilename);
395 end % END UTP_06
396
397 %% UTP_07
398
399 % <TestDescription>
400 %
401 % Tests that the setName method can modify the input TIMESPAN object.
402 %
403 % </TestDescription>
404 function result = utp_07
405
406 % <SyntaxDescription>
407 %
408 % Test that the setName method can modify the input TIMESPAN object
409 % by calling with no output.
410 %
411 % </SyntaxDescription>
412
413 try
414 % <SyntaxCode>
415 % copy ts5 to work with
416 ain = timespan(ts5);
417 % modify ain
418 aout = ain.setName('my name');
419 ain.setName('my name');
420 % </SyntaxCode>
421 stest = true;
422 catch err
423 disp(err.message)
424 stest = false;
425 end
426
427 % <AlgoDescription>
428 %
429 % 1) Check that 'ts5' and 'ain' are now different.
430 % 2) Check that 'ain' has the correct name field
431 %
432 % </AlgoDescription>
433
434 atest = true;
435 if stest
436 % <AlgoCode>
437 % Check that setName modified the input by comparing to the copy
438 if eq(timespan(ts5), ain, ple1), atest = false; end
439 % Check that setName doesn't modified the input for the function notation
440 if ~eq(aout, ain, ple1), atest = false; end
441 % Check that the modified object contains the changed value
442 if ~strcmp(ain.name, 'my name'), atest = false; end
443 % </AlgoCode>
444 else
445 atest = false;
446 end
447
448 % Return a result structure
449 result = utp_prepare_result(atest, stest, dbstack, mfilename);
450 end % END UTP_07
451
452 %% UTP_08
453
454 % <TestDescription>
455 %
456 % Tests that the setName method can set the property with a plist.
457 %
458 % </TestDescription>
459 function result = utp_08
460
461 % <SyntaxDescription>
462 %
463 % Test that the setName method can modify the property 'name'
464 % with a value in a plist.
465 %
466 % </SyntaxDescription>
467
468 try
469 % <SyntaxCode>
470 pl = plist('name', 'my name');
471 out = ts5.setName(pl);
472 mout = rebuild(out);
473 % </SyntaxCode>
474 stest = true;
475 catch err
476 disp(err.message)
477 stest = false;
478 end
479
480 % <AlgoDescription>
481 %
482 % 1) Check that 'ain' has the correct name field
483 % 2) Check that the method rebuild produces the same object as 'out'.
484 %
485 % </AlgoDescription>
486
487 atest = true;
488 if stest
489 % <AlgoCode>
490 % Check the field 'name'
491 if ~strcmp(out.name, 'my name'), atest = false; end
492 % Check the rebuilt object
493 if ~eq(mout, out, ple2), atest = false; end
494 % </AlgoCode>
495 else
496 atest = false;
497 end
498
499 % Return a result structure
500 result = utp_prepare_result(atest, stest, dbstack, mfilename);
501 end % END UTP_08
502
503 %% UTP_09
504
505 % <TestDescription>
506 %
507 % Check that the setName method pass back the output objects to a list of
508 % output variables or to a single variable.
509 %
510 % </TestDescription>
511 function result = utp_09
512
513 % <SyntaxDescription>
514 %
515 % Call the method with a list of output variables and with a single output
516 % variable. Additionaly check that the rebuild method works on the output.
517 %
518 % </SyntaxDescription>
519
520 try
521 % <SyntaxCode>
522 [o1, o2] = setName(ts5, ts2, 'new name');
523 o3 = setName(ts5, ts2, 'new name');
524 mout1 = rebuild(o1);
525 mout2 = rebuild(o2);
526 mout3 = rebuild(o3);
527 % </SyntaxCode>
528 stest = true;
529 catch err
530 disp(err.message)
531 stest = false;
532 end
533
534 % <AlgoDescription>
535 %
536 % 1) Check that the output contains the right number of objects
537 % 2) Check that the 'rebuild' method produces the same object as 'out'.
538 %
539 % </AlgoDescription>
540
541 atest = true;
542 if stest
543 % <AlgoCode>
544 % Check the number of outputs
545 if numel(o1) ~=1, atest = false; end
546 if numel(o2) ~=1, atest = false; end
547 if numel(o3) ~=2, atest = false; end
548 % Check the rebuilding of the object
549 if ~eq(o1, mout1, ple2), atest = false; end
550 if ~eq(o2, mout2, ple2), atest = false; end
551 if ~eq(o3, mout3, ple2), atest = false; end
552 % </AlgoCode>
553 else
554 atest = false;
555 end
556
557 % Return a result structure
558 result = utp_prepare_result(atest, stest, dbstack, mfilename);
559 end % END UTP_09
560
561 end