comparison testing/utp_1.1/utps/parfrac/utp_parfrac_isprop.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_ISPROP a set of UTPs for the parfrac/isprop method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_parfrac_isprop.m,v 1.3 2011/03/29 13:13:33 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The isprop method of the parfrac class determine whether input is object
11 % property.
12 %
13 % </MethodDescription>
14
15 function results = utp_parfrac_isprop(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'parfrac';
22 mthd = 'isprop';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test PARFRAC objects
30 [pf1,pf2,pf3,pfv,pfm] = get_test_objects_parfrac;
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 history is working
42 results = [results utp_07]; % Test the modify call works
43 results = [results utp_08]; % Test negative case
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 isprop method works with a vector of PARFRAC objects as
130 % input.
131 %
132 % </TestDescription>
133 function result = utp_02
134
135 % <SyntaxDescription>
136 %
137 % Test that the isprop method works for a vector of PARFRAC objects as
138 % input.
139 %
140 % </SyntaxDescription>
141
142 try
143 % <SyntaxCode>
144 out = isprop(pfv, 'name');
145 % </SyntaxCode>
146 stest = true;
147 catch err
148 disp(err.message)
149 stest = false;
150 end
151
152 % <AlgoDescription>
153 %
154 % 1) Check that the number of elements in 'out' is the same as in 'pfv'
155 % 2) Check that each output contains the correct data.
156 %
157 % </AlgoDescription>
158
159 atest = true;
160 if stest
161 % <AlgoCode>
162 % Check we have the correct number of outputs
163 if ~isequal(size(out), size(pfv)), atest = false; end
164 % Check each output
165 if ~all(out), atest = false; end
166 % </AlgoCode>
167 else
168 atest = false;
169 end
170
171 % Return a result structure
172 result = utp_prepare_result(atest, stest, dbstack, mfilename);
173 end % END UTP_02
174
175 %% UTP_03
176
177 % <TestDescription>
178 %
179 % Tests that the isprop method works with a matrix of PARFRAC objects as
180 % input.
181 %
182 % </TestDescription>
183 function result = utp_03
184
185 % <SyntaxDescription>
186 %
187 % Test that the isprop method works for a matrix of PARFRAC objects as
188 % input.
189 %
190 % </SyntaxDescription>
191
192 try
193 % <SyntaxCode>
194 out = isprop(pfm, 'name');
195 % </SyntaxCode>
196 stest = true;
197 catch err
198 disp(err.message)
199 stest = false;
200 end
201
202 % <AlgoDescription>
203 %
204 % 1) Check that the number of elements in 'out' is the same as in 'pfm'
205 % 2) Check that each output contains the correct data.
206 %
207 % </AlgoDescription>
208
209 atest = true;
210 if stest
211 % <AlgoCode>
212 % Check we have the correct number of outputs
213 if ~isequal(size(out), size(pfm)), atest = false; end
214 % Check each output
215 if ~all(out), atest = false; end
216 % </AlgoCode>
217 else
218 atest = false;
219 end
220
221 % Return a result structure
222 result = utp_prepare_result(atest, stest, dbstack, mfilename);
223 end % END UTP_03
224
225 %% UTP_04
226
227 % <TestDescription>
228 %
229 % Tests that the isprop method works with a list of PARFRAC objects as
230 % input.
231 %
232 % </TestDescription>
233 function result = utp_04
234
235 % <SyntaxDescription>
236 %
237 % Test that the isprop method works for a list of PARFRAC objects as
238 % input.
239 %
240 % </SyntaxDescription>
241
242 try
243 % <SyntaxCode>
244 out = isprop(pf1,pf2,pf3, 'name');
245 % </SyntaxCode>
246 stest = true;
247 catch err
248 disp(err.message)
249 stest = false;
250 end
251
252 % <AlgoDescription>
253 %
254 % 1) Check that the number of elements in 'out' is the same as in
255 % input.
256 % 2) Check that each output contains the correct data.
257 %
258 % </AlgoDescription>
259
260 atest = true;
261 if stest
262 % <AlgoCode>
263 % Check we have the correct number of outputs
264 if numel(out) ~= 3, atest = false; end
265 % Check each output
266 if ~all(out), atest = false; end
267 % </AlgoCode>
268 else
269 atest = false;
270 end
271
272 % Return a result structure
273 result = utp_prepare_result(atest, stest, dbstack, mfilename);
274 end % END UTP_04
275
276 %% UTP_05
277
278 % <TestDescription>
279 %
280 % Tests that the isprop method works with a mix of different shaped
281 % PARFRAC objects as input.
282 %
283 % </TestDescription>
284 function result = utp_05
285
286 % <SyntaxDescription>
287 %
288 % Test that the isprop method works with an input of matrices and
289 % vectors and single PARFRAC objects.
290 %
291 % </SyntaxDescription>
292
293 try
294 % <SyntaxCode>
295 out = isprop(pf1,pfv,pf2,pfm,pf3, 'name');
296 % </SyntaxCode>
297 stest = true;
298 catch err
299 disp(err.message)
300 stest = false;
301 end
302
303 % <AlgoDescription>
304 %
305 % 1) Check that the number of elements in 'out' is the same as in
306 % input.
307 % 2) Check that each output contains the correct data.
308 %
309 % </AlgoDescription>
310
311 atest = true;
312 if stest
313 % <AlgoCode>
314 % Check we have the correct number of outputs
315 if numel(out) ~= (3+numel(pfm)+numel(pfv)), atest = false; end
316 % Check each output
317 if ~all(out), atest = false; end
318 % </AlgoCode>
319 else
320 atest = false;
321 end
322
323 % Return a result structure
324 result = utp_prepare_result(atest, stest, dbstack, mfilename);
325 end % END UTP_05
326
327 %% UTP_06
328
329 % <TestDescription>
330 %
331 % Tests that the isprop method properly applies history.
332 %
333 % </TestDescription>
334 function result = utp_06
335
336 % <SyntaxDescription>
337 %
338 % The method isprop doesn't change the object, thus it is not necessary
339 % to apply history.
340 %
341 % </SyntaxDescription>
342
343 try
344 % <SyntaxCode>
345 % </SyntaxCode>
346 stest = true;
347 catch err
348 disp(err.message)
349 stest = false;
350 end
351
352 % <AlgoDescription>
353 %
354 % </AlgoDescription>
355
356 atest = true;
357 if stest
358 % <AlgoCode>
359 % </AlgoCode>
360 else
361 atest = false;
362 end
363
364 % Return a result structure
365 result = utp_prepare_result(atest, stest, dbstack, mfilename);
366 end % END UTP_06
367
368 %% UTP_07
369
370 % <TestDescription>
371 %
372 % Tests that the isprop method works for each property.
373 %
374 % </TestDescription>
375 function result = utp_07
376
377 % <SyntaxDescription>
378 %
379 % Test that the isprop method works for the properties:
380 % 'res', 'poles', 'pmul', 'dir', 'iunits', 'ounits', 'hist',
381 % 'name'
382 %
383 % </SyntaxDescription>
384
385 try
386 % <SyntaxCode>
387 % copy pf1 to work with
388 out1 = isprop(pf1, 'res');
389 out2 = isprop(pf1, 'poles');
390 out3 = isprop(pf1, 'pmul');
391 out4 = isprop(pf1, 'dir');
392 out6 = isprop(pf1, 'iunits');
393 out7 = isprop(pf1, 'ounits');
394 out8 = isprop(pf1, 'hist');
395 out9 = isprop(pf1, 'name');
396 % </SyntaxCode>
397 stest = true;
398 catch err
399 disp(err.message)
400 stest = false;
401 end
402
403 % <AlgoDescription>
404 %
405 % 1) Check that each output contains the correct data.
406 %
407 % </AlgoDescription>
408
409 atest = true;
410 if stest
411 % <AlgoCode>
412 if ~out1, atest = false; end;
413 if ~out2, atest = false; end;
414 if ~out3, atest = false; end;
415 if ~out4, atest = false; end;
416 if ~out6, atest = false; end;
417 if ~out7, atest = false; end;
418 if ~out8, atest = false; end;
419 if ~out9, atest = false; end;
420 % </AlgoCode>
421 else
422 atest = false;
423 end
424
425 % Return a result structure
426 result = utp_prepare_result(atest, stest, dbstack, mfilename);
427 end % END UTP_07
428
429 %% UTP_08
430
431 % <TestDescription>
432 %
433 % Test the negative case and the not function command.
434 %
435 % </TestDescription>
436 function result = utp_08
437
438 % <SyntaxDescription>
439 %
440 % Test that the isprop method retrun false for a unknown property and
441 % for methods of the object.
442 %
443 % </SyntaxDescription>
444
445 try
446 % <SyntaxCode>
447 out1 = isprop(pf2, 'foo');
448 out2 = pf2.isprop('foo');
449 out3 = pf2.isprop('name');
450 out4 = pf2.isprop('type');
451 out5 = pf2.isprop('char');
452 out6 = pf2.isprop('creator');
453 out7 = pf2.isprop('created');
454 % </SyntaxCode>
455 stest = true;
456 catch err
457 disp(err.message)
458 stest = false;
459 end
460
461 % <AlgoDescription>
462 %
463 % 1) Check that each output contains the correct data.
464 %
465 % </AlgoDescription>
466
467 atest = true;
468 if stest
469 % <AlgoCode>
470 if out1, atest = false; end;
471 if out2, atest = false; end;
472 if ~out3, atest = false; end;
473 if out4, atest = false; end;
474 if out5, atest = false; end;
475 if out6, atest = false; end;
476 if out7, atest = false; end;
477 % </AlgoCode>
478 else
479 atest = false;
480 end
481
482 % Return a result structure
483 result = utp_prepare_result(atest, stest, dbstack, mfilename);
484 end % END UTP_08
485
486 end