comparison testing/utp_1.1/utps/ao/utp_ao_ecdf.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_ECDF a set of UTPs for the ao/ecdf method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_ecdf.m,v 1.1 2011/07/08 13:13:59 luigi Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The ifft method of the ao class computes the inverse fast fourier
11 % transform of time-series AOs.
12 %
13 % </MethodDescription>
14
15 function results = utp_ao_ecdf(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'ao';
22 mthd = 'ecdf';
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 the modify call does not work
43 results = [results utp_09]; % Test output of the data
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 if io(3).plists.nparams ~= 0, atest = false; end
112
113 end
114 % </AlgoCode>
115 else
116 atest = false;
117 end
118
119 % Return a result structure
120 result = utp_prepare_result(atest, stest, dbstack, mfilename);
121 end % END UTP_01
122
123 %% UTP_02
124
125 % <TestDescription>
126 %
127 % Tests that the ecdf method works with a vector of AOs as input.
128 %
129 % </TestDescription>
130 function result = utp_02
131
132 % <SyntaxDescription>
133 %
134 % Test that the ecdf method works for a vector of AOs as input.
135 %
136 % </SyntaxDescription>
137
138 try
139 % <SyntaxCode>
140 avec = [at5 at5];
141 out1 = ecdf(avec);
142 % </SyntaxCode>
143 stest = true;
144 catch err
145 disp(err.message)
146 stest = false;
147 end
148
149 % <AlgoDescription>
150 %
151 % 1) Check that the number of elements in 'out' is the same of the
152 % number in the input.
153 % 2) Check that each output AO contains the correct data.
154 %
155 % </AlgoDescription>
156
157 atest = true;
158 if stest
159 % <AlgoCode>
160 % Check we have the correct number of outputs
161 if numel(out1) ~= numel(avec), atest = false; end
162 % Check each output
163
164 % </AlgoCode>
165 else
166 atest = false;
167 end
168
169 % Return a result structure
170 result = utp_prepare_result(atest, stest, dbstack, mfilename);
171 end % END UTP_02
172
173 %% UTP_03
174
175 % <TestDescription>
176 %
177 % Tests that the ecdf method works with a matrix of AOs as input.
178 %
179 % </TestDescription>
180 function result = utp_03
181
182 % <SyntaxDescription>
183 %
184 % Test that the ecdf method works for a matrix of AOs as input.
185 %
186 % </SyntaxDescription>
187
188 try
189 % <SyntaxCode>
190 amat = [at5 at5 at5; at5 at5 at5];
191 out1 = ecdf(amat);
192 % </SyntaxCode>
193 stest = true;
194 catch err
195 disp(err.message)
196 stest = false;
197 end
198
199 % <AlgoDescription>
200 %
201 % 1) Check that the number of elements in 'out' is the square of the
202 % number in the input.
203 % 2) Check that each output AO contains the correct data.
204 %
205 % </AlgoDescription>
206
207 atest = true;
208 if stest
209 % <AlgoCode>
210 % Check we have the correct number of outputs
211 if numel(out1) ~= numel(amat), atest = false; end
212 % Check each output
213
214 % </AlgoCode>
215 else
216 atest = false;
217 end
218
219 % Return a result structure
220 result = utp_prepare_result(atest, stest, dbstack, mfilename);
221 end % END UTP_03
222
223 %% UTP_04
224
225 % <TestDescription>
226 %
227 % Tests that the ecdf method works with a list of AOs as input.
228 %
229 % </TestDescription>
230 function result = utp_04
231
232 % <SyntaxDescription>
233 %
234 % Test that the ecdf method works for a list of AOs as input.
235 %
236 % </SyntaxDescription>
237
238 try
239 % <SyntaxCode>
240 out1 = ecdf(at5, at5, at5);
241 % </SyntaxCode>
242 stest = true;
243 catch err
244 disp(err.message)
245 stest = false;
246 end
247
248 % <AlgoDescription>
249 %
250 % 1) Check that the number of elements in 'out' is the square of the
251 % number in the input.
252 % 2) Check that each output AO contains the correct data.
253 %
254 % </AlgoDescription>
255
256 atest = true;
257 if stest
258 % <AlgoCode>
259 % Check we have the correct number of outputs
260 if numel(out1) ~= 3, atest = false; end
261 % Check each output
262
263 % </AlgoCode>
264 else
265 atest = false;
266 end
267
268 % Return a result structure
269 result = utp_prepare_result(atest, stest, dbstack, mfilename);
270 end % END UTP_04
271
272 %% UTP_05
273
274 % <TestDescription>
275 %
276 % Tests that the ecdf method works with a mix of different shaped AOs as
277 % input.
278 %
279 % </TestDescription>
280 function result = utp_05
281
282 % <SyntaxDescription>
283 %
284 % Test that the ecdf method works with an input of matrices and vectors
285 % and single AOs.
286 %
287 % </SyntaxDescription>
288
289 try
290 % <SyntaxCode>
291 out1 = ecdf(at5,[at6 at6],at5,[at5 at5; at5 at5],at6);
292 % </SyntaxCode>
293 stest = true;
294 catch err
295 disp(err.message)
296 stest = false;
297 end
298
299 % <AlgoDescription>
300 %
301 % 1) Check that the number of elements in 'out' is the same as in
302 % input.
303 % 2) Check that each output AO contains the correct data.
304 %
305 % </AlgoDescription>
306
307 atest = true;
308 % aoin = [at1, reshape([at1 at1], 1, []), at1, reshape([at1 at1; at1 at1], 1, []), at1];
309 if stest
310 % <AlgoCode>
311 % Check we have the correct number of outputs
312 if numel(out1) ~= 9, atest = false; end
313 % Check each output
314
315 % </AlgoCode>
316 else
317 atest = false;
318 end
319
320 % Return a result structure
321 result = utp_prepare_result(atest, stest, dbstack, mfilename);
322 end % END UTP_05
323
324 %% UTP_06
325
326 % <TestDescription>
327 %
328 % Tests that the ecdf method properly applies history.
329 %
330 % </TestDescription>
331 function result = utp_06
332
333 % <SyntaxDescription>
334 %
335 % Test that the result of applying the ecdf method can be processed back
336 % to an m-file.
337 %
338 % </SyntaxDescription>
339
340 try
341 % <SyntaxCode>
342 out1 = ecdf(at5, at6);
343 mout1 = rebuild(out1);
344 % </SyntaxCode>
345 stest = true;
346 catch err
347 disp(err.message)
348 stest = false;
349 end
350
351 % <AlgoDescription>
352 %
353 % 1) Check that the last entry in the history of 'out' corresponds to
354 % 'ecdf'.
355 % 2) % Check that the re-built object is the same object as 'out'.
356 %
357 % </AlgoDescription>
358
359 atest = true;
360 if stest
361 % <AlgoCode>
362 % Check the last step in the history of 'out'
363 if ~strcmp(out1(1).hist.methodInfo.mname, 'ecdf'), atest = false; end
364 if ~strcmp(out1(2).hist.methodInfo.mname, 'ecdf'), atest = false; end
365 % Check the re-built object
366 if ~eq(mout1, out1, 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 %% UTP_07
377
378 % <TestDescription>
379 %
380 % Tests that the ecdf method cannot modify the input AO.
381 %
382 % </TestDescription>
383 function result = utp_07
384
385 % <SyntaxDescription>
386 %
387 % Test that the ecdf method cannot modify the input AO by calling with no
388 % output.
389 %
390 % </SyntaxDescription>
391
392 try
393 % <SyntaxCode>
394 % copy at2 to work with
395 ain1 = ao(at5);
396 % modify ain
397 ain1.ecdf;
398 % </SyntaxCode>
399 stest = false;
400 catch err
401 disp(err.message)
402 stest = true;
403 end
404
405 % <AlgoDescription>
406 %
407 %
408 % </AlgoDescription>
409
410 atest = true;
411
412
413 % Return a result structure
414 result = utp_prepare_result(atest, stest, dbstack, mfilename);
415 end % END UTP_07
416
417
418 %% UTP_09
419
420 % <TestDescription>
421 %
422 % Check that the ecdf method pass back the output objects to a list of
423 % output variables or to a single variable.
424 %
425 % </TestDescription>
426 function result = utp_09
427
428 % <SyntaxDescription>
429 %
430 % Call the method with a list of output variables and with a single output
431 % variable. Additionaly check that the rebuild method works on the output.
432 %
433 % </SyntaxDescription>
434
435 try
436 % <SyntaxCode>
437 [o11, o12] = ecdf(at5, at6);
438 no1 = ecdf(at5, at6);
439 mout11 = rebuild(o11);
440 mout12 = rebuild(o12);
441 moutn1 = rebuild(no1);
442
443 % </SyntaxCode>
444 stest = true;
445 catch err
446 disp(err.message)
447 stest = false;
448 end
449
450 % <AlgoDescription>
451 %
452 % 1) Check that the output contains the right number of objects
453 % 2) Check that the 'rebuild' method produces the same object as 'out'.
454 %
455 % </AlgoDescription>
456
457 atest = true;
458 if stest
459 % <AlgoCode>
460 % Check the number of outputs
461 if numel(o11) ~=1, atest = false; end
462 if numel(o12) ~=1, atest = false; end
463 if numel(no1) ~=2, atest = false; end
464 % Check the rebuilding of the object
465 if ~eq(o11, mout11, ple2), atest = false; end
466 if ~eq(o12, mout12, ple2), atest = false; end
467 if ~eq(no1, moutn1, ple2), atest = false; end
468 % </AlgoCode>
469 else
470 atest = false;
471 end
472
473 % Return a result structure
474 result = utp_prepare_result(atest, stest, dbstack, mfilename);
475 end % END UTP_09
476
477
478
479 end