comparison testing/utp_1.1/utps/mfir/utp_mfir_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_MFIR_EQ a set of UTPs for the mfir/eq method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_mfir_eq.m,v 1.8 2011/04/19 18:14:01 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The eq() method of the mfir class fir1 == fir2 compares each element of an
11 % fir object with the corresponding element of an second fir object and returns
12 % a logical 1 (true) where fir1 and fir2 are equal, or logical 0 (false)
13 % where they are not equal.
14 %
15 % </MethodDescription>
16
17 function results = utp_mfir_eq(varargin)
18
19 % Check the inputs
20 if nargin == 0
21
22 % Some keywords
23 class = 'mfir';
24 mthd = 'eq';
25
26 results = [];
27 disp('******************************************************');
28 disp(['**** Running UTPs for ' class '/' mthd]);
29 disp('******************************************************');
30
31 % Test MFIR objects
32 [firhp,firlp,firbp,firbr,firpzm,firao,firv,firm] = get_test_objects_mfir;
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 'histin'
46 results = [results utp_09]; % Test with the exception list 'iunits'
47 results = [results utp_10]; % Test with the exception list 'ounits'
48 results = [results utp_11]; % Test exception list in a plist
49
50 disp('Done.');
51 disp('******************************************************');
52
53 elseif nargin == 1 % Check for UTP functions
54 if strcmp(varargin{1}, 'isutp')
55 results = 1;
56 else
57 results = 0;
58 end
59 else
60 error('### Incorrect inputs')
61 end
62
63 %% UTP_01
64
65 % <TestDescription>
66 %
67 % Tests that the getInfo call works for this method.
68 %
69 % </TestDescription>
70 function result = utp_01
71
72
73 % <SyntaxDescription>
74 %
75 % Test that the getInfo call works for no sets, all sets, and each set
76 % individually.
77 %
78 % </SyntaxDescription>
79
80 try
81 % <SyntaxCode>
82 % Call for no sets
83 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
84 % Call for all sets
85 io(2) = eval([class '.getInfo(''' mthd ''')']);
86 % Call for each set
87 for kk=1:numel(io(2).sets)
88 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
89 end
90 % </SyntaxCode>
91 stest = true;
92 catch err
93 disp(err.message)
94 stest = false;
95 end
96
97 % <AlgoDescription>
98 %
99 % 1) Check that getInfo call returned an minfo object in all cases.
100 % 2) Check that all plists have the correct parameters.
101 %
102 % </AlgoDescription>
103
104 atest = true;
105 if stest
106 % <AlgoCode>
107 % check we have minfo objects
108 if isa(io, 'minfo')
109 % SET 'None'
110 if ~isempty(io(1).sets), atest = false; end
111 if ~isempty(io(1).plists), atest = false; end
112 % Check number of SETS
113 if numel(io(2).sets) ~= 1, atest = false; end
114 % Check all Sets
115 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
116 % SET 'Default'
117 % Check key
118 if ~io(3).plists.isparam('Exceptions'), atest = false; end
119 if ~io(3).plists.isparam('Tol'), atest = false; end
120 % Check default value
121 if ~isequal(io(3).plists.find('Exceptions'), {}), atest = false; end
122 if ~isequal(io(3).plists.find('Tol'), eps(1)), atest = false; end
123 % Check options
124 if ~isequal(io(3).plists.getOptionsForParam('Exceptions'), {{}}), atest = false; end
125 if ~isequal(io(3).plists.getOptionsForParam('Tol'), {eps(1)}), atest = false; end
126 end
127 % </AlgoCode>
128 else
129 atest = false;
130 end
131
132 % Return a result structure
133 result = utp_prepare_result(atest, stest, dbstack, mfilename);
134 end % END UTP_01
135
136 %% UTP_02
137
138 % <TestDescription>
139 %
140 % Tests that the eq method works with a vector of MFIR objects as input.
141 %
142 % </TestDescription>
143 function result = utp_02
144
145 % <SyntaxDescription>
146 %
147 % Test that the eq method works for a vector of MFIR objects as input.
148 % Test the positive and the negative case.
149 %
150 % </SyntaxDescription>
151
152 try
153 % <SyntaxCode>
154 fir = firbr.setName('my name');
155 iirv1 = [firlp, firao, firpzm, firbr];
156 iirv2 = [firlp, firao, firpzm, fir];
157 out1 = eq(iirv1, iirv1);
158 out2 = eq(iirv1, iirv2);
159 % </SyntaxCode>
160 stest = true;
161 catch err
162 disp(err.message)
163 stest = false;
164 end
165
166 % <AlgoDescription>
167 %
168 % 1) Check the output of the eq function.
169 %
170 % </AlgoDescription>
171
172 atest = true;
173 if stest
174 % <AlgoCode>
175 if out1 ~= 1, atest = false; end
176 if out2 ~= 0, atest = false; end
177 % </AlgoCode>
178 else
179 atest = false;
180 end
181
182 % Return a result structure
183 result = utp_prepare_result(atest, stest, dbstack, mfilename);
184 end % END UTP_02
185
186 %% UTP_03
187
188 % <TestDescription>
189 %
190 % Tests that the eq method works with a matrix of MFIR objects as input.
191 %
192 % </TestDescription>
193 function result = utp_03
194
195 % <SyntaxDescription>
196 %
197 % Test that the eq method works for a matrix of MFIR objects as input.
198 % Test the positive and the negative case.
199 %
200 % </SyntaxDescription>
201
202 try
203 % <SyntaxCode>
204 fir = firbr.setName('my name');
205 firm1 = [firlp, firao, firbr, firbr, firpzm, firlp];
206 firm2 = [firlp, firao, fir; firbr, firpzm, firlp];
207 out1 = eq(firm1, firm1);
208 out2 = eq(firm1, firm2);
209 % </SyntaxCode>
210 stest = true;
211 catch err
212 disp(err.message)
213 stest = false;
214 end
215
216 % <AlgoDescription>
217 %
218 % 1) Check the output of the eq function.
219 %
220 % </AlgoDescription>
221
222 atest = true;
223 if stest
224 % <AlgoCode>
225 if out1 ~= 1, atest = false; end
226 if out2 ~= 0, atest = false; end
227 % </AlgoCode>
228 else
229 atest = false;
230 end
231
232 % Return a result structure
233 result = utp_prepare_result(atest, stest, dbstack, mfilename);
234 end % END UTP_03
235
236 %% UTP_04
237
238 % <TestDescription>
239 %
240 % Tests that the eq method works with a list of MFIR objects as input.
241 %
242 % </TestDescription>
243 function result = utp_04
244
245 % <SyntaxDescription>
246 %
247 % The eq method doesn't works for a list of MFIR objects as input.
248 % Nothing to do.
249 %
250 % </SyntaxDescription>
251
252 try
253 % <SyntaxCode>
254 % </SyntaxCode>
255 stest = true;
256 catch err
257 disp(err.message)
258 stest = false;
259 end
260
261 % <AlgoDescription>
262 %
263 % </AlgoDescription>
264
265 atest = true;
266 if stest
267 % <AlgoCode>
268 % </AlgoCode>
269 else
270 atest = false;
271 end
272
273 % Return a result structure
274 result = utp_prepare_result(atest, stest, dbstack, mfilename);
275 end % END UTP_04
276
277 %% UTP_05
278
279 % <TestDescription>
280 %
281 % Tests that the eq method works with a mix of different shaped MFIR objects
282 % as input.
283 %
284 % </TestDescription>
285 function result = utp_05
286
287 % <SyntaxDescription>
288 %
289 % The eq method doesn't works for a list of MFIR objects as input.
290 % Nothing to do.
291 %
292 % </SyntaxDescription>
293
294 try
295 % <SyntaxCode>
296 % </SyntaxCode>
297 stest = true;
298 catch err
299 disp(err.message)
300 stest = false;
301 end
302
303 % <AlgoDescription>
304 %
305 % </AlgoDescription>
306
307 atest = true;
308 if stest
309 % <AlgoCode>
310 % </AlgoCode>
311 else
312 atest = false;
313 end
314
315 % Return a result structure
316 result = utp_prepare_result(atest, stest, dbstack, mfilename);
317 end % END UTP_05
318
319 %% UTP_06
320
321 % <TestDescription>
322 %
323 % Tests that the eq method properly applies history.
324 %
325 % </TestDescription>
326 function result = utp_06
327
328 % <SyntaxDescription>
329 %
330 % The eq method doesn't change the MFIR object, thus will no history added.
331 % Nothing to do
332 %
333 % </SyntaxDescription>
334
335 try
336 % <SyntaxCode>
337 % </SyntaxCode>
338 stest = true;
339 catch err
340 disp(err.message)
341 stest = false;
342 end
343
344 % <AlgoDescription>
345 %
346 % </AlgoDescription>
347
348 atest = true;
349 if stest
350 % <AlgoCode>
351 % </AlgoCode>
352 else
353 atest = false;
354 end
355
356 % Return a result structure
357 result = utp_prepare_result(atest, stest, dbstack, mfilename);
358 end % END UTP_06
359
360 %% UTP_07
361
362 % <TestDescription>
363 %
364 % Test the eq method with an exception list.
365 % With the LTPDA toolbox 2.0 it is only possible to test the exception list
366 % with properties where a public set method exist.
367 %
368 % </TestDescription>
369 function result = utp_07
370
371 % <SyntaxDescription>
372 %
373 % Test the eq method with the exception 'name'. Use the option 'internal' to
374 % suppress the history. It is necessary to add 'created' to the exception
375 % list because fir is created at an other time.
376 %
377 % </SyntaxDescription>
378
379 try
380 % <SyntaxCode>
381 fir = testCallerIsMethod(@setName, firbr, 'my name');
382 out1 = eq(fir, firbr);
383 out2 = eqLocal(fir, firbr, 'name');
384 out3 = eqLocal(fir, firbr, 'mfir/name');
385 out4 = eq(fir.hist, firbr.hist);
386 % </SyntaxCode>
387 stest = true;
388 catch err
389 disp(err.message)
390 stest = false;
391 end
392
393 % <AlgoDescription>
394 %
395 % 1) Check the output.
396 %
397 % </AlgoDescription>
398
399 atest = true;
400 if stest
401 % <AlgoCode>
402 if out1 ~= 0, atest = false; end
403 if out2 ~= 1, atest = false; end
404 if out3 ~= 1, atest = false; end
405 if out4 ~= 1, atest = false; end
406 % </AlgoCode>
407 else
408 atest = false;
409 end
410
411 % Return a result structure
412 result = utp_prepare_result(atest, stest, dbstack, mfilename);
413 end % END UTP_07
414
415 %% UTP_08
416
417 % <TestDescription>
418 %
419 % Test the eq method with an exception list.
420 % With the LTPDA toolbox 2.0 it is only possible to test the exception list
421 % with properties where a public set method exist.
422 %
423 % </TestDescription>
424 function result = utp_08
425
426 % <SyntaxDescription>
427 %
428 % Test the eq method with the exception 'histout'. Use the option 'internal' to
429 % suppress the history. It is necessary to add 'created' to the exception
430 % list because fir is created at an other time.
431 %
432 % </SyntaxDescription>
433
434 try
435 % <SyntaxCode>
436 fir = testCallerIsMethod(@setHistout, firbr, [1 1]);
437 out1 = eq(fir, firbr);
438 out2 = eqLocal(fir, firbr, 'histout');
439 out3 = eqLocal(fir, firbr, 'mfir/histout');
440 out4 = eq(fir.hist, firbr.hist);
441 % </SyntaxCode>
442 stest = true;
443 catch err
444 disp(err.message)
445 stest = false;
446 end
447
448 % <AlgoDescription>
449 %
450 % 1) Check the output.
451 %
452 % </AlgoDescription>
453
454 atest = true;
455 if stest
456 % <AlgoCode>
457 if out1 ~= 0, atest = false; end
458 if out2 ~= 1, atest = false; end
459 if out3 ~= 1, atest = false; end
460 if out4 ~= 1, atest = false; end
461 % </AlgoCode>
462 else
463 atest = false;
464 end
465
466 % Return a result structure
467 result = utp_prepare_result(atest, stest, dbstack, mfilename);
468 end % END UTP_08
469
470 %% UTP_09
471
472 % <TestDescription>
473 %
474 % Test the eq method with an exception list.
475 % With the LTPDA toolbox 2.0 it is only possible to test the exception list
476 % with properties where a public set method exist.
477 %
478 % </TestDescription>
479 function result = utp_09
480
481 % <SyntaxDescription>
482 %
483 % Test the eq method with the exception 'iunits'. Use the option 'internal'
484 % to suppress the history. It is necessary to add 'created' to the exception
485 % list because fir is created at an other time.
486 %
487 % </SyntaxDescription>
488
489 try
490 % <SyntaxCode>
491 fir = testCallerIsMethod(@setIunits, firbr, unit('Hz'));
492 out1 = eq(fir, firbr);
493 out2 = eqLocal(fir, firbr, 'iunits');
494 out3 = eqLocal(fir, firbr, 'mfir/iunits');
495 out4 = eq(fir.hist, firbr.hist);
496 % </SyntaxCode>
497 stest = true;
498 catch err
499 disp(err.message)
500 stest = false;
501 end
502
503 % <AlgoDescription>
504 %
505 % 1) Check the output.
506 %
507 % </AlgoDescription>
508
509 atest = true;
510 if stest
511 % <AlgoCode>
512 if out1 ~= 0, atest = false; end
513 if out2 ~= 1, atest = false; end
514 if out3 ~= 1, atest = false; end
515 if out4 ~= 1, 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_09
524
525 %% UTP_10
526
527 % <TestDescription>
528 %
529 % Test the eq method with an exception list.
530 % With the LTPDA toolbox 2.0 it is only possible to test the exception list
531 % with properties where a public set method exist.
532 %
533 % </TestDescription>
534 function result = utp_10
535
536 % <SyntaxDescription>
537 %
538 % Test the eq method with the exception 'ounits'. Use the option 'internal'
539 % to suppress the history. It is necessary to add 'created' to the exception
540 % list because fir is created at an other time.
541 %
542 % </SyntaxDescription>
543
544 try
545 % <SyntaxCode>
546 fir = testCallerIsMethod(@setOunits, firbr, unit('V'));
547 out1 = eq(fir, firbr);
548 out2 = eqLocal(fir, firbr, 'ounits');
549 out3 = eqLocal(fir, firbr, 'mfir/ounits');
550 out4 = eq(fir.hist, firbr.hist);
551 % </SyntaxCode>
552 stest = true;
553 catch err
554 disp(err.message)
555 stest = false;
556 end
557
558 % <AlgoDescription>
559 %
560 % 1) Check the output.
561 %
562 % </AlgoDescription>
563
564 atest = true;
565 if stest
566 % <AlgoCode>
567 if out1 ~= 0, atest = false; end
568 if out2 ~= 1, atest = false; end
569 if out3 ~= 1, atest = false; end
570 if out4 ~= 1, atest = false; end
571 % </AlgoCode>
572 else
573 atest = false;
574 end
575
576 % Return a result structure
577 result = utp_prepare_result(atest, stest, dbstack, mfilename);
578 end % END UTP_10
579
580 %% UTP_11
581
582 % <TestDescription>
583 %
584 % Test the eq method with an exception list which is in a plist.
585 %
586 % </TestDescription>
587 function result = utp_11
588
589 % <SyntaxDescription>
590 %
591 % Test that the eq method uses the exception list in a plist.
592 %
593 % </SyntaxDescription>
594
595 try
596 % <SyntaxCode>
597 fir = testCallerIsMethod(@setName, firbr, 'my name');
598 pl = plist('Exceptions', {'name', 'UUID'});
599 out1 = eq(fir, firbr);
600 out2 = eq(fir, firbr, pl);
601 out3 = eq(fir, firbr, pl);
602 out4 = eq(fir.hist, firbr.hist);
603 % </SyntaxCode>
604 stest = true;
605 catch err
606 disp(err.message)
607 stest = false;
608 end
609
610 % <AlgoDescription>
611 %
612 % 1) Check the output.
613 %
614 % </AlgoDescription>
615
616 atest = true;
617 if stest
618 % <AlgoCode>
619 % Check the shape of the output data
620 if out1 ~= 0, atest = false; end
621 if out2 ~= 1, atest = false; end
622 if out3 ~= 1, atest = false; end
623 if out4 ~= 1, atest = false; end
624 % </AlgoCode>
625 else
626 atest = false;
627 end
628
629 % Return a result structure
630 result = utp_prepare_result(atest, stest, dbstack, mfilename);
631 end % END UTP_11
632
633 function res = eqLocal(obj1, obj2, ex)
634 e = ple1.find('EXCEPTIONS');
635 ple = plist('EXCEPTIONS', [e {ex}]);
636
637 res = eq(obj1, obj2, ple);
638 end
639 end