Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/plist/utp_plist_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_PLIST_STRING a set of UTPs for the plist/string method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_plist_string.m,v 1.2 2009/07/22 14:02:26 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The string method of the plist class writes a command string that can be | |
11 % used to recreate the input object(s). But the object should not have more than | |
12 % one history step. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_plist_string(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'plist'; | |
23 mthd = 'string'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 % Test PLIST objects | |
31 [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist; | |
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]; % Negative test: The object have more than one history step. | |
43 results = [results utp_07]; % Test different objects for 'val' | |
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 ~= 0, atest = false; end | |
112 % Check key | |
113 % Check default value | |
114 % Check options | |
115 end | |
116 % </AlgoCode> | |
117 else | |
118 atest = false; | |
119 end | |
120 | |
121 % Return a result structure | |
122 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
123 end % END UTP_01 | |
124 | |
125 %% UTP_02 | |
126 | |
127 % <TestDescription> | |
128 % | |
129 % Tests that the string method works with a vector of PLIST objects as input. | |
130 % | |
131 % </TestDescription> | |
132 function result = utp_02 | |
133 | |
134 % <SyntaxDescription> | |
135 % | |
136 % Test that the string method works for a vector of PLIST objects as input. | |
137 % | |
138 % </SyntaxDescription> | |
139 | |
140 try | |
141 % <SyntaxCode> | |
142 out = string(plv); | |
143 rout = eval(out); | |
144 % </SyntaxCode> | |
145 stest = true; | |
146 catch err | |
147 disp(err.message) | |
148 stest = false; | |
149 end | |
150 | |
151 % <AlgoDescription> | |
152 % | |
153 % 1) Check that the output is a executable string. | |
154 % 2) Check the correct number of rout | |
155 % 3) Check the rebuild objects. | |
156 % | |
157 % </AlgoDescription> | |
158 | |
159 atest = true; | |
160 if stest | |
161 % <AlgoCode> | |
162 % Check the output | |
163 if ~ischar(out), atest = false; end; | |
164 if ~isa(rout, 'plist'), atest = false; end | |
165 if numel(rout) ~= numel(plv), atest = false; end | |
166 for kk = 1:numel(plv) | |
167 if eq(rout(kk), plv(kk)), atest = false; 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 string method works with a matrix of PLIST objects as input. | |
183 % | |
184 % </TestDescription> | |
185 function result = utp_03 | |
186 | |
187 % <SyntaxDescription> | |
188 % | |
189 % Test that the string method works for a matrix of PLIST objects as input. | |
190 % | |
191 % </SyntaxDescription> | |
192 | |
193 try | |
194 % <SyntaxCode> | |
195 out = string(plm); | |
196 rout = eval(out); | |
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 output is a executable string. | |
207 % 2) Check the correct number of rout | |
208 % 3) Check the rebuild objects. | |
209 % | |
210 % </AlgoDescription> | |
211 | |
212 atest = true; | |
213 if stest | |
214 % <AlgoCode> | |
215 % Check the output | |
216 if ~ischar(out), atest = false; end | |
217 if ~isa(rout, 'plist'), atest = false; end | |
218 if numel(rout) ~= numel(plm), atest = false; end | |
219 for kk = 1:numel(plm) | |
220 if eq(rout(kk), plm(kk)), atest = false; end | |
221 end | |
222 % </AlgoCode> | |
223 else | |
224 atest = false; | |
225 end | |
226 | |
227 % Return a result structure | |
228 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
229 end % END UTP_03 | |
230 | |
231 %% UTP_04 | |
232 | |
233 % <TestDescription> | |
234 % | |
235 % Tests that the string method works with a list of PLIST objects as input. | |
236 % | |
237 % </TestDescription> | |
238 function result = utp_04 | |
239 | |
240 % <SyntaxDescription> | |
241 % | |
242 % Test that the string method works for a list of PLIST objects as input. | |
243 % | |
244 % </SyntaxDescription> | |
245 | |
246 try | |
247 % <SyntaxCode> | |
248 out = string(pl4,pl3); | |
249 rout = eval(out); | |
250 % </SyntaxCode> | |
251 stest = true; | |
252 catch err | |
253 disp(err.message) | |
254 stest = false; | |
255 end | |
256 | |
257 % <AlgoDescription> | |
258 % | |
259 % 1) Check that the output is a executable string. | |
260 % 2) Check the correct number of rout | |
261 % 3) Check the rebuild objects. | |
262 % | |
263 % </AlgoDescription> | |
264 | |
265 atest = true; | |
266 plin = [pl4, pl3]; | |
267 if stest | |
268 % <AlgoCode> | |
269 % Check the output | |
270 if ~ischar(out), atest = false; end | |
271 if ~isa(rout, 'plist'), atest = false; end | |
272 if numel(rout) ~= numel(plin), atest = false; end | |
273 for kk = 1:numel(plin) | |
274 if eq(rout(kk), plin(kk)), atest = false; end | |
275 end | |
276 % </AlgoCode> | |
277 else | |
278 atest = false; | |
279 end | |
280 | |
281 % Return a result structure | |
282 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
283 end % END UTP_04 | |
284 | |
285 %% UTP_05 | |
286 | |
287 % <TestDescription> | |
288 % | |
289 % Tests that the string method works with a mix of different shaped PLIST objects | |
290 % as input. | |
291 % | |
292 % </TestDescription> | |
293 function result = utp_05 | |
294 | |
295 % <SyntaxDescription> | |
296 % | |
297 % Test that the string method works with an input of matrices and vectors | |
298 % and single PLIST objects. | |
299 % | |
300 % </SyntaxDescription> | |
301 | |
302 try | |
303 % <SyntaxCode> | |
304 out = string(pl4,plm,pl3); | |
305 rout = eval(out); | |
306 % </SyntaxCode> | |
307 stest = true; | |
308 catch err | |
309 disp(err.message) | |
310 stest = false; | |
311 end | |
312 | |
313 % <AlgoDescription> | |
314 % | |
315 % 1) Check that the output is a executable string. | |
316 % 2) Check the correct number of rout | |
317 % 3) Check the rebuild objects. | |
318 % | |
319 % </AlgoDescription> | |
320 | |
321 atest = true; | |
322 plin = [pl4, reshape(plm, 1, []), pl3]; | |
323 if stest | |
324 % <AlgoCode> | |
325 % Check the output | |
326 if ~ischar(out), atest = false; end | |
327 if ~isa(rout, 'plist'), atest = false; end | |
328 if numel(rout) ~= numel(plin), atest = false; end | |
329 for kk = 1:numel(plin) | |
330 if eq(rout(kk), plin(kk)), atest = false; end | |
331 end | |
332 % </AlgoCode> | |
333 else | |
334 atest = false; | |
335 end | |
336 | |
337 % Return a result structure | |
338 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
339 end % END UTP_05 | |
340 | |
341 %% UTP_06 | |
342 | |
343 % <TestDescription> | |
344 % | |
345 % Tests that the string method doesn't work if the PLIST object have more | |
346 % than one history step. | |
347 % | |
348 % </TestDescription> | |
349 function result = utp_06 | |
350 | |
351 % <SyntaxDescription> | |
352 % | |
353 % The method string throws an error because the input object have more than | |
354 % one history step. | |
355 % | |
356 % </SyntaxDescription> | |
357 | |
358 try | |
359 % <SyntaxCode> | |
360 iir = miir(plist('type', 'bandpass')); | |
361 iir.setName('Second history step'); | |
362 pl = plist('filter', iir); | |
363 out = pl.string(); | |
364 % </SyntaxCode> | |
365 stest = false; | |
366 catch err | |
367 stest = true; | |
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 accepts different objects for the 'val' property. | |
391 % | |
392 % </TestDescription> | |
393 function result = utp_07 | |
394 | |
395 % <SyntaxDescription> | |
396 % | |
397 % Create a plist with all possible objects for the 'val' property. | |
398 % | |
399 % </SyntaxDescription> | |
400 | |
401 try | |
402 % <SyntaxCode> | |
403 iir = miir(plist('type', 'lowpass')); | |
404 a = 'char'; | |
405 b = [1 2i 3; 4i 5 6]; | |
406 c = [true false true; false true false]; | |
407 d = java.util.TimeZone.getTimeZone('UTC'); | |
408 e = sym('[a b c; d e f]'); | |
409 f = plist('a', 'char'); | |
410 h = unit('m^-1/2 kg V^3/7'); | |
411 ii = [pz(3) pz(1,2) pz(1-2i) pz(-3)]; | |
412 j = [time(123) time('14:00:00')]; | |
413 k = [specwin('Kaiser', 10, 100) specwin('Hanning', 100)]; | |
414 % --- CHAR | |
415 pl1 = plist('key', 'this is a char'); | |
416 % --- NUMERIC | |
417 pl2 = plist('key', [1 2i 3; 4i 5 6]); | |
418 % --- LOGICAL | |
419 pl3 = plist('key', [true false true; false true false]); | |
420 % --- JAVA (timezone) | |
421 pl4 = plist('key', java.util.TimeZone.getTimeZone('UTC')); | |
422 % --- SYM | |
423 pl5 = plist('key', sym('[a b c; d e f]')); | |
424 % --- PLIST | |
425 pl6 = plist('key', plist('a', 'char')); | |
426 % --- CELL | |
427 cellval = {a b c d e f h ii j k}; | |
428 pl7 = plist('key', cellval); | |
429 % --- STRUCT | |
430 structval.a = a; | |
431 structval.b = b; | |
432 structval.c = c; | |
433 structval.d = d; | |
434 structval.e = e; | |
435 structval.f = f; | |
436 structval.h = h; | |
437 structval.ii = ii; | |
438 structval.j = j; | |
439 structval.k = k; | |
440 pl8 = plist('key', structval); | |
441 % --- LTPDA_NUO | |
442 % ------ HISTORY | |
443 iir = miir(plist('type', 'lowpass')); | |
444 pl9 = plist('key', iir.hist); | |
445 % ------ UNITS | |
446 pl10 = plist('key', unit('m^-1/2 kg V^3/7')); | |
447 % ------ PARAM | |
448 pl11 = plist('key', param('a', 'char')); | |
449 % ------ PROVENANCE | |
450 pl12 = plist('key', provenance); | |
451 % ------ PZ | |
452 pl13 = plist('key', [pz(3) pz(1,2) pz(1-2i) pz(-3)]); | |
453 % ------ TIME | |
454 pl14 = plist('key', [time(123) time('14:00:00')]); | |
455 % ------ SPECWIN | |
456 pl15 = plist('key', [specwin('Kaiser', 10, 100) specwin('Hanning', 100)]); | |
457 out1 = eval(pl1.string); | |
458 out2 = eval(pl2.string); | |
459 out3 = eval(pl3.string); | |
460 out4 = eval(pl4.string); | |
461 out5 = eval(pl5.string); | |
462 out6 = eval(pl6.string); | |
463 out7 = eval(pl7.string); | |
464 out8 = eval(pl8.string); | |
465 out9 = eval(pl9.string); | |
466 out10 = eval(pl10.string); | |
467 out11 = eval(pl11.string); | |
468 out12 = eval(pl12.string); | |
469 out13 = eval(pl13.string); | |
470 out14 = eval(pl14.string); | |
471 out15 = eval(pl15.string); | |
472 % </SyntaxCode> | |
473 stest = true; | |
474 catch err | |
475 stest = false; | |
476 end | |
477 | |
478 % <AlgoDescription> | |
479 % | |
480 % 1) Check that the output is a executable string | |
481 % | |
482 % </AlgoDescription> | |
483 | |
484 atest = true; | |
485 if stest | |
486 % <AlgoCode> | |
487 if ~eq(pl1, out1, ple2), atest = false; end | |
488 if ~eq(pl2, out2, ple2), atest = false; end | |
489 if ~eq(pl3, out3, ple2), atest = false; end | |
490 if ~eq(pl4, out4, ple2), atest = false; end | |
491 if ~eq(pl5, out5, ple2), atest = false; end | |
492 if ~eq(pl6, out6, ple2), atest = false; end | |
493 if ~eq(pl7, out7, ple2), atest = false; end | |
494 if ~eq(pl8, out8, ple2), atest = false; end | |
495 if ~eq(pl10, out10, ple2), atest = false; end | |
496 if ~eq(pl11, out11, ple2), atest = false; end | |
497 if ~eq(pl12, out12, ple2), atest = false; end | |
498 if ~eq(pl13, out13, ple2), atest = false; end | |
499 if ~eq(pl14, out14, ple2), atest = false; end | |
500 if ~eq(pl15, out15, ple2), atest = false; end | |
501 % </AlgoCode> | |
502 else | |
503 atest = false; | |
504 end | |
505 | |
506 % Return a result structure | |
507 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
508 end % END UTP_07 | |
509 | |
510 end |