Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/timespan/utp_timespan_string.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_STRING a set of UTPs for the timespan/string method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_timespan_string.m,v 1.2 2009/07/28 13:17:24 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The string method of the timespan class writes a command string that can be | |
11 % used to recreate the input object(s). But the object must be created with a | |
12 % plist. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_timespan_string(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'timespan'; | |
23 mthd = 'string'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 pl1 = plist('timezone', 'PST', 'timeformat', 'HH:MM:SS.FFF', 'startT', time(1234), 'endT', time(12345)); | |
31 ts1 = timespan(pl1); | |
32 pl2 = plist('startT', '14:00:00', 'endT', '15:15:00'); | |
33 ts2 = timespan(pl2); | |
34 tsv = [ts1, ts2, ts1]; | |
35 tsm = [ts1, ts2, ts1; ts1, ts2, ts1]; | |
36 | |
37 % Exception list for the UTPs: | |
38 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
39 | |
40 % Run the tests | |
41 results = [results utp_01]; % getInfo call | |
42 results = [results utp_02]; % Vector input | |
43 results = [results utp_03]; % Matrix input | |
44 results = [results utp_04]; % List input | |
45 results = [results utp_05]; % Test with mixed input | |
46 results = [results utp_06]; % Test history is working | |
47 results = [results utp_07]; % Negative test: The object have more than one history step. | |
48 | |
49 disp('Done.'); | |
50 disp('******************************************************'); | |
51 | |
52 elseif nargin == 1 % Check for UTP functions | |
53 if strcmp(varargin{1}, 'isutp') | |
54 results = 1; | |
55 else | |
56 results = 0; | |
57 end | |
58 else | |
59 error('### Incorrect inputs') | |
60 end | |
61 | |
62 %% UTP_01 | |
63 | |
64 % <TestDescription> | |
65 % | |
66 % Tests that the getInfo call works for this method. | |
67 % | |
68 % </TestDescription> | |
69 function result = utp_01 | |
70 | |
71 | |
72 % <SyntaxDescription> | |
73 % | |
74 % Test that the getInfo call works for no sets, all sets, and each set | |
75 % individually. | |
76 % | |
77 % </SyntaxDescription> | |
78 | |
79 try | |
80 % <SyntaxCode> | |
81 % Call for no sets | |
82 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
83 % Call for all sets | |
84 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
85 % Call for each set | |
86 for kk=1:numel(io(2).sets) | |
87 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
88 end | |
89 % </SyntaxCode> | |
90 stest = true; | |
91 catch err | |
92 disp(err.message) | |
93 stest = false; | |
94 end | |
95 | |
96 % <AlgoDescription> | |
97 % | |
98 % 1) Check that getInfo call returned an minfo object in all cases. | |
99 % 2) Check that all plists have the correct parameters. | |
100 % | |
101 % </AlgoDescription> | |
102 | |
103 atest = true; | |
104 if stest | |
105 % <AlgoCode> | |
106 % check we have minfo objects | |
107 if isa(io, 'minfo') | |
108 %%% SET 'None' | |
109 if ~isempty(io(1).sets), atest = false; end | |
110 if ~isempty(io(1).plists), atest = false; end | |
111 %%% Check all Sets | |
112 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
113 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
114 %%%%%%%%%% SET 'Default' | |
115 if io(3).plists.nparams ~= 0, atest = false; end | |
116 % Check key | |
117 % Check default value | |
118 % Check options | |
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 string 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 string method works for a vector of TIMESPAN objects as input. | |
141 % | |
142 % </SyntaxDescription> | |
143 | |
144 try | |
145 % <SyntaxCode> | |
146 out = string(tsv); | |
147 rout = eval(out); | |
148 % </SyntaxCode> | |
149 stest = true; | |
150 catch err | |
151 disp(err.message) | |
152 stest = false; | |
153 end | |
154 | |
155 % <AlgoDescription> | |
156 % | |
157 % 1) Check that the output is a executable string. | |
158 % 2) Check the correct number of rout | |
159 % 3) Check the rebuild objects. | |
160 % | |
161 % </AlgoDescription> | |
162 | |
163 atest = true; | |
164 if stest | |
165 % <AlgoCode> | |
166 % Check the output | |
167 if ~ischar(out), atest = false; end; | |
168 if ~isa(rout, 'timespan'), atest = false; end | |
169 if numel(rout) ~= numel(tsv), atest = false; end | |
170 for kk = 1:numel(tsv) | |
171 if eq(rout(kk), tsv(kk)), atest = false; end | |
172 end | |
173 % </AlgoCode> | |
174 else | |
175 atest = false; | |
176 end | |
177 | |
178 % Return a result structure | |
179 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
180 end % END UTP_02 | |
181 | |
182 %% UTP_03 | |
183 | |
184 % <TestDescription> | |
185 % | |
186 % Tests that the string method works with a matrix of TIMESPAN objects as input. | |
187 % | |
188 % </TestDescription> | |
189 function result = utp_03 | |
190 | |
191 % <SyntaxDescription> | |
192 % | |
193 % Test that the string method works for a matrix of TIMESPAN objects as input. | |
194 % | |
195 % </SyntaxDescription> | |
196 | |
197 try | |
198 % <SyntaxCode> | |
199 out = string(tsm); | |
200 rout = eval(out); | |
201 % </SyntaxCode> | |
202 stest = true; | |
203 catch err | |
204 disp(err.message) | |
205 stest = false; | |
206 end | |
207 | |
208 % <AlgoDescription> | |
209 % | |
210 % 1) Check that the output is a executable string. | |
211 % 2) Check the correct number of rout | |
212 % 3) Check the rebuild objects. | |
213 % | |
214 % </AlgoDescription> | |
215 | |
216 atest = true; | |
217 if stest | |
218 % <AlgoCode> | |
219 % Check the output | |
220 if ~ischar(out), atest = false; end | |
221 if ~isa(rout, 'timespan'), atest = false; end | |
222 if numel(rout) ~= numel(tsm), atest = false; end | |
223 for kk = 1:numel(tsm) | |
224 if eq(rout(kk), tsm(kk)), atest = false; end | |
225 end | |
226 % </AlgoCode> | |
227 else | |
228 atest = false; | |
229 end | |
230 | |
231 % Return a result structure | |
232 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
233 end % END UTP_03 | |
234 | |
235 %% UTP_04 | |
236 | |
237 % <TestDescription> | |
238 % | |
239 % Tests that the string method works with a list of TIMESPAN objects as input. | |
240 % | |
241 % </TestDescription> | |
242 function result = utp_04 | |
243 | |
244 % <SyntaxDescription> | |
245 % | |
246 % Test that the string method works for a list of TIMESPAN objects as input. | |
247 % | |
248 % </SyntaxDescription> | |
249 | |
250 try | |
251 % <SyntaxCode> | |
252 out = string(ts1,ts2); | |
253 rout = eval(out); | |
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 output is a executable string. | |
264 % 2) Check the correct number of rout | |
265 % 3) Check the rebuild objects. | |
266 % | |
267 % </AlgoDescription> | |
268 | |
269 atest = true; | |
270 tsin = [ts1, ts2]; | |
271 if stest | |
272 % <AlgoCode> | |
273 % Check the output | |
274 if ~ischar(out), atest = false; end | |
275 if ~isa(rout, 'timespan'), atest = false; end | |
276 if numel(rout) ~= numel(tsin), atest = false; end | |
277 for kk = 1:numel(tsin) | |
278 if eq(rout(kk), tsin(kk)), atest = false; end | |
279 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 string method works with a mix of different shaped TIMESPAN objects | |
294 % as input. | |
295 % | |
296 % </TestDescription> | |
297 function result = utp_05 | |
298 | |
299 % <SyntaxDescription> | |
300 % | |
301 % Test that the string method works with an input of matrices and vectors | |
302 % and single TIMESPAN objects. | |
303 % | |
304 % </SyntaxDescription> | |
305 | |
306 try | |
307 % <SyntaxCode> | |
308 out = string(ts1,tsm,ts2); | |
309 rout = eval(out); | |
310 % </SyntaxCode> | |
311 stest = true; | |
312 catch err | |
313 disp(err.message) | |
314 stest = false; | |
315 end | |
316 | |
317 % <AlgoDescription> | |
318 % | |
319 % 1) Check that the output is a executable string. | |
320 % 2) Check the correct number of rout | |
321 % 3) Check the rebuild objects. | |
322 % | |
323 % </AlgoDescription> | |
324 | |
325 atest = true; | |
326 tsin = [ts1, reshape(tsm, 1, []), ts2]; | |
327 if stest | |
328 % <AlgoCode> | |
329 % Check the output | |
330 if ~ischar(out), atest = false; end | |
331 if ~isa(rout, 'timespan'), atest = false; end | |
332 if numel(rout) ~= numel(tsin), atest = false; end | |
333 for kk = 1:numel(tsin) | |
334 if eq(rout(kk), tsin(kk)), atest = false; end | |
335 end | |
336 % </AlgoCode> | |
337 else | |
338 atest = false; | |
339 end | |
340 | |
341 % Return a result structure | |
342 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
343 end % END UTP_05 | |
344 | |
345 %% UTP_06 | |
346 | |
347 % <TestDescription> | |
348 % | |
349 % Tests that the string method properly applies history. | |
350 % | |
351 % </TestDescription> | |
352 function result = utp_06 | |
353 | |
354 % <SyntaxDescription> | |
355 % | |
356 % The method string doesn't change the data, thus it is not possible to check | |
357 % the history. Nothing to do. | |
358 % | |
359 % </SyntaxDescription> | |
360 | |
361 try | |
362 % <SyntaxCode> | |
363 % </SyntaxCode> | |
364 stest = true; | |
365 catch err | |
366 disp(err.message) | |
367 stest = false; | |
368 end | |
369 | |
370 % <AlgoDescription> | |
371 % | |
372 % </AlgoDescription> | |
373 | |
374 atest = true; | |
375 if stest | |
376 % <AlgoCode> | |
377 % </AlgoCode> | |
378 else | |
379 atest = false; | |
380 end | |
381 | |
382 % Return a result structure | |
383 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
384 end % END UTP_06 | |
385 | |
386 %% UTP_07 | |
387 | |
388 % <TestDescription> | |
389 % | |
390 % Tests that the string method doesn't work if the TIMESPAN object have more | |
391 % than one history step. | |
392 % | |
393 % </TestDescription> | |
394 function result = utp_07 | |
395 | |
396 % <SyntaxDescription> | |
397 % | |
398 % The method string throws an error because the input object have more than | |
399 % one history step. | |
400 % | |
401 % </SyntaxDescription> | |
402 | |
403 try | |
404 % <SyntaxCode> | |
405 ts3 = timespan(3000, 5000); | |
406 ts3.setName('Second history step'); | |
407 out = ts3.string(); | |
408 % </SyntaxCode> | |
409 stest = false; | |
410 catch err | |
411 stest = true; | |
412 end | |
413 | |
414 % <AlgoDescription> | |
415 % | |
416 % </AlgoDescription> | |
417 | |
418 atest = true; | |
419 if stest | |
420 % <AlgoCode> | |
421 % </AlgoCode> | |
422 else | |
423 atest = false; | |
424 end | |
425 | |
426 % Return a result structure | |
427 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
428 end % END UTP_07 | |
429 | |
430 end |