Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_filtSubtract.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_AO_FILTSUBTRACT a set of UTPs for the ao/filtSubtract method | |
2 % | |
3 % M Nofrarias 05-07-09 | |
4 % | |
5 % $Id: utp_ao_filtSubtract.m,v 1.3 2011/04/17 15:46:21 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % FILTSUBTRACT subtracts a frequency dependent noise contribution from an | |
11 % input ao. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_filtSubtract(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'filtSubtract'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test AOs | |
30 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]); | |
31 | |
32 at1.setYunits('Hz'); | |
33 at2.setYunits('Hz'); | |
34 at3.setYunits('Hz'); | |
35 at4.setYunits('Hz'); | |
36 at5.setYunits('Hz'); | |
37 at6.setYunits('Hz'); | |
38 | |
39 % Exception list for the UTPs: | |
40 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
41 | |
42 % Run the tests | |
43 results = [results utp_01]; % getInfo call | |
44 results = [results utp_02]; % Vector input | |
45 results = [results utp_03]; % Matrix input | |
46 results = [results utp_04]; % List input | |
47 results = [results utp_05]; % Test with mixed input | |
48 results = [results utp_06]; % Test history is working | |
49 results = [results utp_07]; % Test output of the data | |
50 | |
51 % | |
52 disp('Done.'); | |
53 disp('******************************************************'); | |
54 | |
55 elseif nargin == 1 % Check for UTP functions | |
56 if strcmp(varargin{1}, 'isutp') | |
57 results = 1; | |
58 else | |
59 results = 0; | |
60 end | |
61 else | |
62 error('### Incorrect inputs') | |
63 end | |
64 | |
65 %% UTP_01 | |
66 | |
67 % <TestDescription> | |
68 % | |
69 % Tests that the getInfo call works for this method. | |
70 % | |
71 % </TestDescription> | |
72 function result = utp_01 | |
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 % <SyntaxCode> | |
82 try | |
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 stest = true; | |
92 catch err | |
93 disp(err.message) | |
94 stest = false; | |
95 end | |
96 % </SyntaxCode> | |
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 % <AlgoCode> | |
106 atest = true; | |
107 if stest | |
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 all Sets | |
114 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
115 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
116 % SET 'Default' | |
117 if io(3).plists.nparams ~= 5, atest = false; end | |
118 % Check key | |
119 % Check default value | |
120 % Check options | |
121 end | |
122 else | |
123 atest = false; | |
124 end | |
125 % </AlgoCode> | |
126 | |
127 % Return a result structure | |
128 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
129 end % END UTP_01 | |
130 | |
131 %% UTP_02 | |
132 | |
133 % <TestDescription> | |
134 % | |
135 % Tests that the filtSubtract method works with a vector of AOs as input. | |
136 % | |
137 % </TestDescription> | |
138 function result = utp_02 | |
139 | |
140 % <SyntaxDescription> | |
141 % | |
142 % Test that the filtSubtract method works for a vector of AOs as input. | |
143 % | |
144 % </SyntaxDescription> | |
145 | |
146 % <SyntaxCode> | |
147 try | |
148 avec = [at1 at5]; | |
149 fs = at1.fs; | |
150 out = filtSubtract(avec); | |
151 stest = true; | |
152 catch err | |
153 disp(err.message) | |
154 stest = false; | |
155 end | |
156 % </SyntaxCode> | |
157 | |
158 % <AlgoDescription> | |
159 % | |
160 % 1) Check that the number of elements in 'out' is the square of the | |
161 % number in the input. | |
162 % 2) Check that each output AO contains the correct data. | |
163 % | |
164 % </AlgoDescription> | |
165 | |
166 % <AlgoCode> | |
167 atest = true; | |
168 if stest | |
169 % Check we have the correct number of outputs | |
170 if numel(out) ~= 1, atest = false; end | |
171 else | |
172 atest = false; | |
173 end | |
174 % </AlgoCode> | |
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 filtSubtract method works with a matrix of AOs as input. | |
185 % | |
186 % </TestDescription> | |
187 function result = utp_03 | |
188 | |
189 % <SyntaxDescription> | |
190 % | |
191 % Test that the filtSubtract method works for a matrix of AOs as input. | |
192 % | |
193 % </SyntaxDescription> | |
194 | |
195 % <SyntaxCode> | |
196 try | |
197 amat = [at1; at5]; | |
198 out = filtSubtract(amat); | |
199 stest = true; | |
200 catch err | |
201 disp(err.message) | |
202 stest = false; | |
203 end | |
204 % </SyntaxCode> | |
205 | |
206 % <AlgoDescription> | |
207 % | |
208 % 1) Check that the number of elements in 'out' is the square of the | |
209 % number in the input. | |
210 % 2) Check that each output AO contains the correct data. | |
211 % | |
212 % </AlgoDescription> | |
213 | |
214 % <AlgoCode> | |
215 atest = true; | |
216 if stest | |
217 % Check we have the correct number of outputs | |
218 if numel(out) ~= 1, atest = false; end | |
219 else | |
220 atest = false; | |
221 end | |
222 % </AlgoCode> | |
223 | |
224 % Return a result structure | |
225 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
226 end % END UTP_03 | |
227 | |
228 %% UTP_04 | |
229 | |
230 % <TestDescription> | |
231 % | |
232 % Tests that the filtSubtract method works with a list of AOs as input. | |
233 % | |
234 % </TestDescription> | |
235 function result = utp_04 | |
236 | |
237 % <SyntaxDescription> | |
238 % | |
239 % Test that the filtSubtract method works for a list of AOs as input. | |
240 % | |
241 % </SyntaxDescription> | |
242 | |
243 % <SyntaxCode> | |
244 try | |
245 out = filtSubtract(at1,at5); | |
246 stest = true; | |
247 catch err | |
248 disp(err.message) | |
249 stest = false; | |
250 end | |
251 % </SyntaxCode> | |
252 | |
253 % <AlgoDescription> | |
254 % | |
255 % 1) Check that the number of elements in 'out' is the square of the | |
256 % number in the input. | |
257 % 2) Check that each output AO contains the correct data. | |
258 % | |
259 % </AlgoDescription> | |
260 | |
261 % <AlgoCode> | |
262 atest = true; | |
263 if stest | |
264 % Check we have the correct number of outputs | |
265 if numel(out) ~= 1, atest = false; end | |
266 else | |
267 atest = false; | |
268 end | |
269 % </AlgoCode> | |
270 | |
271 % Return a result structure | |
272 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
273 end % END UTP_04 | |
274 | |
275 %% UTP_05 | |
276 % <TestDescription> | |
277 % | |
278 % Tests that the filtSubtract method works with a mix of different shaped AOs as | |
279 % input. | |
280 % | |
281 % DOES NOT APPLY TO THIS METHOD | |
282 % | |
283 % </TestDescription> | |
284 function result = utp_05 | |
285 | |
286 % <SyntaxDescription> | |
287 % | |
288 % Test that the filtSubtract method works with an input of matrices and vectors | |
289 % and single AOs. | |
290 % | |
291 % </SyntaxDescription> | |
292 | |
293 % <SyntaxCode> | |
294 try | |
295 % out = filtSubtract(at1,[at5 at6],at5,[at5 at1; at6 at1],at6,pl); | |
296 stest = true; | |
297 catch err | |
298 disp(err.message) | |
299 stest = false; | |
300 end | |
301 % </SyntaxCode> | |
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 AO contains the correct data. | |
308 % | |
309 % </AlgoDescription> | |
310 | |
311 % <AlgoCode> | |
312 atest = true; | |
313 if stest | |
314 % Check we have the correct number of outputs | |
315 % if numel(out) ~= 1, atest = false; end | |
316 else | |
317 atest = false; | |
318 end | |
319 % </AlgoCode> | |
320 | |
321 % Return a result structure | |
322 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
323 end % END UTP_05 | |
324 | |
325 %% UTP_06 | |
326 % <TestDescription> | |
327 % | |
328 % Tests that the filtSubtract method properly applies history. | |
329 % | |
330 % </TestDescription> | |
331 function result = utp_06 | |
332 | |
333 % <SyntaxDescription> | |
334 % | |
335 % Test that the result of applying the filtSubtract method can be processed back | |
336 % to an m-file. | |
337 % | |
338 % </SyntaxDescription> | |
339 | |
340 % <SyntaxCode> | |
341 try | |
342 out = filtSubtract(at1,at5); | |
343 mout = rebuild(out); | |
344 stest = true; | |
345 catch err | |
346 disp(err.message) | |
347 stest = false; | |
348 end | |
349 % </SyntaxCode> | |
350 | |
351 % <AlgoDescription> | |
352 % | |
353 % 1) Check that the last entry in the history of 'out' corresponds to | |
354 % 'filtSubtract'. | |
355 % 2) Check that the re-built object is the same object as 'out'. | |
356 % | |
357 % </AlgoDescription> | |
358 | |
359 % <AlgoCode> | |
360 atest = true; | |
361 if stest | |
362 % Check the last step in the history of 'out' | |
363 if ~strcmp(out.hist.methodInfo.mname, 'filtSubtract'), atest = false; end | |
364 % Check the re-built object | |
365 if ~eq(mout, out, ple2), atest = false; end | |
366 else | |
367 atest = false; | |
368 end | |
369 % </AlgoCode> | |
370 | |
371 % Return a result structure | |
372 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
373 end % END UTP_06 | |
374 | |
375 %% UTP_07 | |
376 | |
377 % <TestDescription> | |
378 % | |
379 % Tests that the filtSubtract method can not modify the input AO. | |
380 % | |
381 % </TestDescription> | |
382 function result = utp_07 | |
383 | |
384 % <SyntaxDescription> | |
385 % | |
386 % Test that the tfe method can not modify the input AO. | |
387 % The method must throw an error for the modifier call. | |
388 % | |
389 % </SyntaxDescription> | |
390 | |
391 try | |
392 % <SyntaxCode> | |
393 % copy at1 to work with | |
394 ain = ao(at1); | |
395 % modify ain | |
396 ain.filtSubtract(at1,at5,at6); | |
397 % </SyntaxCode> | |
398 stest = false; | |
399 catch err | |
400 stest = true; | |
401 end | |
402 | |
403 % <AlgoDescription> | |
404 % | |
405 % 1) Nothing to check. | |
406 % | |
407 % </AlgoDescription> | |
408 | |
409 atest = true; | |
410 if stest | |
411 % <AlgoCode> | |
412 % </AlgoCode> | |
413 else | |
414 atest = false; | |
415 end | |
416 | |
417 % Return a result structure | |
418 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
419 end % END UTP_07 | |
420 | |
421 | |
422 | |
423 end | |
424 |