Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/mfir/utp_mfir_isprop.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_ISPROP a set of UTPs for the mfir/isprop method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_mfir_isprop.m,v 1.6 2011/03/29 13:13:33 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The isprop method of the mfir class determine whether input is object property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_mfir_isprop(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'mfir'; | |
21 mthd = 'isprop'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test MFIR objects | |
29 [firhp,firlp,firbp,firbr,firpzm,firao,firv,firm] = get_test_objects_mfir; | |
30 | |
31 % Exception list for the UTPs: | |
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
33 | |
34 % Run the tests | |
35 results = [results utp_01]; % getInfo call | |
36 results = [results utp_02]; % Vector input | |
37 results = [results utp_03]; % Matrix input | |
38 results = [results utp_04]; % List input | |
39 results = [results utp_05]; % Test with mixed input | |
40 results = [results utp_06]; % Test history is working | |
41 results = [results utp_07]; % Test the modify call works | |
42 results = [results utp_08]; % Test negative case | |
43 | |
44 disp('Done.'); | |
45 disp('******************************************************'); | |
46 | |
47 elseif nargin == 1 % Check for UTP functions | |
48 if strcmp(varargin{1}, 'isutp') | |
49 results = 1; | |
50 else | |
51 results = 0; | |
52 end | |
53 else | |
54 error('### Incorrect inputs') | |
55 end | |
56 | |
57 %% UTP_01 | |
58 | |
59 % <TestDescription> | |
60 % | |
61 % Tests that the getInfo call works for this method. | |
62 % | |
63 % </TestDescription> | |
64 function result = utp_01 | |
65 | |
66 | |
67 % <SyntaxDescription> | |
68 % | |
69 % Test that the getInfo call works for no sets, all sets, and each set | |
70 % individually. | |
71 % | |
72 % </SyntaxDescription> | |
73 | |
74 try | |
75 % <SyntaxCode> | |
76 % Call for no sets | |
77 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
78 % Call for all sets | |
79 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
80 % Call for each set | |
81 for kk=1:numel(io(2).sets) | |
82 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
83 end | |
84 % </SyntaxCode> | |
85 stest = true; | |
86 catch err | |
87 disp(err.message) | |
88 stest = false; | |
89 end | |
90 | |
91 % <AlgoDescription> | |
92 % | |
93 % 1) Check that getInfo call returned an minfo object in all cases. | |
94 % 2) Check that all plists have the correct parameters. | |
95 % | |
96 % </AlgoDescription> | |
97 | |
98 atest = true; | |
99 if stest | |
100 % <AlgoCode> | |
101 % check we have minfo objects | |
102 if isa(io, 'minfo') | |
103 % SET 'None' | |
104 if ~isempty(io(1).sets), atest = false; end | |
105 if ~isempty(io(1).plists), atest = false; end | |
106 % Check all Sets | |
107 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
108 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
109 % SET 'Default' | |
110 if io(3).plists.nparams ~= 0, atest = false; end | |
111 % Check key | |
112 % Check default value | |
113 % Check options | |
114 end | |
115 % </AlgoCode> | |
116 else | |
117 atest = false; | |
118 end | |
119 | |
120 % Return a result structure | |
121 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
122 end % END UTP_01 | |
123 | |
124 %% UTP_02 | |
125 | |
126 % <TestDescription> | |
127 % | |
128 % Tests that the isprop method works with a vector of MFIR objects as input. | |
129 % | |
130 % </TestDescription> | |
131 function result = utp_02 | |
132 | |
133 % <SyntaxDescription> | |
134 % | |
135 % Test that the isprop method works for a vector of MFIR objects as input. | |
136 % | |
137 % </SyntaxDescription> | |
138 | |
139 try | |
140 % <SyntaxCode> | |
141 out = isprop(firv, 'name'); | |
142 % </SyntaxCode> | |
143 stest = true; | |
144 catch err | |
145 disp(err.message) | |
146 stest = false; | |
147 end | |
148 | |
149 % <AlgoDescription> | |
150 % | |
151 % 1) Check that the number of elements in 'out' is the same as in 'firv' | |
152 % 2) Check that each output contains the correct data. | |
153 % | |
154 % </AlgoDescription> | |
155 | |
156 atest = true; | |
157 if stest | |
158 % <AlgoCode> | |
159 % Check we have the correct number of outputs | |
160 if ~isequal(size(out), size(firv)), atest = false; end | |
161 % Check each output | |
162 if ~all(out), atest = false; end | |
163 % </AlgoCode> | |
164 else | |
165 atest = false; | |
166 end | |
167 | |
168 % Return a result structure | |
169 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
170 end % END UTP_02 | |
171 | |
172 %% UTP_03 | |
173 | |
174 % <TestDescription> | |
175 % | |
176 % Tests that the isprop method works with a matrix of MFIR objects as input. | |
177 % | |
178 % </TestDescription> | |
179 function result = utp_03 | |
180 | |
181 % <SyntaxDescription> | |
182 % | |
183 % Test that the isprop method works for a matrix of MFIR objects as input. | |
184 % | |
185 % </SyntaxDescription> | |
186 | |
187 try | |
188 % <SyntaxCode> | |
189 out = isprop(firm, 'name'); | |
190 % </SyntaxCode> | |
191 stest = true; | |
192 catch err | |
193 disp(err.message) | |
194 stest = false; | |
195 end | |
196 | |
197 % <AlgoDescription> | |
198 % | |
199 % 1) Check that the number of elements in 'out' is the same as in 'firm' | |
200 % 2) Check that each output contains the correct data. | |
201 % | |
202 % </AlgoDescription> | |
203 | |
204 atest = true; | |
205 if stest | |
206 % <AlgoCode> | |
207 % Check we have the correct number of outputs | |
208 if ~isequal(size(out), size(firm)), atest = false; end | |
209 % Check each output | |
210 if ~all(out), atest = false; end | |
211 % </AlgoCode> | |
212 else | |
213 atest = false; | |
214 end | |
215 | |
216 % Return a result structure | |
217 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
218 end % END UTP_03 | |
219 | |
220 %% UTP_04 | |
221 | |
222 % <TestDescription> | |
223 % | |
224 % Tests that the isprop method works with a list of MFIR objects as input. | |
225 % | |
226 % </TestDescription> | |
227 function result = utp_04 | |
228 | |
229 % <SyntaxDescription> | |
230 % | |
231 % Test that the isprop method works for a list of MFIR objects as input. | |
232 % | |
233 % </SyntaxDescription> | |
234 | |
235 try | |
236 % <SyntaxCode> | |
237 out = isprop(firlp,firpzm,firbr, 'name'); | |
238 % </SyntaxCode> | |
239 stest = true; | |
240 catch err | |
241 disp(err.message) | |
242 stest = false; | |
243 end | |
244 | |
245 % <AlgoDescription> | |
246 % | |
247 % 1) Check that the number of elements in 'out' is the same as in | |
248 % input. | |
249 % 2) Check that each output contains the correct data. | |
250 % | |
251 % </AlgoDescription> | |
252 | |
253 atest = true; | |
254 if stest | |
255 % <AlgoCode> | |
256 % Check we have the correct number of outputs | |
257 if numel(out) ~= 3, atest = false; end | |
258 % Check each output | |
259 if ~all(out), atest = false; end | |
260 % </AlgoCode> | |
261 else | |
262 atest = false; | |
263 end | |
264 | |
265 % Return a result structure | |
266 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
267 end % END UTP_04 | |
268 | |
269 %% UTP_05 | |
270 | |
271 % <TestDescription> | |
272 % | |
273 % Tests that the isprop method works with a mix of different shaped | |
274 % MFIR objects as input. | |
275 % | |
276 % </TestDescription> | |
277 function result = utp_05 | |
278 | |
279 % <SyntaxDescription> | |
280 % | |
281 % Test that the isprop method works with an input of matrices and vectors | |
282 % and single MFIR objects. | |
283 % | |
284 % </SyntaxDescription> | |
285 | |
286 try | |
287 % <SyntaxCode> | |
288 out = isprop(firlp,firv,firpzm,firm,firbr, 'name'); | |
289 % </SyntaxCode> | |
290 stest = true; | |
291 catch err | |
292 disp(err.message) | |
293 stest = false; | |
294 end | |
295 | |
296 % <AlgoDescription> | |
297 % | |
298 % 1) Check that the number of elements in 'out' is the same as in | |
299 % input. | |
300 % 2) Check that each output contains the correct data. | |
301 % | |
302 % </AlgoDescription> | |
303 | |
304 atest = true; | |
305 if stest | |
306 % <AlgoCode> | |
307 % Check we have the correct number of outputs | |
308 if numel(out) ~= (3+numel(firm)+numel(firv)), atest = false; end | |
309 % Check each output | |
310 if ~all(out), atest = false; end | |
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 isprop method properly applies history. | |
325 % | |
326 % </TestDescription> | |
327 function result = utp_06 | |
328 | |
329 % <SyntaxDescription> | |
330 % | |
331 % The method isprop doesn't change the object, thus it is not necessary to | |
332 % apply history. | |
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 % Tests that the isprop method works for each property. | |
366 % | |
367 % </TestDescription> | |
368 function result = utp_07 | |
369 | |
370 % <SyntaxDescription> | |
371 % | |
372 % Test that the isprop method works for the properties: | |
373 % 'gd', 'ntaps', 'fs', 'infile', 'a', 'histout', | |
374 % 'iunits', 'ounits', 'hist', 'name' | |
375 % | |
376 % </SyntaxDescription> | |
377 | |
378 try | |
379 % <SyntaxCode> | |
380 % copy firlp to work with | |
381 out1 = isprop(firlp, 'gd'); | |
382 out3 = isprop(firlp, 'ntaps'); | |
383 out4 = isprop(firlp, 'fs'); | |
384 out5 = isprop(firlp, 'infile'); | |
385 out6 = isprop(firlp, 'a'); | |
386 out7 = isprop(firlp, 'histout'); | |
387 out8 = isprop(firlp, 'iunits'); | |
388 out9 = isprop(firlp, 'ounits'); | |
389 out10 = isprop(firlp, 'hist'); | |
390 out11 = isprop(firlp, 'name'); | |
391 % </SyntaxCode> | |
392 stest = true; | |
393 catch err | |
394 disp(err.message) | |
395 stest = false; | |
396 end | |
397 | |
398 % <AlgoDescription> | |
399 % | |
400 % 1) Check that each output contains the correct data. | |
401 % | |
402 % </AlgoDescription> | |
403 | |
404 atest = true; | |
405 if stest | |
406 % <AlgoCode> | |
407 if ~out1, atest = false; end; | |
408 if ~out3, atest = false; end; | |
409 if ~out4, atest = false; end; | |
410 if ~out5, atest = false; end; | |
411 if ~out6, atest = false; end; | |
412 if ~out7, atest = false; end; | |
413 if ~out8, atest = false; end; | |
414 if ~out9, atest = false; end; | |
415 if ~out10, atest = false; end; | |
416 if ~out11, atest = false; end; | |
417 % </AlgoCode> | |
418 else | |
419 atest = false; | |
420 end | |
421 | |
422 % Return a result structure | |
423 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
424 end % END UTP_07 | |
425 | |
426 %% UTP_08 | |
427 | |
428 % <TestDescription> | |
429 % | |
430 % Test the negative case and the not function command. | |
431 % | |
432 % </TestDescription> | |
433 function result = utp_08 | |
434 | |
435 % <SyntaxDescription> | |
436 % | |
437 % Test that the isprop method retrun false for a unknown property and for | |
438 % methods of the object. | |
439 % | |
440 % </SyntaxDescription> | |
441 | |
442 try | |
443 % <SyntaxCode> | |
444 out1 = isprop(firbp, 'foo'); | |
445 out2 = firbp.isprop('foo'); | |
446 out3 = firbp.isprop('name'); | |
447 out4 = firbp.isprop('type'); | |
448 out5 = firbp.isprop('char'); | |
449 out6 = firbp.isprop('creator'); | |
450 out7 = firbp.isprop('created'); | |
451 % </SyntaxCode> | |
452 stest = true; | |
453 catch err | |
454 disp(err.message) | |
455 stest = false; | |
456 end | |
457 | |
458 % <AlgoDescription> | |
459 % | |
460 % 1) Check that each output contains the correct data. | |
461 % | |
462 % </AlgoDescription> | |
463 | |
464 atest = true; | |
465 if stest | |
466 % <AlgoCode> | |
467 if out1, atest = false; end; | |
468 if out2, atest = false; end; | |
469 if ~out3, atest = false; end; | |
470 if out4, atest = false; end; | |
471 if out5, atest = false; end; | |
472 if out6, atest = false; end; | |
473 if out7, atest = false; end; | |
474 % </AlgoCode> | |
475 else | |
476 atest = false; | |
477 end | |
478 | |
479 % Return a result structure | |
480 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
481 end % END UTP_08 | |
482 | |
483 end |