Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_getdof.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_GETDOF a set of UTPs for the ao/getdof method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_getdof.m,v 1.3 2011/07/14 05:32:11 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The getdof method of the ao class computes the degrees of freedom for spectral estimate. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_getdof(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 addpath(fullfile(fileparts(which(mfilename)), 'reference_files')) | |
20 | |
21 % Some keywords | |
22 class = 'ao'; | |
23 mthd = 'getdof'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 % Exception list for the UTPs: | |
31 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
32 | |
33 % reference dofs | |
34 rdof = [32;34;38;44;52;59;62;63;63;63]; | |
35 | |
36 % reference ao for dof test | |
37 plrefdata = plist('fs', 1, 'nsecs', 1024, ... | |
38 'tsfcn', 'randn(size(t))'); | |
39 refdata = ao(plrefdata); | |
40 | |
41 % reference overlap for dof test | |
42 rolap = (0:10:90); | |
43 | |
44 | |
45 % Run the tests | |
46 results = [results utp_01]; % getInfo call | |
47 results = [results utp_06]; % Test history is working | |
48 results = [results utp_07]; % Test against reference data | |
49 | |
50 | |
51 disp('Done.'); | |
52 disp('******************************************************'); | |
53 | |
54 elseif nargin == 1 % Check for UTP functions | |
55 if strcmp(varargin{1}, 'isutp') | |
56 results = 1; | |
57 else | |
58 results = 0; | |
59 end | |
60 else | |
61 error('### Incorrect inputs') | |
62 end | |
63 | |
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 | |
75 % <SyntaxDescription> | |
76 % | |
77 % Test that the getInfo call works for no sets, all sets, and each set | |
78 % individually. | |
79 % | |
80 % </SyntaxDescription> | |
81 | |
82 % <SyntaxCode> | |
83 try | |
84 % Call for no sets | |
85 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
86 % Call for all sets | |
87 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
88 % Call for each set | |
89 for kk=1:numel(io(2).sets) | |
90 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
91 end | |
92 stest = true; | |
93 catch err | |
94 disp(err.message) | |
95 stest = false; | |
96 end | |
97 % </SyntaxCode> | |
98 | |
99 % <AlgoDescription> | |
100 % | |
101 % 1) Check that getInfo call returned an minfo object in all cases. | |
102 % 2) Check that all plists have the correct parameters. | |
103 % | |
104 % </AlgoDescription> | |
105 | |
106 % <AlgoCode> | |
107 atest = true; | |
108 if stest | |
109 % check we have minfo objects | |
110 if isa(io, 'minfo') | |
111 | |
112 %%% SET 'None' | |
113 if ~isempty(io(1).sets), atest = false; end | |
114 if ~isempty(io(1).plists), atest = false; end | |
115 %%% Check all Sets | |
116 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
117 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
118 %%%%%%%%%% Default PList | |
119 if io(3).plists.nparams ~= 4, atest = false; end | |
120 % Check key | |
121 if ~io(3).plists.isparam('method'), atest = false; end | |
122 if ~io(3).plists.isparam('DataLength'), atest = false; end | |
123 if ~io(3).plists.isparam('conf'), atest = false; end | |
124 if ~io(3).plists.isparam('dof'), atest = false; end | |
125 % Check default value | |
126 if ~isequal(io(3).plists.find('method'), 'psd'), atest = false; end | |
127 if ~isequal(io(3).plists.find('DataLength'), paramValue.EMPTY_DOUBLE), atest = false; end | |
128 if ~isequal(io(3).plists.find('conf'), 95), atest = false; end | |
129 if ~isequal(io(3).plists.find('dof'), paramValue.EMPTY_DOUBLE), atest = false; end | |
130 % Check options | |
131 if ~isequal(io(3).plists.getOptionsForParam('method'), {'psd','lpsd','mscohere','mslcohere'}), atest = false; end | |
132 if ~isequal(io(3).plists.getOptionsForParam('DataLength'), {paramValue.EMPTY_DOUBLE}), atest = false; end | |
133 if ~isequal(io(3).plists.getOptionsForParam('conf'), {95}), atest = false; end | |
134 if ~isequal(io(3).plists.getOptionsForParam('dof'), {paramValue.EMPTY_DOUBLE}), atest = false; end | |
135 end | |
136 else | |
137 atest = false; | |
138 end | |
139 % </AlgoCode> | |
140 | |
141 % Return a result structure | |
142 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
143 end % END UTP_01 | |
144 | |
145 %% UTP_06 | |
146 | |
147 % <TestDescription> | |
148 % | |
149 % Tests that the getdof method properly applies history. | |
150 % | |
151 % </TestDescription> | |
152 function result = utp_06 | |
153 | |
154 % <SyntaxDescription> | |
155 % | |
156 % Test that the result of applying the getdof method can be processed back | |
157 % to an m-file. | |
158 % | |
159 % </SyntaxDescription> | |
160 | |
161 % <SyntaxCode> | |
162 try | |
163 plsp = plist('order',1,'navs',1); | |
164 rsp = psd(refdata,plsp); | |
165 pldof = plist('method','psd','DataLength',numel(refdata.y)); | |
166 out = getdof(rsp,pldof); | |
167 mout = rebuild(out); | |
168 stest = true; | |
169 catch err | |
170 disp(err.message) | |
171 stest = false; | |
172 end | |
173 % </SyntaxCode> | |
174 | |
175 % <AlgoDescription> | |
176 % | |
177 % 1) Check that the last entry in the history of 'out' corresponds to | |
178 % 'getdof'. | |
179 % 2) Check that the re-built object is the same object as 'out'. | |
180 % | |
181 % </AlgoDescription> | |
182 | |
183 % <AlgoCode> | |
184 atest = true; | |
185 if stest | |
186 % Check the last step in the history of 'out' | |
187 if ~strcmp(out.hist.methodInfo.mname, 'getdof'), atest = false; end | |
188 % Check the re-built object | |
189 if ~eq(mout, out, ple2), atest = false; end | |
190 else | |
191 atest = false; | |
192 end | |
193 % </AlgoCode> | |
194 | |
195 % Return a result structure | |
196 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
197 end % END UTP_06 | |
198 | |
199 %% UTP_07 | |
200 | |
201 % <TestDescription> | |
202 % | |
203 % Tests that the getdof method provides correct values for spectra | |
204 % degrees of freedom. | |
205 % Rreference on D B Percival and A T Walden, Spectral Analysis for | |
206 % Physical Applications, pg. 293 | |
207 % | |
208 % </TestDescription> | |
209 function result = utp_07 | |
210 | |
211 % <SyntaxDescription> | |
212 % | |
213 % Test that the applying psd works on a single AO. | |
214 % | |
215 % </SyntaxDescription> | |
216 | |
217 % <SyntaxCode> | |
218 try | |
219 dofs = zeros(numel(rolap),1); | |
220 for jj=1:numel(rolap) | |
221 plsp = plist('win','Hanning','order',1,'nfft',64,'olap',rolap(jj)); | |
222 axx = psd(refdata,plsp); | |
223 | |
224 df = getdof(axx,plist('method','psd','DataLength',numel(refdata.y))); | |
225 dofs(jj) = df.y; | |
226 end | |
227 | |
228 stest = true; | |
229 catch err | |
230 disp(err.message) | |
231 stest = false; | |
232 end | |
233 % </SyntaxCode> | |
234 | |
235 % <AlgoDescription> | |
236 % | |
237 % 1) Check that output agrees with the reference values. | |
238 % | |
239 % </AlgoDescription> | |
240 | |
241 % <AlgoCode> | |
242 atest = true; | |
243 TOL = eps; | |
244 | |
245 if stest | |
246 if ~isequal(dofs, rdof) || any((abs(dofs - rdof) ./ rdof) >= TOL) | |
247 atest = false; | |
248 end | |
249 else | |
250 atest = false; | |
251 end | |
252 % </AlgoCode> | |
253 | |
254 % Return a result structure | |
255 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
256 end % END UTP_07 | |
257 | |
258 | |
259 | |
260 | |
261 end |