Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_spectrogram.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_SPECTROGRAM a set of UTPs for the ao/spectrogram method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_spectrogram.m,v 1.10 2010/09/18 06:51:58 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The spectrogram method of the ao class computes the spectrogram of time-series AOs. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_spectrogram(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'spectrogram'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test AOs | |
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]); | |
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 | |
42 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear | |
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 % <SyntaxCode> | |
75 try | |
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 stest = true; | |
85 catch err | |
86 disp(err.message) | |
87 stest = false; | |
88 end | |
89 % </SyntaxCode> | |
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 % <AlgoCode> | |
99 atest = true; | |
100 if stest | |
101 % check we have minfo objects | |
102 if isa(io, 'minfo') | |
103 prefs = getappdata(0, 'LTPDApreferences'); | |
104 defaultWinType = char(prefs.getMiscPrefs.getDefaultWindow); | |
105 | |
106 %%% SET 'None' | |
107 pn = 1; | |
108 if ~isempty(io(pn).sets), atest = false; end | |
109 if ~isempty(io(pn).plists), atest = false; end | |
110 %%% Check all Sets | |
111 pn = 2; | |
112 if ~any(strcmpi(io(pn).sets, 'Default')), atest = false; end | |
113 if numel(io(pn).plists) ~= numel(io(pn).sets), atest = false; end | |
114 %%%%%%%%%% SET 'Default' | |
115 pn = 3; | |
116 if io(pn).plists.nparams ~= 3, atest = false; end | |
117 % Check key | |
118 if ~io(pn).plists.isparam('win'), atest = false; end | |
119 if ~io(pn).plists.isparam('nolap'), atest = false; end | |
120 if ~io(pn).plists.isparam('nfft'), atest = false; end | |
121 % Check default value | |
122 if ~strcmpi(io(pn).plists.find('win'), defaultWinType), atest = false; end | |
123 if ~isequal(io(pn).plists.find('nolap'), -1), atest = false; end | |
124 if ~isequal(io(pn).plists.find('nfft'), -1), atest = false; end | |
125 % Check options | |
126 if ~isequal(io(pn).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end | |
127 if ~isequal(io(pn).plists.getOptionsForParam('nolap'), {-1}), atest = false; end | |
128 if ~isequal(io(pn).plists.getOptionsForParam('nfft'), {-1}), atest = false; end | |
129 end | |
130 else | |
131 atest = false; | |
132 end | |
133 % </AlgoCode> | |
134 | |
135 % Return a result structure | |
136 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
137 end % END UTP_01 | |
138 | |
139 %% UTP_02 | |
140 | |
141 % <TestDescription> | |
142 % | |
143 % Tests that the spectrogram method works with a vector of AOs as input. | |
144 % | |
145 % </TestDescription> | |
146 function result = utp_02 | |
147 | |
148 % <SyntaxDescription> | |
149 % | |
150 % Test that the spectrogram method works for a vector of AOs as input. | |
151 % | |
152 % </SyntaxDescription> | |
153 | |
154 % <SyntaxCode> | |
155 try | |
156 avec = [at1 at5 at6]; | |
157 out = spectrogram(avec); | |
158 stest = true; | |
159 catch err | |
160 disp(err.message) | |
161 stest = false; | |
162 end | |
163 % </SyntaxCode> | |
164 | |
165 % <AlgoDescription> | |
166 % | |
167 % 1) Check that the number of elements in 'out' is the square of the | |
168 % number in the input. | |
169 % 2) Check that each output AO contains the correct data. | |
170 % | |
171 % </AlgoDescription> | |
172 | |
173 % <AlgoCode> | |
174 atest = true; | |
175 if stest | |
176 % Check we have the correct number of outputs | |
177 if numel(out) ~= numel(avec), atest = false; end | |
178 else | |
179 atest = false; | |
180 end | |
181 % </AlgoCode> | |
182 | |
183 % Return a result structure | |
184 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
185 end % END UTP_02 | |
186 | |
187 %% UTP_03 | |
188 | |
189 % <TestDescription> | |
190 % | |
191 % Tests that the spectrogram method works with a matrix of AOs as input. | |
192 % | |
193 % </TestDescription> | |
194 function result = utp_03 | |
195 | |
196 % <SyntaxDescription> | |
197 % | |
198 % Test that the spectrogram method works for a matrix of AOs as input. | |
199 % | |
200 % </SyntaxDescription> | |
201 | |
202 % <SyntaxCode> | |
203 try | |
204 amat = [at1 at5 at6; at5 at6 at1]; | |
205 out = spectrogram(amat); | |
206 stest = true; | |
207 catch err | |
208 disp(err.message) | |
209 stest = false; | |
210 end | |
211 % </SyntaxCode> | |
212 | |
213 % <AlgoDescription> | |
214 % | |
215 % 1) Check that the number of elements in 'out' is the square of the | |
216 % number in the input. | |
217 % 2) Check that each output AO contains the correct data. | |
218 % | |
219 % </AlgoDescription> | |
220 | |
221 % <AlgoCode> | |
222 atest = true; | |
223 if stest | |
224 % Check we have the correct number of outputs | |
225 if numel(out) ~= numel(amat), atest = false; end | |
226 else | |
227 atest = false; | |
228 end | |
229 % </AlgoCode> | |
230 | |
231 % Return a result structure | |
232 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
233 end % END UTP_03 | |
234 | |
235 %% UTP_04 | |
236 | |
237 % <TestDescription> | |
238 % | |
239 % Tests that the spectrogram method works with a list of AOs as input. | |
240 % | |
241 % </TestDescription> | |
242 function result = utp_04 | |
243 | |
244 % <SyntaxDescription> | |
245 % | |
246 % Test that the spectrogram method works for a list of AOs as input. | |
247 % | |
248 % </SyntaxDescription> | |
249 | |
250 % <SyntaxCode> | |
251 try | |
252 out = spectrogram(at1,at5,at6); | |
253 stest = true; | |
254 catch err | |
255 disp(err.message) | |
256 stest = false; | |
257 end | |
258 % </SyntaxCode> | |
259 | |
260 % <AlgoDescription> | |
261 % | |
262 % 1) Check that the number of elements in 'out' is the square of the | |
263 % number in the input. | |
264 % 2) Check that each output AO contains the correct data. | |
265 % | |
266 % </AlgoDescription> | |
267 | |
268 % <AlgoCode> | |
269 atest = true; | |
270 if stest | |
271 % Check we have the correct number of outputs | |
272 if numel(out) ~= 3, atest = false; end | |
273 else | |
274 atest = false; | |
275 end | |
276 % </AlgoCode> | |
277 | |
278 % Return a result structure | |
279 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
280 end % END UTP_04 | |
281 | |
282 %% UTP_05 | |
283 | |
284 % <TestDescription> | |
285 % | |
286 % Tests that the spectrogram method works with a mix of different shaped AOs as | |
287 % input. | |
288 % | |
289 % </TestDescription> | |
290 function result = utp_05 | |
291 | |
292 % <SyntaxDescription> | |
293 % | |
294 % Test that the spectrogram method works with an input of matrices and vectors | |
295 % and single AOs. | |
296 % | |
297 % </SyntaxDescription> | |
298 | |
299 % <SyntaxCode> | |
300 try | |
301 out = spectrogram(at1,[at5 at6],at5,[at5 at1; at6 at1],at6); | |
302 stest = true; | |
303 catch err | |
304 disp(err.message) | |
305 stest = false; | |
306 end | |
307 % </SyntaxCode> | |
308 | |
309 % <AlgoDescription> | |
310 % | |
311 % 1) Check that the number of elements in 'out' is the same as in | |
312 % input. | |
313 % 2) Check that each output AO contains the correct data. | |
314 % | |
315 % </AlgoDescription> | |
316 | |
317 % <AlgoCode> | |
318 atest = true; | |
319 if stest | |
320 % Check we have the correct number of outputs | |
321 if numel(out) ~= 9, atest = false; end | |
322 else | |
323 atest = false; | |
324 end | |
325 % </AlgoCode> | |
326 | |
327 % Return a result structure | |
328 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
329 end % END UTP_05 | |
330 | |
331 %% UTP_06 | |
332 | |
333 % <TestDescription> | |
334 % | |
335 % Tests that the spectrogram method properly applies history. | |
336 % | |
337 % </TestDescription> | |
338 function result = utp_06 | |
339 | |
340 % <SyntaxDescription> | |
341 % | |
342 % Test that the result of applying the spectrogram method can be processed back | |
343 % to an m-file. | |
344 % | |
345 % </SyntaxDescription> | |
346 | |
347 % <SyntaxCode> | |
348 try | |
349 out = spectrogram(at5); | |
350 mout = rebuild(out); | |
351 stest = true; | |
352 catch err | |
353 disp(err.message) | |
354 stest = false; | |
355 end | |
356 % </SyntaxCode> | |
357 | |
358 % <AlgoDescription> | |
359 % | |
360 % 1) Check that the last entry in the history of 'out' corresponds to | |
361 % 'spectrogram'. | |
362 % 2) Check that the re-built object is the same object as 'out'. | |
363 % | |
364 % </AlgoDescription> | |
365 | |
366 % <AlgoCode> | |
367 atest = true; | |
368 if stest | |
369 % Check the last step in the history of 'out' | |
370 if ~strcmp(out.hist.methodInfo.mname, 'spectrogram'), atest = false; end | |
371 % Check the re-built object | |
372 if ~eq(mout, out, ple2), atest = false; end | |
373 else | |
374 atest = false; | |
375 end | |
376 % </AlgoCode> | |
377 | |
378 % Return a result structure | |
379 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
380 end % END UTP_06 | |
381 | |
382 end |