comparison testing/utp_1.1/utps/plist/utp_plist_combine.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_COMBINE a set of UTPs for the plist/combine method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_plist_combine.m,v 1.3 2009/07/22 14:02:25 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The combine method of the plist class combine multiple parameter lists
11 % (PLIST) objects into a single PLIST object.
12 %
13 % </MethodDescription>
14
15 function results = utp_plist_combine(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'plist';
22 mthd = 'combine';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test PLIST objects
30 pl1 = plist('a', 1);
31 pl2 = plist('b', 2);
32 pl3 = plist('c', 3);
33 pl4 = plist('d', 4, 'e', 5);
34 plv = [pl1, pl2, pl3];
35 plm = [pl1, pl2; pl3 pl4];
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 the modify call works
47 results = [results utp_07]; % Test with different inputs for the key/value pair
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 combine method works with a vector of PLIST objects as input.
134 %
135 % </TestDescription>
136 function result = utp_02
137
138 % <SyntaxDescription>
139 %
140 % Test that the combine method combines all input PLIST objects to one object.
141 %
142 % </SyntaxDescription>
143
144 try
145 % <SyntaxCode>
146 out = combine(plv);
147 % </SyntaxCode>
148 stest = true;
149 catch err
150 disp(err.message)
151 stest = false;
152 end
153
154 % <AlgoDescription>
155 %
156 % 1) Check that the output is one PLIST object.
157 % 2) Check that the output PLIST contains all key/value pairs.
158 %
159 % </AlgoDescription>
160
161 atest = true;
162 if stest
163 % <AlgoCode>
164 % Check we have the correct number of outputs
165 if ~isa(out, 'plist') && numel(out) ==1, atest = false; end
166 % Check that the output have all key/value pairs
167 for ii = 1:numel(plv)
168 for kk = 1:plv(ii).nparams
169 pp = plv(ii).params(kk);
170 if ~isequal(out.find(pp.key), pp.getVal), atest = false; end
171 end
172 end
173
174 % </AlgoCode>
175 else
176 atest = false;
177 end
178
179 % Return a result structure
180 result = utp_prepare_result(atest, stest, dbstack, mfilename);
181 end % END UTP_02
182
183 %% UTP_03
184
185 % <TestDescription>
186 %
187 % Tests that the combine method works with a matrix of PLIST objects as input.
188 %
189 % </TestDescription>
190 function result = utp_03
191
192 % <SyntaxDescription>
193 %
194 % Test that the combine method combines all input PLIST objects to one object.
195 %
196 % </SyntaxDescription>
197
198 try
199 % <SyntaxCode>
200 out = combine(plm);
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 one PLIST object.
211 % 2) Check that the output PLIST contains all key/value pairs.
212 %
213 % </AlgoDescription>
214
215 atest = true;
216 if stest
217 % <AlgoCode>
218 % Check we have the correct number of outputs
219 if ~isa(out, 'plist') && numel(out) ==1, atest = false; end
220 % Check that the output have all key/value pairs
221 for ii = 1:numel(plm)
222 for kk = 1:plm(ii).nparams
223 pp = plm(ii).params(kk);
224 if ~isequal(out.find(pp.key), pp.getVal), atest = false; end
225 end
226 end
227
228 % </AlgoCode>
229 else
230 atest = false;
231 end
232
233 % Return a result structure
234 result = utp_prepare_result(atest, stest, dbstack, mfilename);
235 end % END UTP_03
236
237 %% UTP_04
238
239 % <TestDescription>
240 %
241 % Tests that the combine method works with a list of PLIST objects as input.
242 %
243 % </TestDescription>
244 function result = utp_04
245
246 % <SyntaxDescription>
247 %
248 % Test that the combine method combines all input PLIST objects to one object.
249 %
250 % </SyntaxDescription>
251
252 try
253 % <SyntaxCode>
254 out = combine(pl1, pl2, pl3);
255 % </SyntaxCode>
256 stest = true;
257 catch err
258 disp(err.message)
259 stest = false;
260 end
261
262 % <AlgoDescription>
263 %
264 % 1) Check that the output is one PLIST object.
265 % 2) Check that the output PLIST contains all key/value pairs.
266 %
267 % </AlgoDescription>
268
269 atest = true;
270 plin = [pl1, pl2, pl3];
271 if stest
272 % <AlgoCode>
273 % Check we have the correct number of outputs
274 if ~isa(out, 'plist') && numel(out) ==1, atest = false; end
275 % Check that the output have all key/value pairs
276 for ii = 1:numel(plin)
277 for kk = 1:plin(ii).nparams
278 pp = plin(ii).params(kk);
279 if ~isequal(out.find(pp.key), pp.getVal), atest = false; end
280 end
281 end
282
283 % </AlgoCode>
284 else
285 atest = false;
286 end
287
288 % Return a result structure
289 result = utp_prepare_result(atest, stest, dbstack, mfilename);
290 end % END UTP_04
291
292 %% UTP_05
293
294 % <TestDescription>
295 %
296 % Tests that the combine method works with a mix of different shaped PLIST
297 % objects as input.
298 %
299 % </TestDescription>
300 function result = utp_05
301
302 % <SyntaxDescription>
303 %
304 % Test that the combine method combines all input PLIST objects to one object.
305 %
306 % </SyntaxDescription>
307
308 try
309 % <SyntaxCode>
310 out = combine(plm, plist('aa', 1));
311 % </SyntaxCode>
312 stest = true;
313 catch err
314 disp(err.message)
315 stest = false;
316 end
317
318 % <AlgoDescription>
319 %
320 % 1) Check that the output is one PLIST object.
321 % 2) Check that the output PLIST contains all key/value pairs.
322 %
323 % </AlgoDescription>
324
325 atest = true;
326 plin = [reshape(plm, 1, []), plist('aa', 1)];
327 if stest
328 % <AlgoCode>
329 % Check we have the correct number of outputs
330 if ~isa(out, 'plist') && numel(out) ==1, atest = false; end
331 % Check that the output have all key/value pairs
332 for ii = 1:numel(plin)
333 for kk = 1:plin(ii).nparams
334 pp = plin(ii).params(kk);
335 if ~isequal(out.find(pp.key), pp.getVal), atest = false; end
336 end
337 end
338
339 % </AlgoCode>
340 else
341 atest = false;
342 end
343
344 % Return a result structure
345 result = utp_prepare_result(atest, stest, dbstack, mfilename);
346 end % END UTP_05
347
348 %% UTP_06
349
350 % <TestDescription>
351 %
352 % Tests that the combine method applies the modify command
353 %
354 % </TestDescription>
355 function result = utp_06
356
357 % <SyntaxDescription>
358 %
359 % Test that the combine method can modify the input PLIST by calling with no
360 % output and that the method doesn't change the input of the function
361 % notation (with a equal sign).
362 %
363 % </SyntaxDescription>
364
365 try
366 % <SyntaxCode>
367 % copy at1 to work with
368 plin = plist(pl1);
369 % modify ain
370 out = plin.combine(pl2);
371 plin.combine(pl2);
372 % </SyntaxCode>
373 stest = true;
374 catch err
375 disp(err.message)
376 stest = false;
377 end
378
379 % <AlgoDescription>
380 %
381 % 1) Check that 'pl1' and 'plin' are now different.
382 % 2) Check that 'ain' combine the key/value pair.
383 %
384 % </AlgoDescription>
385
386 atest = true;
387 if stest
388 % <AlgoCode>
389 % Check that combine modified the input by comparing to the copy
390 if eq(plist(pl1), plin, ple1), atest = false; end
391 % Check that combine doesn't modified the input for the function notation
392 if ~eq(out, plin, ple1), atest = false; end
393 % Check that the modified input have the new key/value pairs
394 if ~isequal(plin.find('a'), 1), atest = false; end
395 if ~isequal(plin.find('b'), 2), atest = false; end
396 % </AlgoCode>
397 else
398 atest = false;
399 end
400
401 % Return a result structure
402 result = utp_prepare_result(atest, stest, dbstack, mfilename);
403 end % END UTP_06
404
405 %% UTP_07
406
407 % <TestDescription>
408 %
409 % Test the combine method doen't overwrite existing keys.
410 %
411 % </TestDescription>
412 function result = utp_07
413
414 % <SyntaxDescription>
415 %
416 % Duplicate parameters which are given priority in the order in which
417 % they appear in the input.
418 %
419 % </SyntaxDescription>
420
421 try
422 % <SyntaxCode>
423 pl1 = plist('a', 1, 'b', 2, 'c', 3);
424 pl2 = plist('b', 'new b', 'd', 4, 'c', 'new c');
425 pl3 = plist('b', 'newer b', 'e', 5, 'd', 'new d');
426 out = combine(pl1, pl2, pl3);
427 pl1.combine(pl2, pl3);
428 % </SyntaxCode>
429 stest = true;
430 catch err
431 disp(err.message)
432 stest = false;
433 end
434
435 % <AlgoDescription>
436 %
437 % 1) Check that the output have all key/value pairs in the order they
438 % appear.
439 %
440 % </AlgoDescription>
441
442 atest = true;
443 if stest
444 % <AlgoCode>
445 % Check number of params
446 if out.nparams ~= 5, atest = false; end
447 if pl1.nparams ~= 5, atest = false; end
448 % Check the params
449 if ~isequal(out.find('a'), 1), atest = false; end
450 if ~isequal(out.find('b'), 2), atest = false; end
451 if ~isequal(out.find('c'), 3), atest = false; end
452 if ~isequal(out.find('d'), 4), atest = false; end
453 if ~isequal(out.find('e'), 5), atest = false; end
454 if ~isequal(pl1.find('a'), 1), atest = false; end
455 if ~isequal(pl1.find('b'), 2), atest = false; end
456 if ~isequal(pl1.find('c'), 3), atest = false; end
457 if ~isequal(pl1.find('d'), 4), atest = false; end
458 if ~isequal(pl1.find('e'), 5), atest = false; end
459 % </AlgoCode>
460 else
461 atest = false;
462 end
463
464 % Return a result structure
465 result = utp_prepare_result(atest, stest, dbstack, mfilename);
466 end % END UTP_07
467
468 end