comparison testing/utp_1.1/utps/pzmodel/utp_pzmodel_index.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_PZMODEL_INDEX a set of UTPs for the pzmodel/index method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_pzmodel_index.m,v 1.4 2009/07/28 17:12:38 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The index method of the pzmodel class index into a PZMODEL vector or
11 % matrix. This properly captures the history.
12 %
13 % </MethodDescription>
14
15 function results = utp_pzmodel_index(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'pzmodel';
22 mthd = 'index';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test PZMODEL objects
30 [pz1, pz2, pz3, pz4, pz5, pzv, pzm] = get_test_objects_pzmodel;
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 history is working
41 results = [results utp_06]; % Test the modify call works
42 results = [results utp_07]; % Test with plist
43 results = [results utp_08]; % Test select more objects with an index
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 ~= 2, atest = false; end
112 % Check key
113 if ~io(3).plists.isparam('i'), atest = false; end
114 if ~io(3).plists.isparam('j'), atest = false; end
115 % Check default value
116 if ~isEmptyDouble(io(3).plists.find('i')), atest = false; end
117 if ~isEmptyDouble(io(3).plists.find('j')), atest = false; end
118 % Check options
119 if ~isequal(io(3).plists.getOptionsForParam('i'), {[]}), atest = false; end
120 if ~isequal(io(3).plists.getOptionsForParam('j'), {[]}), atest = false; end
121 end
122 % </AlgoCode>
123 else
124 atest = false;
125 end
126
127 % Return a result structure
128 result = utp_prepare_result(atest, stest, dbstack, mfilename);
129 end % END UTP_01
130
131 %% UTP_02
132
133 % <TestDescription>
134 %
135 % Tests that the index method works with a vector of PZMODEL objects as
136 % input.
137 %
138 % </TestDescription>
139 function result = utp_02
140
141 % <SyntaxDescription>
142 %
143 % Test that the index method works for a vector of PZMODEL objects as
144 % input. The following indexing should work:
145 % I = [ 1 2 3 ] or (I/J) = [(1,1), (1,2), (1,3)]
146 %
147 % </SyntaxDescription>
148
149 try
150 % <SyntaxCode>
151 objvec = [pz1, pz2, pz3];
152 out1 = objvec.index(1);
153 out2 = objvec.index(3);
154 out3 = objvec.index(1,2);
155 % </SyntaxCode>
156 stest = true;
157 catch err
158 disp(err.message)
159 stest = false;
160 end
161
162 % <AlgoDescription>
163 %
164 % 1) Check that the index method selects the correct object.
165 %
166 % </AlgoDescription>
167
168 atest = true;
169 if stest
170 % <AlgoCode>
171 if ~eq(out1, pz1, ple3), atest = false; end
172 if ~eq(out2, pz3, ple3), atest = false; end
173 if ~eq(out3, pz2, ple3), atest = false; end
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 index method works with a matrix of PZMODEL objects as
188 % input.
189 %
190 % </TestDescription>
191 function result = utp_03
192
193 % <SyntaxDescription>
194 %
195 % Test that the index method works for a matrix of PZMODEL objects as
196 % input. The following indexing should work:
197 % I = [ 1 3 5 ] or (I/J) = [(1,1), (1,2), (1,3)]
198 % [ 2 4 6 ] [(2,1), (2,2), (2,3)]
199 % </SyntaxDescription>
200
201 try
202 % <SyntaxCode>
203 objmat = [pz1, pz2, pz3; ...
204 pz3, pz1, pz2];
205 out1 = objmat.index(5);
206 out2 = objmat.index(4);
207 out3 = objmat.index(1,2);
208 out4 = objmat.index(2,1);
209 out5 = objmat.index(2,2);
210 % </SyntaxCode>
211 stest = true;
212 catch err
213 disp(err.message)
214 stest = false;
215 end
216
217 % <AlgoDescription>
218 %
219 % 1) Check that the index method selects the correct object.
220 %
221 % </AlgoDescription>
222
223 atest = true;
224 if stest
225 % <AlgoCode>
226 if ~eq(out1, pz3, ple3), atest = false; end
227 if ~eq(out2, pz1, ple3), atest = false; end
228 if ~eq(out3, pz2, ple3), atest = false; end
229 if ~eq(out4, pz3, ple3), atest = false; end
230 if ~eq(out5, pz1, ple3), atest = false; end
231 % </AlgoCode>
232 else
233 atest = false;
234 end
235
236 % Return a result structure
237 result = utp_prepare_result(atest, stest, dbstack, mfilename);
238 end % END UTP_03
239
240 %% UTP_04
241
242 % <TestDescription>
243 %
244 % Tests that the index method works with a list of PZMODEL objects as
245 % input.
246 %
247 % </TestDescription>
248 function result = utp_04
249
250 % <SyntaxDescription>
251 %
252 % The index method doesn't work for a list of PZMODEL objects as input.
253 %
254 % </SyntaxDescription>
255
256 try
257 % <SyntaxCode>
258 out = index(pz1,pz2,pz3, 4);
259 % </SyntaxCode>
260 stest = false;
261 catch
262 stest = true;
263 end
264
265 % <AlgoDescription>
266 %
267 % 1) Nothing to test.
268 %
269 % </AlgoDescription>
270
271 atest = true;
272 if stest
273 % <AlgoCode>
274 % </AlgoCode>
275 else
276 atest = false;
277 end
278
279 % Return a result structure
280 result = utp_prepare_result(atest, stest, dbstack, mfilename);
281 end % END UTP_04
282
283 %% UTP_05
284
285 % <TestDescription>
286 %
287 % Tests that the index method properly applies history.
288 %
289 % </TestDescription>
290 function result = utp_05
291
292 % <SyntaxDescription>
293 %
294 % Test that the result of index have an additional history step.
295 %
296 % </SyntaxDescription>
297
298 try
299 % <SyntaxCode>
300 i = 2;
301 j = 3;
302 objmat = [pz1, pz2, pz3; ...
303 pz3, pz1, pz2];
304 out = index(objmat, i, j);
305 % </SyntaxCode>
306 stest = true;
307 catch err
308 disp(err.message)
309 stest = false;
310 end
311
312 % <AlgoDescription>
313 %
314 % 1) Check that the last entry in the history of 'out' corresponds
315 % to 'index'.
316 %
317 % </AlgoDescription>
318
319 atest = true;
320 if stest
321 % <AlgoCode>
322 % Check the last step in the history of 'out'
323 if ~strcmp(out.hist.methodInfo.mname, 'index'), atest = false; end
324 % Check that the history-plist contains the used indices.
325 pl = out.hist.plistUsed;
326 if pl.find('i') ~= i, atest = false; end
327 if pl.find('j') ~= j, atest = false; end
328 % </AlgoCode>
329 else
330 atest = false;
331 end
332
333 % Return a result structure
334 result = utp_prepare_result(atest, stest, dbstack, mfilename);
335 end % END UTP_05
336
337 %% UTP_06
338
339 % <TestDescription>
340 %
341 % Tests that the index method works for the modifier command.
342 %
343 % </TestDescription>
344 function result = utp_06
345
346 % <SyntaxDescription>
347 %
348 % Tests that the index method works for the modifier command.
349 %
350 % </SyntaxDescription>
351
352 try
353 % <SyntaxCode>
354 i = 1;
355 j = 1;
356 objmat = [pz1, pz2, pz3; ...
357 pz3, pz1, pz2];
358 out1 = index(objmat, i, j);
359 out2 = objmat.index(i,j);
360 % </SyntaxCode>
361 stest = true;
362 catch err
363 disp(err.message)
364 stest = false;
365 end
366
367 % <AlgoDescription>
368 %
369 % 1) Check that the history-plist contains the used indices.
370 % 2) Check that the index method selects the correct object
371 %
372 % </AlgoDescription>
373
374 atest = true;
375 if stest
376 % <AlgoCode>
377 % Check that the history-plist contains the used indices.
378 pl = out1.hist.plistUsed;
379 if pl.find('i') ~= i, atest = false; end
380 if pl.find('j') ~= j, atest = false; end
381 % Check that the index method selects the correct object
382 if ~eq(out1, pz1, ple3), atest = false; end
383 % Check that the history-plist contains the used indices.
384 pl = out2.hist.plistUsed;
385 if pl.find('i') ~= i, atest = false; end
386 if pl.find('j') ~= j, atest = false; end
387 % Check that the index method selects the correct object
388 if ~eq(out2, pz1, ple3), atest = false; end
389 % </AlgoCode>
390 else
391 atest = false;
392 end
393
394 % Return a result structure
395 result = utp_prepare_result(atest, stest, dbstack, mfilename);
396 end % END UTP_06
397
398 %% UTP_07
399
400 % <TestDescription>
401 %
402 % Control the method with a plist.
403 %
404 % </TestDescription>
405 function result = utp_07
406
407 % <SyntaxDescription>
408 %
409 % Test that the index method can be controled with a plist.
410 %
411 % </SyntaxDescription>
412
413 try
414 % <SyntaxCode>
415 i1 = 6;
416 i2 = 1;
417 j2 = 3;
418 objmat = [pz1, pz2, pz3; ...
419 pz3, pz1, pz2];
420 pl1 = plist('i', i1);
421 pl2 = plist('i', i2, 'j', j2);
422 out1 = index(objmat, pl1);
423 out2 = index(objmat, pl2);
424 % </SyntaxCode>
425 stest = true;
426 catch err
427 disp(err.message)
428 stest = false;
429 end
430
431 % <AlgoDescription>
432 %
433 % 1) Check that the history-plist contains the used indices.
434 % 2) Check that the index method selects the correct object
435 %
436 % </AlgoDescription>
437
438 atest = true;
439 if stest
440 % <AlgoCode>
441 % Check that the history-plist contains the used indices.
442 pl = out1.hist.plistUsed;
443 if ~isequal(pl.find('i'), i1), atest = false; end
444 if ~isequal(pl.find('j'), []), atest = false; end
445 % Check that the index method selects the correct object
446 if ~eq(out1, pz2, ple3), atest = false; end
447 % Check that the history-plist contains the used indices.
448 pl = out2.hist.plistUsed;
449 if ~isequal(pl.find('i'), i2), atest = false; end
450 if ~isequal(pl.find('j'), j2), atest = false; end
451 % Check that the index method selects the correct object
452 if ~eq(out2, pz3, ple3), atest = false; end
453 % </AlgoCode>
454 else
455 atest = false;
456 end
457
458 % Return a result structure
459 result = utp_prepare_result(atest, stest, dbstack, mfilename);
460 end % END UTP_07
461
462 %% UTP_08
463
464 % <TestDescription>
465 %
466 % Test that the index method selects more objects if I have more indices.
467 %
468 % </TestDescription>
469 function result = utp_08
470
471 % <SyntaxDescription>
472 %
473 % Test that the index method selects more objects if I have more indices.
474 %
475 % </SyntaxDescription>
476
477 try
478 % <SyntaxCode>
479 i = [2 6];
480 objmat = [pz1, pz2, pz3; ...
481 pz3, pz1, pz2];
482 pl = plist('i', i);
483 out1 = objmat.index(i);
484 out2 = objmat.index(pl);
485 % </SyntaxCode>
486 stest = true;
487 catch err
488 disp(err.message)
489 stest = false;
490 end
491
492 % <AlgoDescription>
493 %
494 % 1) Check that the history-plist contains the used indices.
495 % 2) Check that the index method selects the correct object
496 %
497 % </AlgoDescription>
498
499 atest = true;
500 if stest
501 % <AlgoCode>
502 % Check that the history-plist contains the used indices.
503 pl = out1(1).hist.plistUsed;
504 if ~isequal(pl.find('i'), i), atest = false; end
505 if ~isequal(pl.find('j'), []), atest = false; end
506 % Check that the index method selects the correct object
507 if ~eq(out1(1), pz3, ple3), atest = false; end
508 if ~eq(out1(2), pz2, ple3), atest = false; end
509 % Check that the history-plist contains the used indices.
510 pl = out2(2).hist.plistUsed;
511 if ~isequal(pl.find('i'), i), atest = false; end
512 if ~isequal(pl.find('j'), []), atest = false; end
513 % Check that the index method selects the correct object
514 if ~eq(out2(1), pz3, ple3), atest = false; end
515 if ~eq(out2(2), pz2, ple3), atest = false; end
516 % </AlgoCode>
517 else
518 atest = false;
519 end
520
521 % Return a result structure
522 result = utp_prepare_result(atest, stest, dbstack, mfilename);
523 end % END UTP_08
524
525 end