comparison testing/utp_1.1/utps/parfrac/utp_parfrac_setName.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_PARFRAC_SETNAME a set of UTPs for the parfrac/setName method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_parfrac_setName.m,v 1.4 2011/04/19 18:14:01 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The setName method of the parfrac class sets the name property.
11 %
12 % </MethodDescription>
13
14 function results = utp_parfrac_setName(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'parfrac';
21 mthd = 'setName';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test PARFRAC objects
29 [pf1,pf2,pf3,pfv,pfm] = get_test_objects_parfrac;
30
31 % Exception list for the UTPs:
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
33
34 % Run the tests
35 results = [results utp_01]; % getInfo call
36 results = [results utp_02]; % Vector input
37 results = [results utp_03]; % Matrix input
38 results = [results utp_04]; % List input
39 results = [results utp_05]; % Test with mixed input
40 results = [results utp_06]; % Test history is working
41 results = [results utp_07]; % Test the modify call works
42 results = [results utp_08]; % Set the property with a plist
43 results = [results utp_09]; % Test output of the data
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 ~= 1, atest = false; end
112 % Check key
113 if ~io(3).plists.isparam('name'), atest = false; end
114 % Check default value
115 if ~isEmptyChar(io(3).plists.find('name')), atest = false; end
116 % Check options
117 if ~isequal(io(3).plists.getOptionsForParam('name'), {''}), atest = false; end
118 end
119 % </AlgoCode>
120 else
121 atest = false;
122 end
123
124 % Return a result structure
125 result = utp_prepare_result(atest, stest, dbstack, mfilename);
126 end % END UTP_01
127
128 %% UTP_02
129
130 % <TestDescription>
131 %
132 % Tests that the setName method works with a vector of PARFRAC objects as
133 % input.
134 %
135 % </TestDescription>
136 function result = utp_02
137
138 % <SyntaxDescription>
139 %
140 % Test that the setName method works for a vector of PARFRAC objects as
141 % input.
142 %
143 % </SyntaxDescription>
144
145 try
146 % <SyntaxCode>
147 out = setName(pfv, 'my name');
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 number of elements in 'out' is the same as in 'pfv'
158 % 2) Check that each output contains the correct data.
159 %
160 % </AlgoDescription>
161
162 atest = true;
163 if stest
164 % <AlgoCode>
165 % Check we have the correct number of outputs
166 if ~isequal(size(out), size(pfv)), atest = false; end
167 % Check name field of each output
168 for kk=1:numel(out)
169 if ~strcmp(out(kk).name, 'my name'), atest = false; break; end
170 end
171 % </AlgoCode>
172 else
173 atest = false;
174 end
175
176 % Return a result structure
177 result = utp_prepare_result(atest, stest, dbstack, mfilename);
178 end % END UTP_02
179
180 %% UTP_03
181
182 % <TestDescription>
183 %
184 % Tests that the setName method works with a matrix of PARFRAC objects as
185 % input.
186 %
187 % </TestDescription>
188 function result = utp_03
189
190 % <SyntaxDescription>
191 %
192 % Test that the setName method works for a matrix of PARFRAC objects as
193 % input.
194 %
195 % </SyntaxDescription>
196
197 try
198 % <SyntaxCode>
199 out = setName(pfm, 'my name');
200 % </SyntaxCode>
201 stest = true;
202 catch err
203 disp(err.message)
204 stest = false;
205 end
206
207 % <AlgoDescription>
208 %
209 % 1) Check that the number of elements in 'out' is the same as in 'pfm'
210 % 2) Check that each output contains the correct data.
211 %
212 % </AlgoDescription>
213
214 atest = true;
215 if stest
216 % <AlgoCode>
217 % Check we have the correct number of outputs
218 if ~isequal(size(out), size(pfm)), atest = false; end
219 % Check name field of each output
220 for kk=1:numel(out)
221 if ~strcmp(out(kk).name, 'my name'), atest = false; break; end
222 end
223 % </AlgoCode>
224 else
225 atest = false;
226 end
227
228 % Return a result structure
229 result = utp_prepare_result(atest, stest, dbstack, mfilename);
230 end % END UTP_03
231
232 %% UTP_04
233
234 % <TestDescription>
235 %
236 % Tests that the setName method works with a list of PARFRAC objects as
237 % input.
238 %
239 % </TestDescription>
240 function result = utp_04
241
242 % <SyntaxDescription>
243 %
244 % Test that the setName method works for a list of PARFRAC objects as
245 % input.
246 %
247 % </SyntaxDescription>
248
249 try
250 % <SyntaxCode>
251 out = setName(pf1,pf2,pf3, 'my name');
252 % </SyntaxCode>
253 stest = true;
254 catch err
255 disp(err.message)
256 stest = false;
257 end
258
259 % <AlgoDescription>
260 %
261 % 1) Check that the number of elements in 'out' is the same as in
262 % input.
263 % 2) Check that each output contains the correct data.
264 %
265 % </AlgoDescription>
266
267 atest = true;
268 if stest
269 % <AlgoCode>
270 % Check we have the correct number of outputs
271 if numel(out) ~= 3, atest = false; end
272 % Check each output against the input
273 if ~strcmp(out(1).name, 'my name'), atest = false; end
274 if ~strcmp(out(2).name, 'my name'), atest = false; end
275 if ~strcmp(out(3).name, 'my name'), atest = false; 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 setName method works with a mix of different shaped
290 % PARFRAC objects as input.
291 %
292 % </TestDescription>
293 function result = utp_05
294
295 % <SyntaxDescription>
296 %
297 % Test that the setName method works with an input of matrices and
298 % vectors and single PARFRAC objects.
299 %
300 % </SyntaxDescription>
301
302 try
303 % <SyntaxCode>
304 out = setName(pf1,pfv,pf2,pfm,pf3, 'my name');
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 number of elements in 'out' is the same as in
315 % input.
316 % 2) Check that each output contains the correct data.
317 %
318 % </AlgoDescription>
319
320 atest = true;
321 if stest
322 % <AlgoCode>
323 % Check we have the correct number of outputs
324 if numel(out) ~= (3+numel(pfm)+numel(pfv)), atest = false; end
325 for kk=1:numel(out)
326 if ~strcmp(out(kk).name, 'my name'), atest = false; break; end
327 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 setName method properly applies history and that the
342 % option 'internal' suppresses the history.
343 %
344 % </TestDescription>
345 function result = utp_06
346
347 % <SyntaxDescription>
348 %
349 % Test that the result of applying the setName method can be processed
350 % back to an m-file.
351 %
352 % </SyntaxDescription>
353
354 try
355 % <SyntaxCode>
356 out1 = setName(pf3, 'my name');
357 out2 = testCallerIsMethod(@setName, pf3, 'my name');
358 mout1 = rebuild(out1);
359 mout2 = rebuild(out2);
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 last entry in the history of 'out1' corresponds to
370 % 'setName'.
371 % 2) Check that the last entry in the history of 'out2' NOT corresponds to
372 % 'setName'.
373 % 3) Check that the method rebuild produces the same object as 'out'.
374 %
375 % </AlgoDescription>
376
377 atest = true;
378 if stest
379 % <AlgoCode>
380 % Check the last step in the history of 'out1'
381 if ~(strcmp(out1.hist.methodInfo.mname, 'setName') && ...
382 eq(out1.hist.plistUsed, plist('name', 'my name'), ple1))
383 atest = false;
384 end
385 % Check the last step in the history of 'out2'
386 if eq(out2.hist.plistUsed, plist('name', 'my name'), ple1)
387 atest = false;
388 end
389 % Check the rebuilt object
390 if ~eq(mout1, out1, ple1), atest = false; end
391 e = ple1.find('EXCEPTIONS');
392 ple = plist('EXCEPTIONS', [e {'name'}]);
393 if ~eq(mout2, out2, ple), atest = false; end
394 % </AlgoCode>
395 else
396 atest = false;
397 end
398
399 % Return a result structure
400 result = utp_prepare_result(atest, stest, dbstack, mfilename);
401 end % END UTP_06
402
403 %% UTP_07
404
405 % <TestDescription>
406 %
407 % Tests that the setName method can modify the input PARFRAC object.
408 %
409 % </TestDescription>
410 function result = utp_07
411
412 % <SyntaxDescription>
413 %
414 % Test that the setName method can modify the input PARFRAC object
415 % by calling with no output.
416 %
417 % </SyntaxDescription>
418
419 try
420 % <SyntaxCode>
421 % copy pf3 to work with
422 ain = parfrac(pf3);
423 % modify ain
424 aout = ain.setName('my name');
425 ain.setName('my name');
426 % </SyntaxCode>
427 stest = true;
428 catch err
429 disp(err.message)
430 stest = false;
431 end
432
433 % <AlgoDescription>
434 %
435 % 1) Check that 'pf3' and 'ain' are now different.
436 % 2) Check that 'ain' has the correct name field
437 %
438 % </AlgoDescription>
439
440 atest = true;
441 if stest
442 % <AlgoCode>
443 % Check that setName modified the input by comparing to the copy
444 if eq(parfrac(pf3), ain, ple1), atest = false; end
445 % Check that setName doesn't modified the input for the function notation
446 if ~eq(aout, ain, ple1), atest = false; end
447 % Check that the modified object contains the changed value
448 if ~strcmp(ain.name, 'my name'), atest = false; end
449 % </AlgoCode>
450 else
451 atest = false;
452 end
453
454 % Return a result structure
455 result = utp_prepare_result(atest, stest, dbstack, mfilename);
456 end % END UTP_07
457
458 %% UTP_08
459
460 % <TestDescription>
461 %
462 % Tests that the setName method can set the property with a plist.
463 %
464 % </TestDescription>
465 function result = utp_08
466
467 % <SyntaxDescription>
468 %
469 % Test that the setName method can modify the property 'name'
470 % with a value in a plist.
471 %
472 % </SyntaxDescription>
473
474 try
475 % <SyntaxCode>
476 pl = plist('name', 'my name');
477 out = pf3.setName(pl);
478 mout = rebuild(out);
479 % </SyntaxCode>
480 stest = true;
481 catch err
482 disp(err.message)
483 stest = false;
484 end
485
486 % <AlgoDescription>
487 %
488 % 1) Check that 'ain' has the correct name field
489 % 2) Check that the method rebuild produces the same object as 'out'.
490 %
491 % </AlgoDescription>
492
493 atest = true;
494 if stest
495 % <AlgoCode>
496 % Check the field 'name'
497 if ~strcmp(out.name, 'my name'), atest = false; end
498 % Check the rebuilt object
499 if ~eq(mout, out, ple1), atest = false; end
500 % </AlgoCode>
501 else
502 atest = false;
503 end
504
505 % Return a result structure
506 result = utp_prepare_result(atest, stest, dbstack, mfilename);
507 end % END UTP_08
508
509 %% UTP_09
510
511 % <TestDescription>
512 %
513 % Check that the setName method pass back the output objects to a list of
514 % output variables or to a single variable.
515 %
516 % </TestDescription>
517 function result = utp_09
518
519 % <SyntaxDescription>
520 %
521 % Call the method with a list of output variables and with a single
522 % output variable. Additionaly check that the rebuild method works on
523 % the output.
524 %
525 % </SyntaxDescription>
526
527 try
528 % <SyntaxCode>
529 [o1, o2] = setName(pf3, pf2, 'new name');
530 o3 = setName(pf3, pf2, 'new name');
531 mout1 = rebuild(o1);
532 mout2 = rebuild(o2);
533 mout3 = rebuild(o3);
534 % </SyntaxCode>
535 stest = true;
536 catch err
537 disp(err.message)
538 stest = false;
539 end
540
541 % <AlgoDescription>
542 %
543 % 1) Check that the output contains the right number of objects
544 % 2) Check that the 'rebuild' method produces the same object as 'out'.
545 %
546 % </AlgoDescription>
547
548 atest = true;
549 if stest
550 % <AlgoCode>
551 % Check the number of outputs
552 if numel(o1) ~=1, atest = false; end
553 if numel(o2) ~=1, atest = false; end
554 if numel(o3) ~=2, atest = false; end
555 % Check the rebuilding of the object
556 if ~eq(o1, mout1, ple2), atest = false; end
557 if ~eq(o2, mout2, ple2), atest = false; end
558 if ~eq(o3, mout3, ple2), atest = false; end
559 % </AlgoCode>
560 else
561 atest = false;
562 end
563
564 % Return a result structure
565 result = utp_prepare_result(atest, stest, dbstack, mfilename);
566 end % END UTP_09
567
568 end