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