comparison testing/utp_1.1/utps/plist/utp_plist_plist2cmds.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_PLIST2CMDS a set of UTPs for the plist/plist2cmds method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_plist_plist2cmds.m,v 1.4 2009/08/24 17:23:10 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The plist2cmds method of the plist class convert a plist to a set of
11 % commands.
12 %
13 % </MethodDescription>
14
15 function results = utp_plist_plist2cmds(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'plist';
22 mthd = 'plist2cmds';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test PLIST objects
30 [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist;
31
32 % Exception list for the UTPs:
33 % [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
34
35 % Run the tests
36 results = [results utp_01]; % getInfo call
37 results = [results utp_02]; % Vector input
38 results = [results utp_03]; % Matrix input
39 results = [results utp_04]; % List input
40 results = [results utp_05]; % Test with mixed input
41 results = [results utp_06]; % Test different objects for 'val'
42
43 disp('Done.');
44 disp('******************************************************');
45
46 elseif nargin == 1 % Check for UTP functions
47 if strcmp(varargin{1}, 'isutp')
48 results = 1;
49 else
50 results = 0;
51 end
52 else
53 error('### Incorrect inputs')
54 end
55
56 end
57
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 class = 'plist';
78 mthd = 'plist2cmds';
79
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 plist2cmds method works with a vector of PLIST objects as input.
134 %
135 % </TestDescription>
136 function result = utp_02
137
138 % <SyntaxDescription>
139 %
140 % The plist2cmds method doesn't works for a vector of PLIST objects as input.
141 %
142 % </SyntaxDescription>
143
144 try
145 % <SyntaxCode>
146 % </SyntaxCode>
147 stest = true;
148 catch err
149 disp(err.message)
150 stest = false;
151 end
152
153 % <AlgoDescription>
154 %
155 % 1) Nothing to test.
156 %
157 % </AlgoDescription>
158
159 atest = true;
160 if stest
161 % <AlgoCode>
162 % </AlgoCode>
163 else
164 atest = false;
165 end
166
167 % Return a result structure
168 result = utp_prepare_result(atest, stest, dbstack, mfilename);
169 end % END UTP_02
170
171 %% UTP_03
172
173 % <TestDescription>
174 %
175 % Tests that the plist2cmds method works with a matrix of PLIST objects as input.
176 %
177 % </TestDescription>
178 function result = utp_03
179
180 % <SyntaxDescription>
181 %
182 % The plist2cmds method doesn't works for a matrix of PLIST objects as input.
183 %
184 % </SyntaxDescription>
185
186 try
187 % <SyntaxCode>
188 % </SyntaxCode>
189 stest = true;
190 catch err
191 disp(err.message)
192 stest = false;
193 end
194
195 % <AlgoDescription>
196 %
197 % 1) Nothing to test.
198 %
199 % </AlgoDescription>
200
201 atest = true;
202 if stest
203 % <AlgoCode>
204 % </AlgoCode>
205 else
206 atest = false;
207 end
208
209 % Return a result structure
210 result = utp_prepare_result(atest, stest, dbstack, mfilename);
211 end % END UTP_03
212
213 %% UTP_04
214
215 % <TestDescription>
216 %
217 % Tests that the plist2cmds method works with a list of PLIST objects as input.
218 %
219 % </TestDescription>
220 function result = utp_04
221
222 % <SyntaxDescription>
223 %
224 % The plist2cmds method doesn't works for a list of PLIST objects as input.
225 %
226 % </SyntaxDescription>
227
228 try
229 % <SyntaxCode>
230 % </SyntaxCode>
231 stest = true;
232 catch err
233 disp(err.message)
234 stest = false;
235 end
236
237 % <AlgoDescription>
238 %
239 % 1) Nothing to test.
240 %
241 % </AlgoDescription>
242
243 atest = true;
244 if stest
245 % <AlgoCode>
246 % </AlgoCode>
247 else
248 atest = false;
249 end
250
251 % Return a result structure
252 result = utp_prepare_result(atest, stest, dbstack, mfilename);
253 end % END UTP_04
254
255 %% UTP_05
256
257 % <TestDescription>
258 %
259 % Tests that the plist2cmds method works with a mix of different shaped
260 % PLIST objects as input.
261 %
262 % </TestDescription>
263 function result = utp_05
264
265 % <SyntaxDescription>
266 %
267 % The plist2cmds method doesn't works with an input of matrices and vectors
268 % and single PLIST objects.
269 %
270 % </SyntaxDescription>
271
272 try
273 % <SyntaxCode>
274 % </SyntaxCode>
275 stest = true;
276 catch err
277 disp(err.message)
278 stest = false;
279 end
280
281 % <AlgoDescription>
282 %
283 % 1) Nothing to test
284 %
285 % </AlgoDescription>
286
287 atest = true;
288 if stest
289 % <AlgoCode>
290 % </AlgoCode>
291 else
292 atest = false;
293 end
294
295 % Return a result structure
296 result = utp_prepare_result(atest, stest, dbstack, mfilename);
297 end % END UTP_05
298
299 %% UTP_06
300
301 % <TestDescription>
302 %
303 % Tests that the plist2cmds method accepts different objects for the 'val' property.
304 %
305 % </TestDescription>
306 function result = utp_06
307
308 % <SyntaxDescription>
309 %
310 % Create a plist with all possible objects for the 'val' property.
311 %
312 % </SyntaxDescription>
313
314 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
315
316 try
317 % <SyntaxCode>
318 iir = miir(plist('type', 'lowpass'));
319 a = 'char';
320 b = [1 2i 3; 4i 5 6];
321 c = [true false true; false true false];
322 d = java.util.TimeZone.getTimeZone('UTC');
323 e = sym('[a b c; d e f]');
324 f = plist('a', 'char', 'b', ao(8)+ao(9));
325 g = iir.resp;
326 h = unit('m^-1/2 kg V^3/7');
327 ii = [pz(3) pz(1,2) pz(1-2i) pz(-3)];
328 j = [time(123) time('14:00:00')];
329 k = [specwin('Kaiser', 10, 100) specwin('Hanning', 100)];
330 % --- CHAR
331 pl1 = plist('key', 'this is a char');
332 % --- NUMERIC
333 pl2 = plist('key', [1 2i 3; 4i 5 6]);
334 % --- LOGICAL
335 pl3 = plist('key', [true false true; false true false]);
336 % --- JAVA (timezone)
337 pl4 = plist('key', java.util.TimeZone.getTimeZone('UTC'));
338 % --- SYM
339 pl5 = plist('key', sym('[a b c; d e f]'));
340 % --- PLIST
341 pl6 = plist('key', plist('a', 'char'));
342 % --- CELL
343 cellval = {a b c d e f g h ii j k (ao(8) + ao(9))};
344 pl7 = plist('key', cellval);
345 % --- STRUCT
346 structval.a = a;
347 structval.b = b;
348 structval.c = c;
349 structval.d = d;
350 structval.e = e;
351 structval.f = f;
352 structval.g = g;
353 structval.h = h;
354 structval.ii = ii;
355 structval.j = j;
356 structval.k = k;
357 pl8 = plist('key', structval);
358 % --- LTPDA_NUO
359 % ------ HISTORY
360 iir = miir(plist('type', 'lowpass'));
361 pl9 = plist('key', iir.hist);
362 % ------ UNITS
363 pl10 = plist('key', unit('m^-1/2 kg V^3/7'));
364 % ------ PARAM
365 pl11 = plist('key', param('a', 'char'));
366 % ------ PROVENANCE
367 pl12 = plist('key', provenance);
368 % ------ PZ
369 pl13 = plist('key', [pz(3) pz(1,2) pz(1-2i) pz(-3)]);
370 % ------ TIME
371 pl14 = plist('key', [time(123) time('14:00:00')]);
372 % ------ SPECWIN
373 pl15 = plist('key', [specwin('Kaiser', 10, 100) specwin('Hanning', 100)]);
374
375 pl = plist();
376 % Evaluate the commands
377 % The result is stored in the variable 'pl'.
378 out1 = pl1.plist2cmds;
379 eval(out1{1});
380 out1 = pl;
381 out2 = pl2.plist2cmds;
382 eval(out2{1})
383 out2 = pl;
384 out3 = pl3.plist2cmds;
385 eval(out3{1})
386 out3 = pl;
387 out4 = pl4.plist2cmds;
388 eval(out4{1})
389 out4 = pl;
390 out5 = pl5.plist2cmds;
391 eval(out5{1})
392 out5 = pl;
393 out6 = pl6.plist2cmds;
394 eval(out6{1})
395 out6 = pl;
396 out7 = pl7.plist2cmds;
397 for pp = numel(out7):-1:1
398 eval(out7{pp})
399 end
400 out7 = pl;
401 out8 = pl8.plist2cmds;
402 for pp = numel(out8):-1:1
403 eval(out8{pp})
404 end
405 out8 = pl;
406 out9 = pl9.plist2cmds;
407 for pp = numel(out9):-1:1
408 eval(out9{pp})
409 end
410 out9 = pl;
411 out10 = pl10.plist2cmds;
412 eval(out10{1})
413 out10 = pl;
414 out11 = pl11.plist2cmds;
415 eval(out11{1})
416 out11 = pl;
417 out12 = pl12.plist2cmds;
418 eval(out12{1})
419 out12 = pl;
420 out13 = pl13.plist2cmds;
421 eval(out13{1})
422 out13 = pl;
423 out14 = pl14.plist2cmds;
424 eval(out14{1})
425 out14 = pl;
426 out15 = pl15.plist2cmds;
427 eval(out15{1})
428 out15 = pl;
429 % </SyntaxCode>
430 stest = true;
431 catch err
432 stest = false;
433 end
434
435 % <AlgoDescription>
436 %
437 % 1) Check that the output is a executable plist2cmds
438 %
439 % </AlgoDescription>
440
441 atest = true;
442 if stest
443 % <AlgoCode>
444 if ~eq(pl1, out1, ple2), atest = false; end
445 if ~eq(pl2, out2, ple2), atest = false; end
446 if ~eq(pl3, out3, ple2), atest = false; end
447 if ~eq(pl4, out4, ple2), atest = false; end
448 if ~eq(pl5, out5, ple2), atest = false; end
449 if ~eq(pl6, out6, ple2), atest = false; end
450 if ~eq(pl7, out7, ple2), atest = false; end
451 if ~eq(pl8, out8, ple2), atest = false; end
452 if ~eq(pl10, out10, ple2), atest = false; end
453 if ~eq(pl11, out11, ple2), atest = false; end
454 if ~eq(pl12, out12, ple2), atest = false; end
455 if ~eq(pl13, out13, ple2), atest = false; end
456 if ~eq(pl14, out14, ple2), atest = false; end
457 if ~eq(pl15, out15, ple2), atest = false; end
458 % </AlgoCode>
459 else
460 atest = false;
461 end
462
463 % Return a result structure
464 result = utp_prepare_result(atest, stest, dbstack, mfilename);
465 end % END UTP_06
466