Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_compute.m @ 45:a59cdb8aaf31 database-connection-manager
Merge
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 19:07:22 +0100 |
parents | 409a22968d5e |
children |
comparison
equal
deleted
inserted
replaced
42:f90d4f666cc7 | 45:a59cdb8aaf31 |
---|---|
1 % UTP_AO_COMPUTE a set of UTPs for the ao/compute method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_compute.m,v 1.7 2010/06/07 16:43:06 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The compute method of the ao class applies the user-specified | |
11 % calculations to the input AOs. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_compute(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'compute'; | |
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 | |
43 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear | |
44 | |
45 disp('Done.'); | |
46 disp('******************************************************'); | |
47 | |
48 elseif nargin == 1 % Check for UTP functions | |
49 if strcmp(varargin{1}, 'isutp') | |
50 results = 1; | |
51 else | |
52 results = 0; | |
53 end | |
54 else | |
55 error('### Incorrect inputs') | |
56 end | |
57 | |
58 %% UTP_01 | |
59 | |
60 % <TestDescription> | |
61 % | |
62 % Tests that the getInfo call works for this method. | |
63 % | |
64 % </TestDescription> | |
65 function result = utp_01 | |
66 | |
67 | |
68 % <SyntaxDescription> | |
69 % | |
70 % Test that the getInfo call works for no sets, all sets, and each set | |
71 % individually. | |
72 % | |
73 % </SyntaxDescription> | |
74 | |
75 try | |
76 % <SyntaxCode> | |
77 % Call for no sets | |
78 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
79 % Call for all sets | |
80 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
81 % Call for each set | |
82 for kk=1:numel(io(2).sets) | |
83 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
84 end | |
85 % </SyntaxCode> | |
86 stest = true; | |
87 catch err | |
88 disp(err.message) | |
89 stest = false; | |
90 end | |
91 | |
92 % <AlgoDescription> | |
93 % | |
94 % 1) Check that getInfo call returned an minfo object in all cases. | |
95 % 2) Check that all plists have the correct parameters. | |
96 % | |
97 % </AlgoDescription> | |
98 | |
99 atest = true; | |
100 if stest | |
101 % <AlgoCode> | |
102 % check we have minfo objects | |
103 if isa(io, 'minfo') | |
104 % SET 'None' | |
105 if ~isempty(io(1).sets), atest = false; end | |
106 if ~isempty(io(1).plists), atest = false; end | |
107 % Check all Sets | |
108 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
109 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
110 % SET 'Default' | |
111 % Check key | |
112 if ~io(3).plists.isparam('operations'), atest = false; end | |
113 % Check default value | |
114 if ~isequal(io(3).plists.find('operations'), 'a'), atest = false; end | |
115 % Check options | |
116 if ~isequal(io(3).plists.getOptionsForParam('operations'), {'a'}), atest = false; end | |
117 end | |
118 % </AlgoCode> | |
119 else | |
120 atest = false; | |
121 end | |
122 | |
123 % Return a result structure | |
124 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
125 end % END UTP_01 | |
126 | |
127 %% UTP_02 | |
128 | |
129 % <TestDescription> | |
130 % | |
131 % Tests that the complex method works with a vector of AOs as input. | |
132 % | |
133 % </TestDescription> | |
134 function result = utp_02 | |
135 | |
136 % <SyntaxDescription> | |
137 % | |
138 % Test that the complex method works for a vector of AOs as input. | |
139 % | |
140 % </SyntaxDescription> | |
141 | |
142 try | |
143 % <SyntaxCode> | |
144 out = compute([at1 at1], 'a(1)./a(2)'); | |
145 stest = true; | |
146 % </SyntaxCode> | |
147 catch err | |
148 disp(err.message) | |
149 stest = false; | |
150 end | |
151 | |
152 % <AlgoDescription> | |
153 % | |
154 % 1) Check that the number of elements in 'out' is 1. | |
155 % 2) Check that each output AO contains the correct data. | |
156 % | |
157 % </AlgoDescription> | |
158 | |
159 atest = true; | |
160 if stest | |
161 % <AlgoCode> | |
162 % Check we have the correct number of outputs | |
163 if numel(out) ~= 1, atest = false; end | |
164 % Check each output against the expected operations | |
165 if ne(out, at1./at1, ple1), atest = false; end | |
166 % </AlgoCode> | |
167 else | |
168 atest = false; | |
169 end | |
170 | |
171 % Return a result structure | |
172 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
173 end % END UTP_02 | |
174 | |
175 %% UTP_03 | |
176 | |
177 % <TestDescription> | |
178 % | |
179 % Tests that the compute method works with a matrix of AOs as input. | |
180 % | |
181 % </TestDescription> | |
182 function result = utp_03 | |
183 | |
184 % <SyntaxDescription> | |
185 % | |
186 % Test that the compute method works for a matrix of AOs as input. | |
187 % | |
188 % </SyntaxDescription> | |
189 | |
190 try | |
191 % <SyntaxCode> | |
192 a = [at1 at1 at5; at1 at6 at4]; | |
193 out = compute(a, {'1.23 + a(1,3)./a(2,2)', 'log10(a(2,1))'}); | |
194 % </SyntaxCode> | |
195 stest = true; | |
196 catch err | |
197 disp(err.message) | |
198 stest = false; | |
199 end | |
200 | |
201 % <AlgoDescription> | |
202 % | |
203 % 1) Check that the number of elements in 'out' is 2. | |
204 % 2) Check that each output AO contains the correct data. | |
205 % | |
206 % </AlgoDescription> | |
207 | |
208 atest = true; | |
209 if stest | |
210 % <AlgoCode> | |
211 % Check we have the correct number of outputs | |
212 if numel(out) ~= 2, atest = false; end | |
213 % Check each output against the expected operations | |
214 if ne(out(1), 1.23 + a(1,3)./a(2,2), ple1), atest = false; end | |
215 if ne(out(2), log10(a(2,1)), ple1), atest = false; end | |
216 % </AlgoCode> | |
217 else | |
218 atest = false; | |
219 end | |
220 | |
221 % Return a result structure | |
222 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
223 end % END UTP_03 | |
224 | |
225 %% UTP_04 | |
226 | |
227 % <TestDescription> | |
228 % | |
229 % Tests that the compute method works with a list of AOs as input. | |
230 % | |
231 % </TestDescription> | |
232 function result = utp_04 | |
233 | |
234 % <SyntaxDescription> | |
235 % | |
236 % Test that the compute method works for a list of AOs as input. | |
237 % | |
238 % </SyntaxDescription> | |
239 | |
240 try | |
241 % <SyntaxCode> | |
242 out = compute(at1, at1, plist('Operations', {'a(1)./a(2)', 'a(1)-a(2)'})); | |
243 % </SyntaxCode> | |
244 stest = true; | |
245 catch err | |
246 disp(err.message) | |
247 stest = false; | |
248 end | |
249 | |
250 % <AlgoDescription> | |
251 % | |
252 % 1) Check that the number of elements in 'out' is 2. | |
253 % 2) Check that each output AO contains the correct data. | |
254 % | |
255 % </AlgoDescription> | |
256 | |
257 atest = true; | |
258 if stest | |
259 % <AlgoCode> | |
260 % Check we have the correct number of outputs | |
261 if numel(out) ~= 2, atest = false; end | |
262 % Check each output against the expected operations | |
263 if ne(out(1), at1./at1, ple1), atest = false; end | |
264 if ne(out(2), at1-at1, ple1), atest = false; end | |
265 % </AlgoCode> | |
266 else | |
267 atest = false; | |
268 end | |
269 | |
270 % Return a result structure | |
271 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
272 end % END UTP_04 | |
273 | |
274 %% UTP_05 | |
275 | |
276 % <TestDescription> | |
277 % | |
278 % Tests that the compute method works with a mix of different shaped AOs as | |
279 % input. | |
280 % | |
281 % </TestDescription> | |
282 function result = utp_05 | |
283 | |
284 % <SyntaxDescription> | |
285 % | |
286 % Test that the compute method works with an input of matrices and vectors | |
287 % and single AOs. | |
288 % | |
289 % </SyntaxDescription> | |
290 | |
291 try | |
292 % <SyntaxCode> | |
293 out = compute(at1,[at3 at1],at2,[at1 at2; at1 at3], plist('Operations', {'a(1)./a(3)', 'a(5)-a(6)'})); | |
294 % </SyntaxCode> | |
295 stest = true; | |
296 catch err | |
297 disp(err.message) | |
298 stest = false; | |
299 end | |
300 | |
301 % <AlgoDescription> | |
302 % | |
303 % 1) Check that the number of elements in 'out' is 2. | |
304 % 2) Check that each output AO contains the correct data. | |
305 % | |
306 % </AlgoDescription> | |
307 | |
308 atest = true; | |
309 if stest | |
310 % <AlgoCode> | |
311 % Check we have the correct number of outputs | |
312 if numel(out) ~= 2, atest = false; end | |
313 % Check each output against the expected operations | |
314 if ne(out(1), at1./at1, ple1), atest = false; end | |
315 if ne(out(2), at1-at1, ple1), atest = false; end | |
316 % </AlgoCode> | |
317 else | |
318 atest = false; | |
319 end | |
320 | |
321 % Return a result structure | |
322 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
323 end % END UTP_05 | |
324 | |
325 %% UTP_06 | |
326 | |
327 % <TestDescription> | |
328 % | |
329 % Tests that the compute method applies no history. | |
330 % | |
331 % </TestDescription> | |
332 function result = utp_06 | |
333 | |
334 % <SyntaxDescription> | |
335 % | |
336 % Test that the result of applying the compute method can be processed back | |
337 % to an m-file. | |
338 % | |
339 % </SyntaxDescription> | |
340 | |
341 try | |
342 % <SyntaxCode> | |
343 out = compute(at1, [at2 at1], plist('Operations', 'a(1)./a(3)')); | |
344 mout = rebuild(out); | |
345 % </SyntaxCode> | |
346 stest = true; | |
347 catch err | |
348 disp(err.message) | |
349 stest = false; | |
350 end | |
351 | |
352 % <AlgoDescription> | |
353 % | |
354 % 1) Check that the last entry in the history of 'out' is not | |
355 % 'compute'. | |
356 % 2) Check that the rebuilt object is the same as 'out'. | |
357 % | |
358 % </AlgoDescription> | |
359 | |
360 atest = true; | |
361 if stest | |
362 % <AlgoCode> | |
363 % Check the last step in the history of 'out' | |
364 if strcmp(out.hist.methodInfo.mname, 'compute'), atest = false; end | |
365 % Check the rebuilt object | |
366 if ~eq(mout, out, ple2), atest = false; end | |
367 % </AlgoCode> | |
368 else | |
369 atest = false; | |
370 end | |
371 | |
372 % Return a result structure | |
373 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
374 end % END UTP_06 | |
375 | |
376 end |