Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_export.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_EXPORT a set of UTPs for the ao/export method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_export.m,v 1.4 2011/04/18 16:57:44 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The export method of the ao class export an analysis object data to a | |
11 % text file. This is a very simple method which accepts only one parfrac as | |
12 % input thus are the most general units test not possible. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_ao_export(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'ao'; | |
23 mthd = 'export'; | |
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 % Run the tests | |
34 results = [results utp_01]; % getInfo call | |
35 results = [results utp_02]; % Test with non complex data | |
36 results = [results utp_03]; % Test with complex data | |
37 results = [results utp_04]; % List with plist(filename) | |
38 | |
39 disp('Done.'); | |
40 disp('******************************************************'); | |
41 | |
42 elseif nargin == 1 % Check for UTP functions | |
43 if strcmp(varargin{1}, 'isutp') | |
44 results = 1; | |
45 else | |
46 results = 0; | |
47 end | |
48 else | |
49 error('### Incorrect inputs') | |
50 end | |
51 | |
52 %% UTP_01 | |
53 | |
54 % <TestDescription> | |
55 % | |
56 % Tests that the getInfo call works for this method. | |
57 % | |
58 % </TestDescription> | |
59 function result = utp_01 | |
60 | |
61 | |
62 % <SyntaxDescription> | |
63 % | |
64 % Test that the getInfo call works for no sets, all sets, and each set | |
65 % individually. | |
66 % | |
67 % </SyntaxDescription> | |
68 | |
69 try | |
70 % <SyntaxCode> | |
71 % Call for no sets | |
72 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
73 % Call for all sets | |
74 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
75 % Call for each set | |
76 for kk=1:numel(io(2).sets) | |
77 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
78 end | |
79 % </SyntaxCode> | |
80 stest = true; | |
81 catch err | |
82 disp(err.message) | |
83 stest = false; | |
84 end | |
85 | |
86 % <AlgoDescription> | |
87 % | |
88 % 1) Check that getInfo call returned an minfo object in all cases. | |
89 % 2) Check that all plists have the correct parameters. | |
90 % | |
91 % </AlgoDescription> | |
92 | |
93 atest = true; | |
94 if stest | |
95 % <AlgoCode> | |
96 % check we have minfo objects | |
97 if isa(io, 'minfo') | |
98 %%% SET 'None' | |
99 if ~isempty(io(1).sets), atest = false; end | |
100 if ~isempty(io(1).plists), atest = false; end | |
101 %%% Check all Sets | |
102 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
103 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
104 %%%%%%%%%% SET 'Default' | |
105 if io(3).plists.nparams ~= 2, atest = false; end | |
106 % Check key | |
107 if ~io(3).plists.isparam('filename'), atest = false; end | |
108 if ~io(3).plists.isparam('complex format'), atest = false; end | |
109 % Check default value | |
110 if ~isEmptyChar(io(3).plists.find('filename')), atest = false; end | |
111 if ~isequal(io(3).plists.find('complex format'), 'realimag'), atest = false; end | |
112 % Check options | |
113 if ~isequal(io(3).plists.getOptionsForParam('filename'), {''}), atest = false; end | |
114 if ~isequal(io(3).plists.getOptionsForParam('complex format'), {'absdeg', 'realimag', 'absrad'}), atest = false; end | |
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 export method works with non complex data in the AO. | |
130 % | |
131 % </TestDescription> | |
132 function result = utp_02 | |
133 | |
134 % <SyntaxDescription> | |
135 % | |
136 % Tests that the export method works with non complex data in the AO. | |
137 % | |
138 % </SyntaxDescription> | |
139 | |
140 try | |
141 % <SyntaxCode> | |
142 plts = plist('fs', '1', 'nsecs', 30, 'tsfcn', 'randn(size(t))'); | |
143 plfs = plist('f', '1:30', 'fsfcn', 'randn(size(f))'); | |
144 plxy = plist('x', '1:30', 'xyfcn', 'randn(size(x))'); | |
145 fn1 = ('at1.txt'); | |
146 fn2 = ('at2.txt'); | |
147 fn3 = ('at3.txt'); | |
148 at1 = ao(plts); | |
149 at2 = ao(plfs); | |
150 at3 = ao(plxy); | |
151 | |
152 export(at1, fn1); | |
153 export(at2, fn2); | |
154 export(at3, fn3); | |
155 % </SyntaxCode> | |
156 stest = true; | |
157 catch err | |
158 disp(err.message) | |
159 stest = false; | |
160 end | |
161 | |
162 % <AlgoDescription> | |
163 % | |
164 % 1) Check that the file exist. | |
165 % 2) Check that the read data is the same as the saved data. | |
166 % | |
167 % </AlgoDescription> | |
168 | |
169 atest = true; | |
170 if stest | |
171 % <AlgoCode> | |
172 % Check that the file exist | |
173 if exist(fn1, 'file') ~= 2, atest = false; end | |
174 if exist(fn2, 'file') ~= 2, atest = false; end | |
175 if exist(fn3, 'file') ~= 2, atest = false; end | |
176 % Check that the read data is the same as the saved data | |
177 a1 = ao(fn1, plist('type', 'tsdata', 'columns', [1 2])); | |
178 a2 = ao(fn2, plist('type', 'fsdata', 'columns', [1 2])); | |
179 a3 = ao(fn3, plist('type', 'xydata', 'columns', [1 2])); | |
180 if ~isequal(at1.x, a1.x), atest = false; end | |
181 if ~isequal(at1.y, a1.y), atest = false; end | |
182 if ~isequal(at2.x, a2.x), atest = false; end | |
183 if ~isequal(at2.y, a2.y), atest = false; end | |
184 if ~isequal(at3.x, a3.x), atest = false; end | |
185 if ~isequal(at3.y, a3.y), atest = false; end | |
186 % </AlgoCode> | |
187 delete(fn1); | |
188 delete(fn2); | |
189 delete(fn3); | |
190 else | |
191 atest = false; | |
192 end | |
193 | |
194 % Return a result structure | |
195 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
196 end % END UTP_02 | |
197 | |
198 %% UTP_03 | |
199 | |
200 % <TestDescription> | |
201 % | |
202 % Tests that the export method works with complex data in the AO. | |
203 % | |
204 % </TestDescription> | |
205 function result = utp_03 | |
206 | |
207 % <SyntaxDescription> | |
208 % | |
209 % Tests that the export method works with complex data in the AO. | |
210 % | |
211 % </SyntaxDescription> | |
212 | |
213 try | |
214 % <SyntaxCode> | |
215 plts = plist('fs', '1', 'nsecs', 30, 'tsfcn', 'randn(size(t)) + randn(size(t))*i'); | |
216 plfs = plist('f', '1:30', 'fsfcn', 'randn(size(f)) + randn(size(f))*i'); | |
217 plxy = plist('x', '1:30', 'xyfcn', 'randn(size(x)) + randn(size(x))*i'); | |
218 fn1 = ('at1.txt'); | |
219 fn2 = ('at2.txt'); | |
220 fn3 = ('at3.txt'); | |
221 at1 = ao(plts); | |
222 at2 = ao(plfs); | |
223 at3 = ao(plxy); | |
224 | |
225 export(at1, fn1); | |
226 export(at2, fn2); | |
227 export(at3, fn3); | |
228 % </SyntaxCode> | |
229 stest = true; | |
230 catch err | |
231 disp(err.message) | |
232 stest = false; | |
233 end | |
234 | |
235 % <AlgoDescription> | |
236 % | |
237 % 1) Check that the file exist. | |
238 % 2) Check that the read data is the same as the saved data. | |
239 % | |
240 % </AlgoDescription> | |
241 | |
242 atest = true; | |
243 if stest | |
244 % <AlgoCode> | |
245 % Check that the file exist | |
246 if exist(fn1, 'file') ~= 2, atest = false; end | |
247 if exist(fn2, 'file') ~= 2, atest = false; end | |
248 if exist(fn3, 'file') ~= 2, atest = false; end | |
249 % Check that the read data is the same as the saved data | |
250 a1r = ao(fn1, plist('type', 'tsdata', 'columns', [1 2])); | |
251 a1c = ao(fn1, plist('type', 'tsdata', 'columns', [1 3])); | |
252 a2r = ao(fn2, plist('type', 'fsdata', 'columns', [1 2])); | |
253 a2c = ao(fn2, plist('type', 'fsdata', 'columns', [1 3])); | |
254 a3r = ao(fn3, plist('type', 'xydata', 'columns', [1 2])); | |
255 a3c = ao(fn3, plist('type', 'xydata', 'columns', [1 3])); | |
256 a1 = complex(a1r, a1c); | |
257 a2 = complex(a2r, a2c); | |
258 a3 = complex(a3r, a3c); | |
259 if ~isequal(at1.x, a1.x), atest = false; end | |
260 if ~isequal(at1.y, a1.y), atest = false; end | |
261 if ~isequal(at2.x, a2.x), atest = false; end | |
262 if ~isequal(at2.y, a2.y), atest = false; end | |
263 if ~isequal(at3.x, a3.x), atest = false; end | |
264 if ~isequal(at3.y, a3.y), atest = false; end | |
265 % </AlgoCode> | |
266 delete(fn1); | |
267 delete(fn2); | |
268 delete(fn3); | |
269 else | |
270 atest = false; | |
271 end | |
272 | |
273 % Return a result structure | |
274 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
275 end % END UTP_03 | |
276 | |
277 %% UTP_04 | |
278 | |
279 % <TestDescription> | |
280 % | |
281 % Tests that the export method works with a plist which contains the filename. | |
282 % | |
283 % </TestDescription> | |
284 function result = utp_04 | |
285 | |
286 % <SyntaxDescription> | |
287 % | |
288 % Tests that the export method works with a plist which contains the | |
289 % filename. | |
290 % | |
291 % </SyntaxDescription> | |
292 | |
293 try | |
294 % <SyntaxCode> | |
295 plts = plist('fs', '1', 'nsecs', 30, 'tsfcn', 'randn(size(t)) + randn(size(t))*i'); | |
296 plfs = plist('f', '1:30', 'fsfcn', 'randn(size(f))'); | |
297 fn1 = ('at1.txt'); | |
298 fn2 = ('at2.txt'); | |
299 at1 = ao(plts); | |
300 at2 = ao(plfs); | |
301 | |
302 export(at1, plist('filename', fn1)); | |
303 export(at2, plist('filename', fn2)); | |
304 % </SyntaxCode> | |
305 stest = true; | |
306 catch err | |
307 disp(err.message) | |
308 stest = false; | |
309 end | |
310 | |
311 % <AlgoDescription> | |
312 % | |
313 % 1) Check that the file exist. | |
314 % 2) Check that the read data is the same as the saved data. | |
315 % | |
316 % </AlgoDescription> | |
317 | |
318 atest = true; | |
319 if stest | |
320 % <AlgoCode> | |
321 % Check that the file exist | |
322 if exist(fn1, 'file') ~= 2, atest = false; end | |
323 if exist(fn2, 'file') ~= 2, atest = false; end | |
324 % Check that the read data is the same as the saved data | |
325 a1r = ao(fn1, plist('type', 'tsdata', 'columns', [1 2])); | |
326 a1c = ao(fn1, plist('type', 'tsdata', 'columns', [1 3])); | |
327 a2 = ao(fn2, plist('type', 'fsdata', 'columns', [1 2])); | |
328 a1 = complex(a1r, a1c); | |
329 if ~isequal(at1.x, a1.x), atest = false; end | |
330 if ~isequal(at1.y, a1.y), atest = false; end | |
331 if ~isequal(at2.x, a2.x), atest = false; end | |
332 if ~isequal(at2.y, a2.y), atest = false; end | |
333 % </AlgoCode> | |
334 delete(fn1); | |
335 delete(fn2); | |
336 else | |
337 atest = false; | |
338 end | |
339 | |
340 % Return a result structure | |
341 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
342 end % END UTP_04 | |
343 | |
344 end |