comparison testing/utp_1.1/utps/ao/utp_ao_created.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_CREATED a set of UTPs for the ao/created method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_created.m,v 1.3 2009/07/27 19:28:58 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The created method of the ao returns a time object of the last
11 % modification. For this uses the created method the 'proctime' property of
12 % the last history step and computs from this value a timeobject.
13 %
14 % </MethodDescription>
15
16 function results = utp_ao_created(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'ao';
23 mthd = 'created';
24
25 results = [];
26 disp('******************************************************');
27 disp(['**** Running UTPs for ' class '/' mthd]);
28 disp('******************************************************');
29
30 % Test AO objects
31 [at1,at2,at3,at4,at5,at6,atvec,atmat] = get_test_objects_ao;
32
33 % Exception list for the UTPs:
34 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
35
36 % Run the tests
37 results = [results utp_01]; % getInfo call
38 results = [results utp_02]; % Vector input
39 results = [results utp_03]; % Matrix input
40 results = [results utp_04]; % List input
41 results = [results utp_05]; % Test with mixed input
42 results = [results utp_06]; % Test history is working
43 results = [results utp_07]; % Test the modify call works
44 results = [results utp_08]; % Test empty object
45
46 disp('Done.');
47 disp('******************************************************');
48
49 elseif nargin == 1 % Check for UTP functions
50 if strcmp(varargin{1}, 'isutp')
51 results = 1;
52 else
53 results = 0;
54 end
55 else
56 error('### Incorrect inputs')
57 end
58
59 %% UTP_01
60
61 % <TestDescription>
62 %
63 % Tests that the getInfo call works for this method.
64 %
65 % </TestDescription>
66 function result = utp_01
67
68
69 % <SyntaxDescription>
70 %
71 % Test that the getInfo call works for no sets, all sets, and each set
72 % individually.
73 %
74 % </SyntaxDescription>
75
76 try
77 % <SyntaxCode>
78 % Call for no sets
79 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
80 % Call for all sets
81 io(2) = eval([class '.getInfo(''' mthd ''')']);
82 % Call for each set
83 for kk=1:numel(io(2).sets)
84 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
85 end
86 % </SyntaxCode>
87 stest = true;
88 catch err
89 disp(err.message)
90 stest = false;
91 end
92
93 % <AlgoDescription>
94 %
95 % 1) Check that getInfo call returned an minfo object in all cases.
96 % 2) Check that all plists have the correct parameters.
97 %
98 % </AlgoDescription>
99
100 atest = true;
101 if stest
102 % <AlgoCode>
103 % check we have minfo objects
104 if isa(io, 'minfo')
105 %%% SET 'None'
106 if ~isempty(io(1).sets), atest = false; end
107 if ~isempty(io(1).plists), atest = false; end
108 %%% Check all Sets
109 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
110 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
111 %%%%%%%%%% SET 'Default'
112 if io(3).plists.nparams ~= 0, atest = false; end
113 % Check key
114 % Check default value
115 % Check options
116 end
117 % </AlgoCode>
118 else
119 atest = false;
120 end
121
122 % Return a result structure
123 result = utp_prepare_result(atest, stest, dbstack, mfilename);
124 end % END UTP_01
125
126 %% UTP_02
127
128 % <TestDescription>
129 %
130 % Tests that the created method works with a vector of AOs as input.
131 %
132 % </TestDescription>
133 function result = utp_02
134
135 % <SyntaxDescription>
136 %
137 % Test that the created method works for a vector of AOs as input.
138 %
139 % </SyntaxDescription>
140
141 try
142 % <SyntaxCode>
143 out = created(atvec);
144 % </SyntaxCode>
145 stest = true;
146 catch err
147 disp(err.message)
148 stest = false;
149 end
150
151 % <AlgoDescription>
152 %
153 % 1) Check that the number of elements in 'out' is the same as in 'atvec'
154 % 2) Check that each output contains the correct data.
155 %
156 % </AlgoDescription>
157
158 atest = true;
159 if stest
160 % <AlgoCode>
161 % Check that the output is a time object
162 if ~isa(out, 'time'), atest = false; end
163 % Check we have the correct number of outputs
164 if ~isequal(size(out), size(atvec)), atest = false; end
165 % Check the time-object
166 for kk=1:numel(out)
167 if out(kk).utc_epoch_milli ~= atvec(kk).hist.proctime, atest = false; break; end
168 end
169 % </AlgoCode>
170 else
171 atest = false;
172 end
173
174 % Return a result structure
175 result = utp_prepare_result(atest, stest, dbstack, mfilename);
176 end % END UTP_02
177
178 %% UTP_03
179
180 % <TestDescription>
181 %
182 % Tests that the created method works with a matrix of AOs as input.
183 %
184 % </TestDescription>
185 function result = utp_03
186
187 % <SyntaxDescription>
188 %
189 % Test that the created method works for a matrix of AOs as input.
190 %
191 % </SyntaxDescription>
192
193 try
194 % <SyntaxCode>
195 out = created(atmat);
196 % </SyntaxCode>
197 stest = true;
198 catch err
199 disp(err.message)
200 stest = false;
201 end
202
203 % <AlgoDescription>
204 %
205 % 1) Check that the number of elements in 'out' is the same as in 'atmat'
206 % 2) Check that each output contains the correct data.
207 %
208 % </AlgoDescription>
209
210 atest = true;
211 if stest
212 % <AlgoCode>
213 % Check that the output is a time object
214 if ~isa(out, 'time'), atest = false; end
215 % Check we have the correct number of outputs
216 if ~isequal(size(out), size(atmat)), atest = false; end
217 % Check time-object
218 for kk=1:numel(out)
219 if out(kk).utc_epoch_milli ~= atmat(kk).hist.proctime, atest = false; break; end
220 end
221 % </AlgoCode>
222 else
223 atest = false;
224 end
225
226 % Return a result structure
227 result = utp_prepare_result(atest, stest, dbstack, mfilename);
228 end % END UTP_03
229
230 %% UTP_04
231
232 % <TestDescription>
233 %
234 % Tests that the created method works with a list of AOs as input.
235 %
236 % </TestDescription>
237 function result = utp_04
238
239 % <SyntaxDescription>
240 %
241 % Test that the created method works for a list of AOs as input.
242 %
243 % </SyntaxDescription>
244
245 try
246 % <SyntaxCode>
247 out = created(at1,at2,at3);
248 % </SyntaxCode>
249 stest = true;
250 catch err
251 disp(err.message)
252 stest = false;
253 end
254
255 % <AlgoDescription>
256 %
257 % 1) Check that the number of elements in 'out' is the same as in input.
258 % 2) Check that each output contains the correct data.
259 %
260 % </AlgoDescription>
261
262 atest = true;
263 if stest
264 % <AlgoCode>
265 % Check that the output is a time object
266 if ~isa(out, 'time'), atest = false; end
267 % Check we have the correct number of outputs
268 if numel(out) ~= 3, atest = false; end
269 % Check each output against the input
270 if out(1).utc_epoch_milli ~= at1.hist.proctime, atest = false; end
271 if out(2).utc_epoch_milli ~= at2.hist.proctime, atest = false; end
272 if out(3).utc_epoch_milli ~= at3.hist.proctime, atest = false; end
273 % </AlgoCode>
274 else
275 atest = false;
276 end
277
278 % Return a result structure
279 result = utp_prepare_result(atest, stest, dbstack, mfilename);
280 end % END UTP_04
281
282 %% UTP_05
283
284 % <TestDescription>
285 %
286 % Tests that the created method works with a mix of different shaped AOs
287 % as input.
288 %
289 % </TestDescription>
290 function result = utp_05
291
292 % <SyntaxDescription>
293 %
294 % Test that the created method works with an input of matrices and
295 % vectors and single AOs.
296 %
297 % </SyntaxDescription>
298
299 try
300 % <SyntaxCode>
301 out = created(at1,atvec,at2,atmat,at3);
302 % </SyntaxCode>
303 stest = true;
304 catch err
305 disp(err.message)
306 stest = false;
307 end
308
309 % <AlgoDescription>
310 %
311 % 1) Check that the number of elements in 'out' is the same as in input.
312 % 2) Check that each output contains the correct data.
313 %
314 % </AlgoDescription>
315
316 atest = true;
317 aoin = [at1,reshape(atvec,1,[]),at2,reshape(atmat,1,[]),at3];
318 if stest
319 % <AlgoCode>
320 % Check that the output is a time object
321 if ~isa(out, 'time'), atest = false; end
322 % Check we have the correct number of outputs
323 if numel(out) ~= (3+numel(atmat)+numel(atvec)), atest = false; end
324 for kk=1:numel(out)
325 if out(kk).utc_epoch_milli ~= aoin(kk).hist.proctime, atest = false; break; end
326 end
327 % </AlgoCode>
328 else
329 atest = false;
330 end
331
332 % Return a result structure
333 result = utp_prepare_result(atest, stest, dbstack, mfilename);
334 end % END UTP_05
335
336 %% UTP_06
337
338 % <TestDescription>
339 %
340 % Tests that the created method properly applies history
341 %
342 % </TestDescription>
343 function result = utp_06
344
345 % <SyntaxDescription>
346 %
347 % This method doesn't change the input object, thus no history is added
348 % to the object.
349 %
350 % </SyntaxDescription>
351
352 try
353 % <SyntaxCode>
354 % </SyntaxCode>
355 stest = true;
356 catch err
357 disp(err.message)
358 stest = false;
359 end
360
361 % <AlgoDescription>
362 %
363 % 1) Nothing to check.
364 %
365 % </AlgoDescription>
366
367 atest = true;
368 if stest
369 % <AlgoCode>
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_06
378
379 %% UTP_07
380
381 % <TestDescription>
382 %
383 % Tests that the created method can be used with the modify command.
384 %
385 % </TestDescription>
386 function result = utp_07
387
388 % <SyntaxDescription>
389 %
390 % Tests that the created method can be used with the modify command.
391 %
392 % </SyntaxDescription>
393
394 try
395 % <SyntaxCode>
396 out1 = at3.created;
397 out2 = atmat.created;
398 % </SyntaxCode>
399 stest = true;
400 catch err
401 disp(err.message)
402 stest = false;
403 end
404
405 % <AlgoDescription>
406 %
407 % 1) Check the single object
408 % 2) Check the matrix object
409 %
410 % </AlgoDescription>
411
412 atest = true;
413 if stest
414 % <AlgoCode>
415 % Check the single object
416 if out1.utc_epoch_milli ~= at3.hist.proctime, atest = false; end
417 % Check the matrix
418 for kk = 1:numel(out2)
419 if out2(kk).utc_epoch_milli ~= atmat(kk).hist.proctime, atest = false; end
420 end
421 % </AlgoCode>
422 else
423 atest = false;
424 end
425
426 % Return a result structure
427 result = utp_prepare_result(atest, stest, dbstack, mfilename);
428 end % END UTP_07
429
430 %% UTP_08
431
432 % <TestDescription>
433 %
434 % Tests that the created method retruns always a well defined time object
435 % even for an empty input object.
436 %
437 % </TestDescription>
438 function result = utp_08
439
440 % <SyntaxDescription>
441 %
442 % Test that the created method with an empty AO
443 %
444 % </SyntaxDescription>
445
446 try
447 % <SyntaxCode>
448 a1 = ao();
449 out = a1.created;
450 % </SyntaxCode>
451 stest = true;
452 catch err
453 disp(err.message)
454 stest = false;
455 end
456
457 % <AlgoDescription>
458 %
459 % 1) Check that the output is a time object with a ell defined time.
460 %
461 % </AlgoDescription>
462
463 atest = true;
464 if stest
465 % <AlgoCode>
466 if ~isa(out, 'time'), atest = false; end
467 if isnan(out.utc_epoch_milli), 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_08
476
477 end