Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_yunits.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_YUNITS a set of UTPs for the ao/yunits method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_yunits.m,v 1.5 2011/04/05 04:29:44 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The yunits method of the ao class is a get-function to get the yunits values | |
11 % of the data object | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_yunits(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'yunits'; | |
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 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Run the tests | |
36 results = [results utp_01]; % getInfo call | |
37 results = [results utp_02]; % Vector input | |
38 results = [results utp_03]; % Matrix input | |
39 results = [results utp_04]; % List input | |
40 results = [results utp_05]; % Test with mixed input | |
41 results = [results utp_06]; % Test history is working | |
42 results = [results utp_07]; % Test with all data objects | |
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 try | |
75 % <SyntaxCode> | |
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 % </SyntaxCode> | |
85 stest = true; | |
86 catch err | |
87 disp(err.message) | |
88 stest = false; | |
89 end | |
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 atest = true; | |
99 if stest | |
100 % <AlgoCode> | |
101 % check we have minfo objects | |
102 if isa(io, 'minfo') | |
103 % SET 'None' | |
104 if ~isempty(io(1).sets), atest = false; end | |
105 if ~isempty(io(1).plists), atest = false; end | |
106 % Check all Sets | |
107 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
108 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
109 % SET 'Default' | |
110 if io(3).plists.nparams ~= 0, atest = false; end | |
111 % Check key | |
112 % Check default value | |
113 % Check options | |
114 end | |
115 % </AlgoCode> | |
116 else | |
117 atest = false; | |
118 end | |
119 | |
120 % Return a result structure | |
121 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
122 end % END UTP_01 | |
123 | |
124 %% UTP_02 | |
125 | |
126 % <TestDescription> | |
127 % | |
128 % Tests that the yunits method works with a vector of AOs as input. | |
129 % | |
130 % </TestDescription> | |
131 function result = utp_02 | |
132 | |
133 % <SyntaxDescription> | |
134 % | |
135 % Tests that the yunits method works with a vector of AOs as input. | |
136 % | |
137 % </SyntaxDescription> | |
138 | |
139 try | |
140 % <SyntaxCode> | |
141 avec = [at1 at2 at5 at6]; | |
142 % Vector output | |
143 out = yunits(avec); | |
144 % List output | |
145 [out1, out2, out3, out4] = yunits(avec); | |
146 % </SyntaxCode> | |
147 stest = true; | |
148 catch err | |
149 disp(err.message) | |
150 stest = false; | |
151 end | |
152 | |
153 % <AlgoDescription> | |
154 % | |
155 % 1) Check that the number of elements in 'out' is the same as in the input. | |
156 % 2) Check that each output unit object contains the correct values. | |
157 % | |
158 % </AlgoDescription> | |
159 | |
160 atest = true; | |
161 if stest | |
162 % <AlgoCode> | |
163 % Check we have the correct number of outputs | |
164 if numel(out) ~= numel(avec), atest = false; end | |
165 % Check we have the correct values in the outputs | |
166 % Vector output | |
167 for kk = 1:numel(out) | |
168 if ~eq(out(kk), avec(kk).data.yunits), atest = false; end | |
169 end | |
170 % List output | |
171 if ~eq(out1, avec(1).data.yunits), atest = false; end | |
172 if ~eq(out2, avec(2).data.yunits), atest = false; end | |
173 if ~eq(out3, avec(3).data.yunits), atest = false; end | |
174 if ~eq(out4, avec(4).data.yunits), atest = false; end | |
175 % </AlgoCode> | |
176 else | |
177 atest = false; | |
178 end | |
179 | |
180 % Return a result structure | |
181 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
182 end % END UTP_02 | |
183 | |
184 %% UTP_03 | |
185 | |
186 % <TestDescription> | |
187 % | |
188 % Tests that the yunits method works with a matrix of AOs as input. | |
189 % | |
190 % </TestDescription> | |
191 function result = utp_03 | |
192 | |
193 % <SyntaxDescription> | |
194 % | |
195 % Tests that the yunits method works with a matrix of AOs as input. | |
196 % | |
197 % </SyntaxDescription> | |
198 | |
199 try | |
200 % <SyntaxCode> | |
201 amat = [at1 at5 at6; at5 at6 at1]; | |
202 % Vector output | |
203 out = yunits(amat); | |
204 % List output | |
205 [out1, out2, out3, out4, out5, out6] = yunits(amat); | |
206 % </SyntaxCode> | |
207 stest = true; | |
208 catch err | |
209 disp(err.message) | |
210 stest = false; | |
211 end | |
212 | |
213 % <AlgoDescription> | |
214 % | |
215 % 1) Check that the number of elements in 'out' is the same as in the input. | |
216 % 2) Check that each output unit object contains the correct values. | |
217 % | |
218 % </AlgoDescription> | |
219 | |
220 atest = true; | |
221 if stest | |
222 % <AlgoCode> | |
223 % Check we have the correct number of outputs | |
224 if numel(out) ~= numel(amat), atest = false; end | |
225 % Check we have the correct values in the outputs | |
226 % Vector output | |
227 for kk = 1:numel(out) | |
228 if ~eq(out(kk), amat(kk).data.yunits), atest = false; end | |
229 end | |
230 % List output | |
231 if ~eq(out1, amat(1).data.yunits), atest = false; end | |
232 if ~eq(out2, amat(2).data.yunits), atest = false; end | |
233 if ~eq(out3, amat(3).data.yunits), atest = false; end | |
234 if ~eq(out4, amat(4).data.yunits), atest = false; end | |
235 if ~eq(out5, amat(5).data.yunits), atest = false; end | |
236 if ~eq(out6, amat(6).data.yunits), atest = false; end | |
237 % </AlgoCode> | |
238 else | |
239 atest = false; | |
240 end | |
241 | |
242 % Return a result structure | |
243 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
244 end % END UTP_03 | |
245 | |
246 %% UTP_04 | |
247 | |
248 % <TestDescription> | |
249 % | |
250 % Tests that the yunits method works with a list of AOs as input. | |
251 % | |
252 % </TestDescription> | |
253 function result = utp_04 | |
254 | |
255 % <SyntaxDescription> | |
256 % | |
257 % Tests that the yunits method works with a list of AOs as input. | |
258 % | |
259 % </SyntaxDescription> | |
260 | |
261 try | |
262 % <SyntaxCode> | |
263 % Vector output | |
264 out = yunits(at3, at4, at5, at6); | |
265 % List output | |
266 [out1, out2, out3, out4] = yunits(at3, at4, at5, at6); | |
267 % </SyntaxCode> | |
268 stest = true; | |
269 catch err | |
270 disp(err.message) | |
271 stest = false; | |
272 end | |
273 | |
274 % <AlgoDescription> | |
275 % | |
276 % 1) Check that the number of elements in 'out' is the same as in the input. | |
277 % 2) Check that each output unit object contains the correct values. | |
278 % | |
279 % </AlgoDescription> | |
280 | |
281 atest = true; | |
282 if stest | |
283 % <AlgoCode> | |
284 % Check we have the correct number of outputs | |
285 if numel(out) ~= 4, atest = false; end | |
286 % Check we have the correct values in the outputs | |
287 % Vector output | |
288 if ~eq(out(1), at3.data.yunits), atest = false; end | |
289 if ~eq(out1, at3.data.yunits), atest = false; end | |
290 if ~eq(out(2), at4.data.yunits), atest = false; end | |
291 if ~eq(out2, at4.data.yunits), atest = false; end | |
292 % List output | |
293 if ~eq(out(3), at5.data.yunits), atest = false; end | |
294 if ~eq(out3, at5.data.yunits), atest = false; end | |
295 if ~eq(out(4), at6.data.yunits), atest = false; end | |
296 if ~eq(out4, at6.data.yunits), atest = false; end | |
297 % </AlgoCode> | |
298 else | |
299 atest = false; | |
300 end | |
301 | |
302 % Return a result structure | |
303 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
304 end % END UTP_04 | |
305 | |
306 %% UTP_05 | |
307 | |
308 % <TestDescription> | |
309 % | |
310 % Tests that the yunits method works with a mix of different shaped AOs as | |
311 % input. | |
312 % | |
313 % </TestDescription> | |
314 function result = utp_05 | |
315 | |
316 % <SyntaxDescription> | |
317 % | |
318 % Tests that the yunits method works with a mix of different shaped AOs as | |
319 % input. | |
320 % | |
321 % </SyntaxDescription> | |
322 | |
323 try | |
324 % <SyntaxCode> | |
325 % Vector output | |
326 out = yunits(at1,[at4 at6],at5,[at5 at1; at6 at1],at6); | |
327 % List output | |
328 [out1, out2, out3, out4, out5, out6, out7, out8, out9] = ... | |
329 yunits(at1,[at4 at6],at5,[at5 at1; at6 at1],at6); | |
330 % </SyntaxCode> | |
331 stest = true; | |
332 catch err | |
333 disp(err.message) | |
334 stest = false; | |
335 end | |
336 | |
337 % <AlgoDescription> | |
338 % | |
339 % 1) Check that the number of elements in 'out' is the same as in the input. | |
340 % 2) Check that each output unit object contains the correct values. | |
341 % | |
342 % </AlgoDescription> | |
343 | |
344 atest = true; | |
345 if stest | |
346 % <AlgoCode> | |
347 % Check we have the correct number of outputs | |
348 if numel(out) ~= 9, atest = false; end | |
349 % Check we have the correct values in the outputs | |
350 % Vector output | |
351 if ~eq(out(1), at1.data.yunits), atest = false; end | |
352 if ~eq(out(2), at4.data.yunits), atest = false; end | |
353 if ~eq(out(3), at6.data.yunits), atest = false; end | |
354 if ~eq(out(4), at5.data.yunits), atest = false; end | |
355 if ~eq(out(5), at5.data.yunits), atest = false; end | |
356 if ~eq(out(6), at6.data.yunits), atest = false; end | |
357 if ~eq(out(7), at1.data.yunits), atest = false; end | |
358 if ~eq(out(8), at1.data.yunits), atest = false; end | |
359 if ~eq(out(9), at6.data.yunits), atest = false; end | |
360 % List output | |
361 if ~eq(out1, at1.data.yunits), atest = false; end | |
362 if ~eq(out2, at4.data.yunits), atest = false; end | |
363 if ~eq(out3, at6.data.yunits), atest = false; end | |
364 if ~eq(out4, at5.data.yunits), atest = false; end | |
365 if ~eq(out5, at5.data.yunits), atest = false; end | |
366 if ~eq(out6, at6.data.yunits), atest = false; end | |
367 if ~eq(out7, at1.data.yunits), atest = false; end | |
368 if ~eq(out8, at1.data.yunits), atest = false; end | |
369 if ~eq(out9, at6.data.yunits), atest = false; end | |
370 % </AlgoCode> | |
371 else | |
372 atest = false; | |
373 end | |
374 | |
375 % Return a result structure | |
376 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
377 end % END UTP_05 | |
378 | |
379 %% UTP_06 | |
380 | |
381 % <TestDescription> | |
382 % | |
383 % Tests that the yunits method properly applies history. | |
384 % | |
385 % </TestDescription> | |
386 function result = utp_06 | |
387 | |
388 % <SyntaxDescription> | |
389 % | |
390 % The yunits method doesn't change the AO, thus will no history added. | |
391 % Nothing to do | |
392 % | |
393 % </SyntaxDescription> | |
394 | |
395 try | |
396 % <SyntaxCode> | |
397 % </SyntaxCode> | |
398 stest = true; | |
399 catch err | |
400 disp(err.message) | |
401 stest = false; | |
402 end | |
403 | |
404 % <AlgoDescription> | |
405 % | |
406 % </AlgoDescription> | |
407 | |
408 atest = true; | |
409 if stest | |
410 % <AlgoCode> | |
411 % </AlgoCode> | |
412 else | |
413 atest = false; | |
414 end | |
415 | |
416 % Return a result structure | |
417 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
418 end % END UTP_06 | |
419 | |
420 %% UTP_07 | |
421 | |
422 % <TestDescription> | |
423 % | |
424 % Tests that the yunits method works for AOs with different data objects. | |
425 % | |
426 % </TestDescription> | |
427 function result = utp_07 | |
428 | |
429 % <SyntaxDescription> | |
430 % | |
431 % Test that the yunits method returns the yunits values for AOs with cdata, | |
432 % fsdata, tsdata and xydata objects. | |
433 % | |
434 % </SyntaxDescription> | |
435 | |
436 try | |
437 % <SyntaxCode> | |
438 at4.setYunits('Hz s^-1'); | |
439 u1 = at1.yunits; | |
440 u2 = at2.yunits; | |
441 u3 = at3.yunits; | |
442 u4 = at4.yunits; | |
443 % </SyntaxCode> | |
444 stest = true; | |
445 catch err | |
446 disp(err.message) | |
447 stest = false; | |
448 end | |
449 | |
450 % <AlgoDescription> | |
451 % | |
452 % 1) Check the output. | |
453 % | |
454 % </AlgoDescription> | |
455 | |
456 atest = true; | |
457 if stest | |
458 % <AlgoCode> | |
459 if ~eq(u1, at1.data.yunits), atest = false; end; | |
460 if ~eq(u2, at2.data.yunits), atest = false; end; | |
461 if ~eq(u3, at3.data.yunits), atest = false; end; | |
462 if ~eq(u4, at4.data.yunits), atest = false; end; | |
463 % </AlgoCode> | |
464 else | |
465 atest = false; | |
466 end | |
467 | |
468 % Return a result structure | |
469 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
470 end % END UTP_07 | |
471 | |
472 end |