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