comparison testing/utp_1.1/utps/parfrac/utp_parfrac_eq.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_EQ a set of UTPs for the parfrac/eq method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_parfrac_eq.m,v 1.7 2011/04/19 18:14:01 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The eq() method of the parfrac class pf1 == pf2 compares each element of
11 % a parfrac object with the corresponding element of an second parfrac
12 % object and returns a logical 1 (true) where pf1 and pf2 are equal, or
13 % logical 0 (false) where they are not equal.
14 %
15 % </MethodDescription>
16
17 function results = utp_parfrac_eq(varargin)
18
19 % Check the inputs
20 if nargin == 0
21
22 % Some keywords
23 class = 'parfrac';
24 mthd = 'eq';
25
26 results = [];
27 disp('******************************************************');
28 disp(['**** Running UTPs for ' class '/' mthd]);
29 disp('******************************************************');
30
31 % Test PARFRAC objects
32 [pf1,pf2,pf3,pfv,pfm] = get_test_objects_parfrac;
33
34 % Exception list for the UTPs:
35 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
36
37 % Run the tests
38 results = [results utp_01]; % getInfo call
39 results = [results utp_02]; % Vector input
40 results = [results utp_03]; % Matrix input
41 results = [results utp_04]; % List input
42 results = [results utp_05]; % Test with mixed input
43 results = [results utp_06]; % Test history is working
44 results = [results utp_07]; % Test with the exception list 'name'
45 results = [results utp_08]; % Test with the exception list 'iunits'
46 results = [results utp_09]; % Test with the exception list 'ounits'
47 results = [results utp_10]; % Test exception list in a plist
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 number of SETS
112 if numel(io(2).sets) ~= 1, atest = false; end
113 % Check all Sets
114 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
115 % SET 'Default'
116 % Check key
117 if ~io(3).plists.isparam('Exceptions'), atest = false; end
118 if ~io(3).plists.isparam('Tol'), atest = false; end
119 % Check default value
120 if ~isequal(io(3).plists.find('Exceptions'), {}), atest = false; end
121 if ~isequal(io(3).plists.find('Tol'), eps(1)), atest = false; end
122 % Check options
123 if ~isequal(io(3).plists.getOptionsForParam('Exceptions'), {{}}), atest = false; end
124 if ~isequal(io(3).plists.getOptionsForParam('Tol'), {eps(1)}), atest = false; end
125 end
126 % </AlgoCode>
127 else
128 atest = false;
129 end
130
131 % Return a result structure
132 result = utp_prepare_result(atest, stest, dbstack, mfilename);
133 end % END UTP_01
134
135 %% UTP_02
136
137 % <TestDescription>
138 %
139 % Tests that the eq method works with a vector of PARFRAC objects as input.
140 %
141 % </TestDescription>
142 function result = utp_02
143
144 % <SyntaxDescription>
145 %
146 % Test that the eq method works for a vector of PARFRAC objects as input.
147 % Test the positive and the negative case.
148 %
149 % </SyntaxDescription>
150
151 try
152 % <SyntaxCode>
153 pa = pf3.setName('my name');
154 pfv1 = [pf1, pf2, pf3];
155 pfv2 = [pf1, pf2, pa];
156 out1 = eq(pfv1, pfv1);
157 out2 = eq(pfv1, pfv2);
158 % </SyntaxCode>
159 stest = true;
160 catch err
161 disp(err.message)
162 stest = false;
163 end
164
165 % <AlgoDescription>
166 %
167 % 1) Check the output of the eq function.
168 %
169 % </AlgoDescription>
170
171 atest = true;
172 if stest
173 % <AlgoCode>
174 if out1 ~= 1, atest = false; end
175 if out2 ~= 0, atest = false; end
176 % </AlgoCode>
177 else
178 atest = false;
179 end
180
181 % Return a result structure
182 result = utp_prepare_result(atest, stest, dbstack, mfilename);
183 end % END UTP_02
184
185 %% UTP_03
186
187 % <TestDescription>
188 %
189 % Tests that the eq method works with a matrix of PARFRAC objects as input.
190 %
191 % </TestDescription>
192 function result = utp_03
193
194 % <SyntaxDescription>
195 %
196 % Test that the eq method works for a matrix of PARFRAC objects as input.
197 % Test the positive and the negative case.
198 %
199 % </SyntaxDescription>
200
201 try
202 % <SyntaxCode>
203 pa = pf3.setName('my name');
204 pfm1 = [pf1, pf2, pf3, pf1, pf2, pf3];
205 pfm2 = [pf3, pf2, pa; pf1, pf2, pf3];
206 out1 = eq(pfm1, pfm1);
207 out2 = eq(pfm1, pfm2);
208 % </SyntaxCode>
209 stest = true;
210 catch err
211 disp(err.message)
212 stest = false;
213 end
214
215 % <AlgoDescription>
216 %
217 % 1) Check the output of the eq function.
218 %
219 % </AlgoDescription>
220
221 atest = true;
222 if stest
223 % <AlgoCode>
224 if out1 ~= 1, atest = false; end
225 if out2 ~= 0, atest = false; end
226 % </AlgoCode>
227 else
228 atest = false;
229 end
230
231 % Return a result structure
232 result = utp_prepare_result(atest, stest, dbstack, mfilename);
233 end % END UTP_03
234
235 %% UTP_04
236
237 % <TestDescription>
238 %
239 % Tests that the eq method works with a list of PARFRAC objects as input.
240 %
241 % </TestDescription>
242 function result = utp_04
243
244 % <SyntaxDescription>
245 %
246 % The eq method doesn't works for a list of PARFRAC objects as input.
247 % Nothing to do.
248 %
249 % </SyntaxDescription>
250
251 try
252 % <SyntaxCode>
253 % </SyntaxCode>
254 stest = true;
255 catch err
256 disp(err.message)
257 stest = false;
258 end
259
260 % <AlgoDescription>
261 %
262 % </AlgoDescription>
263
264 atest = true;
265 if stest
266 % <AlgoCode>
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 eq method works with a mix of different shaped PARFRAC objects
281 % as input.
282 %
283 % </TestDescription>
284 function result = utp_05
285
286 % <SyntaxDescription>
287 %
288 % The eq method doesn't works for a list of PARFRAC objects as input.
289 % Nothing to do.
290 %
291 % </SyntaxDescription>
292
293 try
294 % <SyntaxCode>
295 % </SyntaxCode>
296 stest = true;
297 catch err
298 disp(err.message)
299 stest = false;
300 end
301
302 % <AlgoDescription>
303 %
304 % </AlgoDescription>
305
306 atest = true;
307 if stest
308 % <AlgoCode>
309 % </AlgoCode>
310 else
311 atest = false;
312 end
313
314 % Return a result structure
315 result = utp_prepare_result(atest, stest, dbstack, mfilename);
316 end % END UTP_05
317
318 %% UTP_06
319
320 % <TestDescription>
321 %
322 % Tests that the eq method properly applies history.
323 %
324 % </TestDescription>
325 function result = utp_06
326
327 % <SyntaxDescription>
328 %
329 % The eq method doesn't change the PARFRAC object, thus will no history added.
330 % Nothing to do
331 %
332 % </SyntaxDescription>
333
334 try
335 % <SyntaxCode>
336 % </SyntaxCode>
337 stest = true;
338 catch err
339 disp(err.message)
340 stest = false;
341 end
342
343 % <AlgoDescription>
344 %
345 % </AlgoDescription>
346
347 atest = true;
348 if stest
349 % <AlgoCode>
350 % </AlgoCode>
351 else
352 atest = false;
353 end
354
355 % Return a result structure
356 result = utp_prepare_result(atest, stest, dbstack, mfilename);
357 end % END UTP_06
358
359 %% UTP_07
360
361 % <TestDescription>
362 %
363 % Test the eq method with an exception list.
364 % With the LTPDA toolbox 2.0 it is only possible to test the exception
365 % list with properties where a public set method exist.
366 %
367 % </TestDescription>
368 function result = utp_07
369
370 % <SyntaxDescription>
371 %
372 % Test the eq method with the exception 'name'. Use the option
373 % 'internal' to suppress the history. It is necessary to add 'created'
374 % to the exception list because 'pa' is created at an other time.
375 %
376 % </SyntaxDescription>
377
378 try
379 % <SyntaxCode>
380 pa = testCallerIsMethod(@setName, pf3, 'my name');
381 out1 = eq(pa, pf3);
382 out2 = eqLocal(pa, pf3, 'name');
383 out3 = eqLocal(pa, pf3, 'parfrac/name');
384 out4 = eq(pa.hist, pf3.hist);
385 % </SyntaxCode>
386 stest = true;
387 catch err
388 disp(err.message)
389 stest = false;
390 end
391
392 % <AlgoDescription>
393 %
394 % 1) Check the output.
395 %
396 % </AlgoDescription>
397
398 atest = true;
399 if stest
400 % <AlgoCode>
401 if out1 ~= 0, atest = false; end
402 if out2 ~= 1, atest = false; end
403 if out3 ~= 1, atest = false; end
404 if out4 ~= 1, atest = false; end
405 % </AlgoCode>
406 else
407 atest = false;
408 end
409
410 % Return a result structure
411 result = utp_prepare_result(atest, stest, dbstack, mfilename);
412 end % END UTP_07
413
414 %% UTP_08
415
416 % <TestDescription>
417 %
418 % Test the eq method with an exception list.
419 % With the LTPDA toolbox 2.0 it is only possible to test the exception list
420 % with properties where a public set method exist.
421 %
422 % </TestDescription>
423 function result = utp_08
424
425 % <SyntaxDescription>
426 %
427 % Test the eq method with the exception 'iunits'. Use the option 'internal'
428 % to suppress the history. It is necessary to add 'created' to the exception
429 % list because 'pa' is created at an other time.
430 %
431 % </SyntaxDescription>
432
433 try
434 % <SyntaxCode>
435 pa = testCallerIsMethod(@setIunits, pf3, unit('Hz'));
436 out1 = eq(pa, pf3);
437 out2 = eqLocal(pa, pf3, 'iunits');
438 out3 = eqLocal(pa, pf3, 'parfrac/iunits');
439 out4 = eq(pa.hist, pf3.hist);
440 % </SyntaxCode>
441 stest = true;
442 catch err
443 disp(err.message)
444 stest = false;
445 end
446
447 % <AlgoDescription>
448 %
449 % 1) Check the output.
450 %
451 % </AlgoDescription>
452
453 atest = true;
454 if stest
455 % <AlgoCode>
456 if out1 ~= 0, atest = false; end
457 if out2 ~= 1, atest = false; end
458 if out3 ~= 1, atest = false; end
459 if out4 ~= 1, atest = false; end
460 % </AlgoCode>
461 else
462 atest = false;
463 end
464
465 % Return a result structure
466 result = utp_prepare_result(atest, stest, dbstack, mfilename);
467 end % END UTP_08
468
469 %% UTP_09
470
471 % <TestDescription>
472 %
473 % Test the eq method with an exception list.
474 % With the LTPDA toolbox 2.0 it is only possible to test the exception
475 % list with properties where a public set method exist.
476 %
477 % </TestDescription>
478 function result = utp_09
479
480 % <SyntaxDescription>
481 %
482 % Test the eq method with the exception 'ounits'. Use the option
483 % 'internal' to suppress the history. It is necessary to add 'created'
484 % to the exception list because 'pa' is created at an other time.
485 %
486 % </SyntaxDescription>
487
488 try
489 % <SyntaxCode>
490 pa = testCallerIsMethod(@setOunits, pf3, unit('V'));
491 out1 = eq(pa, pf3);
492 out2 = eqLocal(pa, pf3, 'ounits');
493 out3 = eqLocal(pa, pf3, 'parfrac/ounits');
494 out4 = eq(pa.hist, pf3.hist);
495 % </SyntaxCode>
496 stest = true;
497 catch err
498 disp(err.message)
499 stest = false;
500 end
501
502 % <AlgoDescription>
503 %
504 % 1) Check the output.
505 %
506 % </AlgoDescription>
507
508 atest = true;
509 if stest
510 % <AlgoCode>
511 if out1 ~= 0, atest = false; end
512 if out2 ~= 1, atest = false; end
513 if out3 ~= 1, atest = false; end
514 if out4 ~= 1, atest = false; end
515 % </AlgoCode>
516 else
517 atest = false;
518 end
519
520 % Return a result structure
521 result = utp_prepare_result(atest, stest, dbstack, mfilename);
522 end % END UTP_09
523
524 %% UTP_10
525
526 % <TestDescription>
527 %
528 % Test the eq method with an exception list which is in a plist.
529 %
530 % </TestDescription>
531 function result = utp_10
532
533 % <SyntaxDescription>
534 %
535 % Test that the eq method uses the exception list in a plist.
536 %
537 % </SyntaxDescription>
538
539 try
540 % <SyntaxCode>
541 pa = testCallerIsMethod(@setName, pf3, 'my name');
542 pl = plist('Exceptions', {'name', 'UUID'});
543 out1 = eq(pa, pf3);
544 out2 = eq(pa, pf3, pl);
545 out3 = eq(pa, pf3, pl);
546 out4 = eq(pa.hist, pf3.hist);
547 % </SyntaxCode>
548 stest = true;
549 catch err
550 disp(err.message)
551 stest = false;
552 end
553
554 % <AlgoDescription>
555 %
556 % 1) Check the output.
557 %
558 % </AlgoDescription>
559
560 atest = true;
561 if stest
562 % <AlgoCode>
563 % Check the shape of the output data
564 if out1 ~= 0, atest = false; end
565 if out2 ~= 1, atest = false; end
566 if out3 ~= 1, atest = false; end
567 if out4 ~= 1, atest = false; end
568 % </AlgoCode>
569 else
570 atest = false;
571 end
572
573 % Return a result structure
574 result = utp_prepare_result(atest, stest, dbstack, mfilename);
575 end % END UTP_10
576
577 function res = eqLocal(obj1, obj2, ex)
578 e = ple1.find('EXCEPTIONS');
579 ple = plist('EXCEPTIONS', [e {ex}]);
580
581 res = eq(obj1, obj2, ple);
582 end
583 end