Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/miir/utp_miir_string.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_STRING a set of UTPs for the miir/string method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_miir_string.m,v 1.2 2009/07/23 14:12:02 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The string method of the miir class writes a command string that can be | |
11 % used to recreate the input object(s). But the object should not have more than | |
12 % one history step. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_miir_string(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'miir'; | |
23 mthd = 'string'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 iir1 = miir(plist('type', 'lowpass')); | |
31 iir2 = miir(plist('type', 'highpass')); | |
32 iirv = [iir1, iir2, iir1]; | |
33 iirm = [iir1, iir2, iir1; iir1, iir2, iir1]; | |
34 | |
35 % Exception list for the UTPs: | |
36 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
37 | |
38 % Run the tests | |
39 results = [results utp_01]; % getInfo call | |
40 results = [results utp_02]; % Vector input | |
41 results = [results utp_03]; % Matrix input | |
42 results = [results utp_04]; % List input | |
43 results = [results utp_05]; % Test with mixed input | |
44 results = [results utp_06]; % Test history is working | |
45 results = [results utp_07]; % Negative test: The object have more than one history step. | |
46 | |
47 disp('Done.'); | |
48 disp('******************************************************'); | |
49 | |
50 elseif nargin == 1 % Check for UTP functions | |
51 if strcmp(varargin{1}, 'isutp') | |
52 results = 1; | |
53 else | |
54 results = 0; | |
55 end | |
56 else | |
57 error('### Incorrect inputs') | |
58 end | |
59 | |
60 %% UTP_01 | |
61 | |
62 % <TestDescription> | |
63 % | |
64 % Tests that the getInfo call works for this method. | |
65 % | |
66 % </TestDescription> | |
67 function result = utp_01 | |
68 | |
69 | |
70 % <SyntaxDescription> | |
71 % | |
72 % Test that the getInfo call works for no sets, all sets, and each set | |
73 % individually. | |
74 % | |
75 % </SyntaxDescription> | |
76 | |
77 try | |
78 % <SyntaxCode> | |
79 % Call for no sets | |
80 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
81 % Call for all sets | |
82 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
83 % Call for each set | |
84 for kk=1:numel(io(2).sets) | |
85 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
86 end | |
87 % </SyntaxCode> | |
88 stest = true; | |
89 catch err | |
90 disp(err.message) | |
91 stest = false; | |
92 end | |
93 | |
94 % <AlgoDescription> | |
95 % | |
96 % 1) Check that getInfo call returned an minfo object in all cases. | |
97 % 2) Check that all plists have the correct parameters. | |
98 % | |
99 % </AlgoDescription> | |
100 | |
101 atest = true; | |
102 if stest | |
103 % <AlgoCode> | |
104 % check we have minfo objects | |
105 if isa(io, 'minfo') | |
106 % SET 'None' | |
107 if ~isempty(io(1).sets), atest = false; end | |
108 if ~isempty(io(1).plists), atest = false; end | |
109 % Check all Sets | |
110 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
111 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
112 % SET 'Default' | |
113 if io(3).plists.nparams ~= 0, atest = false; end | |
114 % Check key | |
115 % Check default value | |
116 % Check options | |
117 end | |
118 % </AlgoCode> | |
119 else | |
120 atest = false; | |
121 end | |
122 | |
123 % Return a result structure | |
124 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
125 end % END UTP_01 | |
126 | |
127 %% UTP_02 | |
128 | |
129 % <TestDescription> | |
130 % | |
131 % Tests that the string method works with a vector of MIIR objects as input. | |
132 % | |
133 % </TestDescription> | |
134 function result = utp_02 | |
135 | |
136 % <SyntaxDescription> | |
137 % | |
138 % Test that the string method works for a vector of MIIR objects as input. | |
139 % | |
140 % </SyntaxDescription> | |
141 | |
142 try | |
143 % <SyntaxCode> | |
144 out = string(iirv); | |
145 rout = eval(out); | |
146 % </SyntaxCode> | |
147 stest = true; | |
148 catch err | |
149 disp(err.message) | |
150 stest = false; | |
151 end | |
152 | |
153 % <AlgoDescription> | |
154 % | |
155 % 1) Check that the output is a executable string. | |
156 % 2) Check the correct number of rout | |
157 % 3) Check the rebuild objects. | |
158 % | |
159 % </AlgoDescription> | |
160 | |
161 atest = true; | |
162 if stest | |
163 % <AlgoCode> | |
164 % Check the output | |
165 if ~ischar(out), atest = false; end; | |
166 if ~isa(rout, 'miir'), atest = false; end | |
167 if numel(rout) ~= numel(iirv), atest = false; end | |
168 for kk = 1:numel(iirv) | |
169 if eq(rout(kk), iirv(kk)), atest = false; end | |
170 end | |
171 % </AlgoCode> | |
172 else | |
173 atest = false; | |
174 end | |
175 | |
176 % Return a result structure | |
177 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
178 end % END UTP_02 | |
179 | |
180 %% UTP_03 | |
181 | |
182 % <TestDescription> | |
183 % | |
184 % Tests that the string method works with a matrix of MIIR objects as input. | |
185 % | |
186 % </TestDescription> | |
187 function result = utp_03 | |
188 | |
189 % <SyntaxDescription> | |
190 % | |
191 % Test that the string method works for a matrix of MIIR objects as input. | |
192 % | |
193 % </SyntaxDescription> | |
194 | |
195 try | |
196 % <SyntaxCode> | |
197 out = string(iirm); | |
198 rout = eval(out); | |
199 % </SyntaxCode> | |
200 stest = true; | |
201 catch err | |
202 disp(err.message) | |
203 stest = false; | |
204 end | |
205 | |
206 % <AlgoDescription> | |
207 % | |
208 % 1) Check that the output is a executable string. | |
209 % 2) Check the correct number of rout | |
210 % 3) Check the rebuild objects. | |
211 % | |
212 % </AlgoDescription> | |
213 | |
214 atest = true; | |
215 if stest | |
216 % <AlgoCode> | |
217 % Check the output | |
218 if ~ischar(out), atest = false; end | |
219 if ~isa(rout, 'miir'), atest = false; end | |
220 if numel(rout) ~= numel(iirm), atest = false; end | |
221 for kk = 1:numel(iirm) | |
222 if eq(rout(kk), iirm(kk)), atest = false; end | |
223 end | |
224 % </AlgoCode> | |
225 else | |
226 atest = false; | |
227 end | |
228 | |
229 % Return a result structure | |
230 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
231 end % END UTP_03 | |
232 | |
233 %% UTP_04 | |
234 | |
235 % <TestDescription> | |
236 % | |
237 % Tests that the string method works with a list of MIIR objects as input. | |
238 % | |
239 % </TestDescription> | |
240 function result = utp_04 | |
241 | |
242 % <SyntaxDescription> | |
243 % | |
244 % Test that the string method works for a list of MIIR objects as input. | |
245 % | |
246 % </SyntaxDescription> | |
247 | |
248 try | |
249 % <SyntaxCode> | |
250 out = string(iir1,iir2); | |
251 rout = eval(out); | |
252 % </SyntaxCode> | |
253 stest = true; | |
254 catch err | |
255 disp(err.message) | |
256 stest = false; | |
257 end | |
258 | |
259 % <AlgoDescription> | |
260 % | |
261 % 1) Check that the output is a executable string. | |
262 % 2) Check the correct number of rout | |
263 % 3) Check the rebuild objects. | |
264 % | |
265 % </AlgoDescription> | |
266 | |
267 atest = true; | |
268 iirin = [iir1, iir2]; | |
269 if stest | |
270 % <AlgoCode> | |
271 % Check the output | |
272 if ~ischar(out), atest = false; end | |
273 if ~isa(rout, 'miir'), atest = false; end | |
274 if numel(rout) ~= numel(iirin), atest = false; end | |
275 for kk = 1:numel(iirin) | |
276 if eq(rout(kk), iirin(kk)), atest = false; end | |
277 end | |
278 % </AlgoCode> | |
279 else | |
280 atest = false; | |
281 end | |
282 | |
283 % Return a result structure | |
284 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
285 end % END UTP_04 | |
286 | |
287 %% UTP_05 | |
288 | |
289 % <TestDescription> | |
290 % | |
291 % Tests that the string method works with a mix of different shaped MIIR objects | |
292 % as input. | |
293 % | |
294 % </TestDescription> | |
295 function result = utp_05 | |
296 | |
297 % <SyntaxDescription> | |
298 % | |
299 % Test that the string method works with an input of matrices and vectors | |
300 % and single MIIR objects. | |
301 % | |
302 % </SyntaxDescription> | |
303 | |
304 try | |
305 % <SyntaxCode> | |
306 out = string(iir1,iirm,iir2); | |
307 rout = eval(out); | |
308 % </SyntaxCode> | |
309 stest = true; | |
310 catch err | |
311 disp(err.message) | |
312 stest = false; | |
313 end | |
314 | |
315 % <AlgoDescription> | |
316 % | |
317 % 1) Check that the output is a executable string. | |
318 % 2) Check the correct number of rout | |
319 % 3) Check the rebuild objects. | |
320 % | |
321 % </AlgoDescription> | |
322 | |
323 atest = true; | |
324 iirin = [iir1, reshape(iirm, 1, []), iir2]; | |
325 if stest | |
326 % <AlgoCode> | |
327 % Check the output | |
328 if ~ischar(out), atest = false; end | |
329 if ~isa(rout, 'miir'), atest = false; end | |
330 if numel(rout) ~= numel(iirin), atest = false; end | |
331 for kk = 1:numel(iirin) | |
332 if eq(rout(kk), iirin(kk)), atest = false; end | |
333 end | |
334 % </AlgoCode> | |
335 else | |
336 atest = false; | |
337 end | |
338 | |
339 % Return a result structure | |
340 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
341 end % END UTP_05 | |
342 | |
343 %% UTP_06 | |
344 | |
345 % <TestDescription> | |
346 % | |
347 % Tests that the string method properly applies history. | |
348 % | |
349 % </TestDescription> | |
350 function result = utp_06 | |
351 | |
352 % <SyntaxDescription> | |
353 % | |
354 % The method string doesn't change the data, thus it is not possible to check | |
355 % the history. Nothing to do. | |
356 % | |
357 % </SyntaxDescription> | |
358 | |
359 try | |
360 % <SyntaxCode> | |
361 % </SyntaxCode> | |
362 stest = true; | |
363 catch err | |
364 disp(err.message) | |
365 stest = false; | |
366 end | |
367 | |
368 % <AlgoDescription> | |
369 % | |
370 % </AlgoDescription> | |
371 | |
372 atest = true; | |
373 if stest | |
374 % <AlgoCode> | |
375 % </AlgoCode> | |
376 else | |
377 atest = false; | |
378 end | |
379 | |
380 % Return a result structure | |
381 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
382 end % END UTP_06 | |
383 | |
384 %% UTP_07 | |
385 | |
386 % <TestDescription> | |
387 % | |
388 % Tests that the string method doesn't work if the MIIR object have more | |
389 % than one history step. | |
390 % | |
391 % </TestDescription> | |
392 function result = utp_07 | |
393 | |
394 % <SyntaxDescription> | |
395 % | |
396 % The method string throws an error because the input object have more than | |
397 % one history step. | |
398 % | |
399 % </SyntaxDescription> | |
400 | |
401 try | |
402 % <SyntaxCode> | |
403 iir3 = miir(plist('type', 'bandpass')); | |
404 iir3.setName('Second history step'); | |
405 out = iir3.string(); | |
406 % </SyntaxCode> | |
407 stest = false; | |
408 catch err | |
409 stest = true; | |
410 end | |
411 | |
412 % <AlgoDescription> | |
413 % | |
414 % </AlgoDescription> | |
415 | |
416 atest = true; | |
417 if stest | |
418 % <AlgoCode> | |
419 % </AlgoCode> | |
420 else | |
421 atest = false; | |
422 end | |
423 | |
424 % Return a result structure | |
425 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
426 end % END UTP_07 | |
427 | |
428 end |