Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/pzmodel/utp_pzmodel_mrdivide.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_PZMODEL_MRDIVIDE a set of UTPs for the pzmodel/mrdivide method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_pzmodel_mrdivide.m,v 1.2 2009/07/23 18:56:38 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The mrdivide method of the pzmodel class overloads the division operator | |
11 % for PZMODELs. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_pzmodel_mrdivide(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'pzmodel'; | |
22 mthd = 'mrdivide'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Exception list for the UTPs: | |
30 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
31 | |
32 % Run the tests | |
33 results = [results utp_01]; % getInfo call | |
34 results = [results utp_02]; % Vector input | |
35 results = [results utp_03]; % Matrix input | |
36 results = [results utp_04]; % List input | |
37 results = [results utp_05]; % Test with mixed input | |
38 results = [results utp_06]; % Test history is working | |
39 results = [results utp_07]; % Test the I-/O-units | |
40 | |
41 disp('Done.'); | |
42 disp('******************************************************'); | |
43 | |
44 elseif nargin == 1 % Check for UTP functions | |
45 if strcmp(varargin{1}, 'isutp') | |
46 results = 1; | |
47 else | |
48 results = 0; | |
49 end | |
50 else | |
51 error('### Incorrect inputs') | |
52 end | |
53 | |
54 %% UTP_01 | |
55 | |
56 % <TestDescription> | |
57 % | |
58 % Tests that the getInfo call works for this method. | |
59 % | |
60 % </TestDescription> | |
61 function result = utp_01 | |
62 | |
63 | |
64 % <SyntaxDescription> | |
65 % | |
66 % Test that the getInfo call works for no sets, all sets, and each set | |
67 % individually. | |
68 % | |
69 % </SyntaxDescription> | |
70 | |
71 try | |
72 % <SyntaxCode> | |
73 % Call for no sets | |
74 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
75 % Call for all sets | |
76 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
77 % Call for each set | |
78 for kk=1:numel(io(2).sets) | |
79 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
80 end | |
81 % </SyntaxCode> | |
82 stest = true; | |
83 catch err | |
84 disp(err.message) | |
85 stest = false; | |
86 end | |
87 | |
88 % <AlgoDescription> | |
89 % | |
90 % 1) Check that getInfo call returned an minfo object in all cases. | |
91 % 2) Check that all plists have the correct parameters. | |
92 % | |
93 % </AlgoDescription> | |
94 | |
95 atest = true; | |
96 if stest | |
97 % <AlgoCode> | |
98 % check we have minfo objects | |
99 if isa(io, 'minfo') | |
100 % SET 'None' | |
101 if ~isempty(io(1).sets), atest = false; end | |
102 if ~isempty(io(1).plists), atest = false; end | |
103 % Check all Sets | |
104 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
105 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
106 % SET 'Default' | |
107 if io(3).plists.nparams ~= 0, atest = false; end | |
108 % Check key | |
109 % Check default value | |
110 % Check options | |
111 end | |
112 % </AlgoCode> | |
113 else | |
114 atest = false; | |
115 end | |
116 | |
117 % Return a result structure | |
118 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
119 end % END UTP_01 | |
120 | |
121 %% UTP_02 | |
122 | |
123 % <TestDescription> | |
124 % | |
125 % Tests that the mrdivide method works with a vector of PZMODELs as input. | |
126 % | |
127 % </TestDescription> | |
128 function result = utp_02 | |
129 | |
130 % <SyntaxDescription> | |
131 % | |
132 % Test that the mrdivide method works for a vector of PZMODELs as input. | |
133 % | |
134 % </SyntaxDescription> | |
135 | |
136 try | |
137 % <SyntaxCode> | |
138 pz1 = pzmodel(2, pz(1), pz(-4)); | |
139 pz2 = pzmodel(3, pz(2), pz(-3)); | |
140 pz3 = pzmodel(4, pz(3), pz(-2)); | |
141 pz4 = pzmodel(5, pz(4), pz(-1)); | |
142 out1 = mrdivide(pz1, [pz2, pz3, pz4 pz1]); | |
143 out2 = pz1 / [pz2, pz3, pz4 pz1]; | |
144 % </SyntaxCode> | |
145 stest = true; | |
146 catch err | |
147 disp(err.message) | |
148 stest = false; | |
149 end | |
150 | |
151 % <AlgoDescription> | |
152 % | |
153 % 1) Check that the output is exact one PZMODEL object. | |
154 % 2) Check the gain of the output | |
155 % 3) Check the poles of the output | |
156 % 4) Check the zeros of the output | |
157 % | |
158 % </AlgoDescription> | |
159 | |
160 atest = true; | |
161 if stest | |
162 % <AlgoCode> | |
163 if numel(out1) ~= 1, atest = false; end | |
164 if numel(out2) ~= 1, atest = false; end | |
165 % Check 'gain' | |
166 if out1.gain ~= (2 / 3 / 4 / 5 / 2), atest = false; end | |
167 if out2.gain ~= (2 / 3 / 4 / 5 / 2), atest = false; end | |
168 % Check 'poles' | |
169 if ~eq(out1.poles, [pz(1), pz(-3), pz(-2), pz(-1), pz(-4)]), atest = false; end | |
170 if ~eq(out2.poles, [pz(1), pz(-3), pz(-2), pz(-1), pz(-4)]), atest = false; end | |
171 % Check 'zeros' | |
172 if ~eq(out1.zeros, [pz(-4), pz(2), pz(3), pz(4), pz(1)]), atest = false; end | |
173 if ~eq(out2.zeros, [pz(-4), pz(2), pz(3), pz(4), pz(1)]), atest = false; end | |
174 % </AlgoCode> | |
175 else | |
176 atest = false; | |
177 end | |
178 | |
179 % Return a result structure | |
180 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
181 end % END UTP_02 | |
182 | |
183 %% UTP_03 | |
184 | |
185 % <TestDescription> | |
186 % | |
187 % Tests that the mrdivide method works with a matrix of PZMODELs as input. | |
188 % | |
189 % </TestDescription> | |
190 function result = utp_03 | |
191 | |
192 % <SyntaxDescription> | |
193 % | |
194 % Tests that the rdivie method works with a matrix of PZMODELs as input. | |
195 % | |
196 % </SyntaxDescription> | |
197 | |
198 try | |
199 % <SyntaxCode> | |
200 pz1 = pzmodel(2, pz(1), pz(-4)); | |
201 pz2 = pzmodel(3, pz(2), pz(-3)); | |
202 pz3 = pzmodel(4, pz(3), pz(-2)); | |
203 pz4 = pzmodel(5, pz(4), pz(-1)); | |
204 out1 = mrdivide(pz1, [pz4, pz3, pz2; pz1 pz4 pz3]); | |
205 out2 = pz1 / [pz4, pz3, pz2; pz1 pz4 pz3]; | |
206 % </SyntaxCode> | |
207 stest = true; | |
208 catch err | |
209 disp(err.message) | |
210 stest = false; | |
211 end | |
212 | |
213 % <AlgoDescription> | |
214 % | |
215 % 1) Check that the output is exact one PZMODEL object. | |
216 % 2) Check the gain of the output | |
217 % 3) Check the poles of the output | |
218 % 4) Check the zeros of the output | |
219 % | |
220 % </AlgoDescription> | |
221 | |
222 atest = true; | |
223 if stest | |
224 % <AlgoCode> | |
225 if numel(out1) ~= 1, atest = false; end | |
226 if numel(out2) ~= 1, atest = false; end | |
227 % Check 'gain' | |
228 if out1.gain ~= (2 / 5 / 2 / 4 / 5 / 3 / 4), atest = false; end | |
229 if out2.gain ~= (2 / 5 / 2 / 4 / 5 / 3 / 4), atest = false; end | |
230 % Check 'poles' | |
231 if ~eq(out1.poles, [pz(1), pz(-1), pz(-4), pz(-2), pz(-1), pz(-3), pz(-2)]), atest = false; end | |
232 if ~eq(out2.poles, [pz(1), pz(-1), pz(-4), pz(-2), pz(-1), pz(-3), pz(-2)]), atest = false; end | |
233 % Check 'zeros' | |
234 if ~eq(out1.zeros, [pz(-4), pz(4), pz(1), pz(3), pz(4), pz(2), pz(3)]), atest = false; end | |
235 if ~eq(out2.zeros, [pz(-4), pz(4), pz(1), pz(3), pz(4), pz(2), pz(3)]), atest = false; end | |
236 % </AlgoCode> | |
237 else | |
238 atest = false; | |
239 end | |
240 | |
241 % Return a result structure | |
242 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
243 end % END UTP_03 | |
244 | |
245 %% UTP_04 | |
246 | |
247 % <TestDescription> | |
248 % | |
249 % Tests that the mrdivide method works with a list of PZMODELs as input. | |
250 % | |
251 % </TestDescription> | |
252 function result = utp_04 | |
253 | |
254 % <SyntaxDescription> | |
255 % | |
256 % Tests that the mrdivide method works with a list of PZMODELs as input. | |
257 % | |
258 % </SyntaxDescription> | |
259 | |
260 try | |
261 % <SyntaxCode> | |
262 pz1 = pzmodel(2, pz(1), pz(-4)); | |
263 pz2 = pzmodel(3, pz(2), pz(-3)); | |
264 pz3 = pzmodel(4, pz(3), pz(-2)); | |
265 out1 = mrdivide(pz1, pz2, pz3); | |
266 out2 = pz1 / pz2 / pz3; | |
267 % </SyntaxCode> | |
268 stest = true; | |
269 catch err | |
270 disp(err.message) | |
271 stest = false; | |
272 end | |
273 | |
274 % <AlgoDescription> | |
275 % | |
276 % 1) Check that the output is exact one PZMODEL object. | |
277 % 2) Check the gain of the output | |
278 % 3) Check the poles of the output | |
279 % 4) Check the zeros of the output | |
280 % | |
281 % </AlgoDescription> | |
282 | |
283 atest = true; | |
284 if stest | |
285 % <AlgoCode> | |
286 if numel(out1) ~= 1, atest = false; end | |
287 if numel(out2) ~= 1, atest = false; end | |
288 % Check 'gain' | |
289 if out1.gain ~= (2 / 3 / 4), atest = false; end | |
290 if out2.gain ~= (2 / 3 / 4), atest = false; end | |
291 % Check 'poles' | |
292 if ~eq(out1.poles, [pz(1), pz(-3), pz(-2)]), atest = false; end | |
293 if ~eq(out2.poles, [pz(1), pz(-3), pz(-2)]), atest = false; end | |
294 % Check 'zeros' | |
295 if ~eq(out1.zeros, [pz(-4), pz(2), pz(3)]), atest = false; end | |
296 if ~eq(out2.zeros, [pz(-4), pz(2), pz(3)]), atest = false; end | |
297 % </AlgoCode> | |
298 else | |
299 atest = false; | |
300 end | |
301 | |
302 % Return a result structure | |
303 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
304 end % END UTP_04 | |
305 | |
306 %% UTP_05 | |
307 | |
308 % <TestDescription> | |
309 % | |
310 % Tests that the mrdivide method works with a mix of different shaped | |
311 % PZMODELs as input. | |
312 % | |
313 % </TestDescription> | |
314 function result = utp_05 | |
315 | |
316 % <SyntaxDescription> | |
317 % | |
318 % Tests that the mrdivide method works with a mix of different shaped | |
319 % PZMODELs as input. | |
320 % | |
321 % </SyntaxDescription> | |
322 | |
323 try | |
324 % <SyntaxCode> | |
325 pz1 = pzmodel(2, pz(1), pz(-4)); | |
326 pz2 = pzmodel(3, pz(2), pz(-3)); | |
327 pz3 = pzmodel(4, pz(3), pz(-2)); | |
328 pz4 = pzmodel(5, pz(4), pz(-1)); | |
329 out1 = mrdivide(pz1, [pz2 pz3], pz4); | |
330 out2 = pz1 / [pz2 pz3] / pz4; | |
331 mout = rebuild(out2); | |
332 % </SyntaxCode> | |
333 stest = true; | |
334 catch err | |
335 disp(err.message) | |
336 stest = false; | |
337 end | |
338 | |
339 % <AlgoDescription> | |
340 % | |
341 % 1) Check that the output is exact one PZMODEL object. | |
342 % 2) Check the gain of the output | |
343 % 3) Check the poles of the output | |
344 % 4) Check the zeros of the output | |
345 % 5) Check the rebuilt object | |
346 % | |
347 % </AlgoDescription> | |
348 | |
349 atest = true; | |
350 if stest | |
351 % <AlgoCode> | |
352 if numel(out1) ~= 1, atest = false; end | |
353 if numel(out2) ~= 1, atest = false; end | |
354 % Check 'gain' | |
355 if out1.gain ~= (2 / 3 / 4 / 5), atest = false; end | |
356 if out2.gain ~= (2 / 3 / 4 / 5), atest = false; end | |
357 % Check 'poles' | |
358 if ~eq(out1.poles, [pz(1), pz(-3), pz(-2), pz(-1)]), atest = false; end | |
359 if ~eq(out2.poles, [pz(1), pz(-3), pz(-2), pz(-1)]), atest = false; end | |
360 % Check 'zeros' | |
361 if ~eq(out1.zeros, [pz(-4), pz(2), pz(3), pz(4)]), atest = false; end | |
362 if ~eq(out2.zeros, [pz(-4), pz(2), pz(3), pz(4)]), atest = false; end | |
363 % Check the rebuilt object | |
364 if ~eq(mout, out2, ple2), atest = false; end | |
365 % </AlgoCode> | |
366 else | |
367 atest = false; | |
368 end | |
369 | |
370 % Return a result structure | |
371 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
372 end % END UTP_05 | |
373 | |
374 %% UTP_06 | |
375 | |
376 % <TestDescription> | |
377 % | |
378 % Tests that the mrdivide method properly applies history. | |
379 % | |
380 % </TestDescription> | |
381 function result = utp_06 | |
382 | |
383 % <SyntaxDescription> | |
384 % | |
385 % Test that the result of applying the mrdivide method can be processed | |
386 % back. | |
387 % | |
388 % </SyntaxDescription> | |
389 | |
390 try | |
391 % <SyntaxCode> | |
392 pz1 = pzmodel(2, pz(1), pz(-4)); | |
393 pz2 = pzmodel(3, pz(2), pz(-3)); | |
394 out = mrdivide(pz1, pz2); | |
395 mout = rebuild(out); | |
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 the last entry in the history of 'out' corresponds to | |
406 % 'mrdivide'. | |
407 % 2) Check that re-built object is the same object as the input. | |
408 % | |
409 % </AlgoDescription> | |
410 | |
411 atest = true; | |
412 if stest | |
413 % <AlgoCode> | |
414 % Check the last step in the history of 'out' | |
415 if ~strcmp(out.hist.methodInfo.mname, 'rdivide'), atest = false; end | |
416 % The rebuilt object must be the same as 'out' | |
417 if ~eq(mout, out, ple2), atest = false; end | |
418 % </AlgoCode> | |
419 else | |
420 atest = false; | |
421 end | |
422 | |
423 % Return a result structure | |
424 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
425 end % END UTP_06 | |
426 | |
427 %% UTP_07 | |
428 | |
429 % <TestDescription> | |
430 % | |
431 % Check that the mrdivide method only divide PZMODELs with the same output | |
432 % units. | |
433 % | |
434 % </TestDescription> | |
435 function result = utp_07 | |
436 | |
437 % <SyntaxDescription> | |
438 % | |
439 % Check that the mrdivide method only divide PZMODELs with the same | |
440 % output units. Check also the negative case. | |
441 % | |
442 % </SyntaxDescription> | |
443 | |
444 try | |
445 % <SyntaxCode> | |
446 pz1 = pzmodel(2, pz(1), pz(-3)); | |
447 pz2 = pzmodel(3, pz(2), pz(-2)); | |
448 pz3 = pzmodel(4, pz(3), pz(-1)); | |
449 pz1.setOunits('Hz Hz^-1/2'); | |
450 pz2.setOunits('Hz Hz^-1/2'); | |
451 pz3.setOunits('Hz Hz^-1/2'); | |
452 pz1.setIunits('m'); | |
453 pz2.setIunits('Hz Hz^-1/2'); | |
454 pz3.setIunits('Hz Hz^-1/2'); | |
455 out = pz1 / pz2 / pz3; | |
456 mout = rebuild(out); | |
457 % Negative case | |
458 pz2.setOunits('m'); | |
459 try | |
460 out = pz1 / pz2; | |
461 stest = false; | |
462 catch | |
463 stest = true; | |
464 end | |
465 % </SyntaxCode> | |
466 catch err | |
467 disp(err.message) | |
468 stest = false; | |
469 end | |
470 | |
471 % <AlgoDescription> | |
472 % | |
473 % 1) Check the I-/O-units | |
474 % | |
475 % </AlgoDescription> | |
476 | |
477 atest = true; | |
478 if stest | |
479 % <AlgoCode> | |
480 % Check the I-/O-units | |
481 if ~eq(out.iunits, unit('m')), atest = false; end | |
482 if ~eq(out.ounits, unit('Hz Hz^-1/2')), atest = false; end | |
483 % Check the re-built object. | |
484 if ~eq(mout, mout, ple2), atest = false; end | |
485 % </AlgoCode> | |
486 else | |
487 atest = false; | |
488 end | |
489 | |
490 % Return a result structure | |
491 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
492 end % END UTP_07 | |
493 | |
494 end |