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