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