comparison testing/utp_1.1/utps/ao/utp_ao_setYunits.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_SETYUNITS a set of UTPs for the ao/setYunits method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_setYunits.m,v 1.15 2011/04/19 18:14:01 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The setYunits method of the ao class sets the yunits property.
11 %
12 % </MethodDescription>
13
14 function results = utp_ao_setYunits(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'ao';
21 mthd = 'setYunits';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test AOs
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
30
31 % Exception list for the UTPs:
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
33
34 % Run the tests
35 results = [results utp_01]; % getInfo call
36 results = [results utp_02]; % Vector input
37 results = [results utp_03]; % Matrix input
38 results = [results utp_04]; % List input
39 results = [results utp_05]; % Test with mixed input
40 results = [results utp_06]; % Test history is working
41 results = [results utp_07]; % Test the modify call works
42 results = [results utp_08]; % Set the property with a plist
43 results = [results utp_09]; % Test output of the data
44 results = [results utp_11(mthd, at1, ple1, plist('yunits', 'm'))]; % Test plotinfo doesn't disappear
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 ~= 1, atest = false; end
113 % Check key
114 if ~io(3).plists.isparam('yunits'), atest = false; end
115 % Check default value
116 if ~isEmptyChar(io(3).plists.find('yunits')), atest = false; end
117 % Check options
118 if ~isequal(io(3).plists.getOptionsForParam('yunits'), {''}), atest = false; end
119 % </AlgoCode>
120 end
121 else
122 atest = false;
123 end
124
125 % Return a result structure
126 result = utp_prepare_result(atest, stest, dbstack, mfilename);
127 end % END UTP_01
128
129 %% UTP_02
130
131 % <TestDescription>
132 %
133 % Tests that the setYunits method works with a vector of AOs as input.
134 %
135 % </TestDescription>
136 function result = utp_02
137
138 % <SyntaxDescription>
139 %
140 % Test that the setYunits method works for a vector of AOs as input.
141 %
142 % </SyntaxDescription>
143
144 try
145 % <SyntaxCode>
146 out = setYunits(atvec, 's m');
147 % </SyntaxCode>
148 stest = true;
149 catch err
150 disp(err.message)
151 stest = false;
152 end
153
154 % <AlgoDescription>
155 %
156 % 1) Check that the number of elements in 'out' is the same as in 'atvec'
157 % 2) Check that each output AO contains the correct data.
158 %
159 % </AlgoDescription>
160
161 atest = true;
162 if stest
163 % <AlgoCode>
164 % Check we have the correct number of outputs
165 if ~isequal(size(out), size(atvec)), atest = false; end
166 % Check yunits field of each output
167 for kk=1:numel(out)
168 if ~eq(out(kk).data.yunits, unit('s m'), ple1)
169 atest = false;
170 break;
171 end
172 end
173 % </AlgoCode>
174 else
175 atest = false;
176 end
177
178 % Return a result structure
179 result = utp_prepare_result(atest, stest, dbstack, mfilename);
180 end % END UTP_02
181
182 %% UTP_03
183
184 % <TestDescription>
185 %
186 % Tests that the setYunits method works with a matrix of AOs as input.
187 %
188 % </TestDescription>
189 function result = utp_03
190
191 % <SyntaxDescription>
192 %
193 % Test that the setYunits method works for a matrix of AOs as input.
194 %
195 % </SyntaxDescription>
196
197 try
198 % <SyntaxCode>
199 out = setYunits(atmat, 'kg s^2');
200 % </SyntaxCode>
201 stest = true;
202 catch err
203 disp(err.message)
204 stest = false;
205 end
206
207 % <AlgoDescription>
208 %
209 % 1) Check that the number of elements in 'out' is the same as in 'atmat'
210 % 2) Check that each output AO contains the correct data.
211 %
212 % </AlgoDescription>
213
214 atest = true;
215 if stest
216 % <AlgoCode>
217 % Check we have the correct number of outputs
218 if ~isequal(size(out), size(atmat)), atest = false; end
219 % Check yunits field of each output
220 for kk=1:numel(out)
221 if ~eq(out(kk).data.yunits, unit('kg s^2'), ple1)
222 atest = false;
223 break;
224 end
225 end
226 % </AlgoCode>
227 else
228 atest = false;
229 end
230
231 % Return a result structure
232 result = utp_prepare_result(atest, stest, dbstack, mfilename);
233 end % END UTP_03
234
235 %% UTP_04
236
237 % <TestDescription>
238 %
239 % Tests that the setYunits method works with a list of AOs as input.
240 %
241 % </TestDescription>
242 function result = utp_04
243
244 % <SyntaxDescription>
245 %
246 % Test that the setYunits method works for a list of AOs as input.
247 %
248 % </SyntaxDescription>
249
250 try
251 % <SyntaxCode>
252 u1 = unit('V m^-1');
253 out = setYunits(at1,at2,at5, u1);
254 % </SyntaxCode>
255 stest = true;
256 catch err
257 disp(err.message)
258 stest = false;
259 end
260
261 % <AlgoDescription>
262 %
263 % 1) Check that the number of elements in 'out' is the same as in
264 % input.
265 % 2) Check that each output AO contains the correct data.
266 %
267 % </AlgoDescription>
268
269 atest = true;
270 if stest
271 % <AlgoCode>
272 % Check we have the correct number of outputs
273 if numel(out) ~= 3, atest = false; end
274 % Check each output against the input
275 if ~eq(out(1).data.yunits, u1), atest = false; end
276 if ~eq(out(2).data.yunits, u1), atest = false; end
277 if ~eq(out(3).data.yunits, u1), atest = false; end
278 % </AlgoCode>
279 else
280 atest = false;
281 end
282
283 % Return a result structure
284 result = utp_prepare_result(atest, stest, dbstack, mfilename);
285 end % END UTP_04
286
287 %% UTP_05
288
289 % <TestDescription>
290 %
291 % Tests that the setYunits method works with a mix of different shaped AOs as
292 % input.
293 %
294 % </TestDescription>
295 function result = utp_05
296
297 % <SyntaxDescription>
298 %
299 % Test that the setYunits method works with an input of matrices and vectors
300 % and single AOs.
301 %
302 % </SyntaxDescription>
303
304 try
305 % <SyntaxCode>
306 u1 = unit('V m^-1');
307 atvec = [at1, at2, at3, at6];
308 out = setYunits(at1,atvec,at2,atmat,at5, u1);
309 % </SyntaxCode>
310 stest = true;
311 catch err
312 disp(err.message)
313 stest = false;
314 end
315
316 % <AlgoDescription>
317 %
318 % 1) Check that the number of elements in 'out' is the same as in
319 % input.
320 % 2) Check that each output AO contains the correct data.
321 %
322 % </AlgoDescription>
323
324 atest = true;
325 if stest
326 % <AlgoCode>
327 % Check we have the correct number of outputs
328 if numel(out) ~= (3+numel(atmat)+numel(atvec)), atest = false; end
329 for kk=1:numel(out)
330 if ~eq(out(kk).data.yunits, u1)
331 atest = false;
332 break;
333 end
334 end
335 % </AlgoCode>
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_05
343
344 %% UTP_06
345
346 % <TestDescription>
347 %
348 % Tests that the setYunits method properly applies history and that the
349 % option 'internal' suppresses the history.
350 %
351 % </TestDescription>
352 function result = utp_06
353
354 % <SyntaxDescription>
355 %
356 % Test that the result of applying the setYunits method can be processed back
357 % to an m-file.
358 %
359 % </SyntaxDescription>
360
361 try
362 % <SyntaxCode>
363 u1 = unit('V m^-1');
364 out1 = setYunits(at1, u1);
365 out2 = testCallerIsMethod(@setYunits, at1, u1);
366 mout1 = rebuild(out1);
367 mout2 = rebuild(out2);
368 % </SyntaxCode>
369 stest = true;
370 catch err
371 disp(err.message)
372 stest = false;
373 end
374
375 % <AlgoDescription>
376 %
377 % 1) Check that the last entry in the history of 'out1' corresponds to
378 % 'setYunits'.
379 % 1) Check that the last entry in the history of 'out2' NOT corresponds to
380 % 'setYunits'.
381 % 2) Check that the re-built object is the same object as 'out'.
382 %
383 % </AlgoDescription>
384
385 atest = true;
386 if stest
387 % <AlgoCode>
388 % Check the last step in the history of 'out1'
389 if ~strcmp(out1.hist.methodInfo.mname, 'setYunits'), atest = false; end
390 % Check the last step in the history of 'out2'
391 if strcmp(out2.hist.methodInfo.mname, 'setYunits'), atest = false; end
392 % Check the re-built object
393 if ~eq(mout1, out1, ple2), atest = false; end
394 e = ple2.find('EXCEPTIONS');
395 ple = plist('EXCEPTIONS', [e {'yunits'}]);
396 if ~eq(mout2, out2, ple), atest = false; end
397 % </AlgoCode>
398 else
399 atest = false;
400 end
401
402 % Return a result structure
403 result = utp_prepare_result(atest, stest, dbstack, mfilename);
404 end % END UTP_06
405
406 %% UTP_07
407
408 % <TestDescription>
409 %
410 % Tests that the setYunits method can modify the input AO.
411 %
412 % </TestDescription>
413 function result = utp_07
414
415 % <SyntaxDescription>
416 %
417 % Test that the setYunits method can modify the input AO by calling with no
418 % output.
419 %
420 % </SyntaxDescription>
421
422 try
423 % <SyntaxCode>
424 % copy at1 to work with
425 u1 = unit('N V');
426 ain = ao(at1);
427 % modify ain
428 aout = ain.setYunits(u1);
429 ain.setYunits(u1);
430 % </SyntaxCode>
431 stest = true;
432 catch err
433 disp(err.message)
434 stest = false;
435 end
436
437 % <AlgoDescription>
438 %
439 % 1) Check that 'at1' and 'ain' are now different.
440 % 2) Check that 'ain' has the correct yunits field
441 %
442 % </AlgoDescription>
443
444 atest = true;
445 if stest
446 % <AlgoCode>
447 % Check that setYunits modified the input by comparing to the copy
448 if eq(ao(at1), ain, ple1), atest = false; end
449 % Check that setYunits doesn't modified the input for the function notation
450 if ~eq(aout, ain, ple1), atest = false; end
451 % Check that the modified object contains the changed value
452 if ~eq(ain.data.yunits, u1), atest = false; end
453 % </AlgoCode>
454 else
455 atest = false;
456 end
457
458 % Return a result structure
459 result = utp_prepare_result(atest, stest, dbstack, mfilename);
460 end % END UTP_07
461
462 %% UTP_08
463
464 % <TestDescription>
465 %
466 % Tests that the setYunits method can set the property with a plist.
467 %
468 % </TestDescription>
469 function result = utp_08
470
471 % <SyntaxDescription>
472 %
473 % Test that the setYunits method can modify the property 'yunits'
474 % with a value in a plist.
475 %
476 % </SyntaxDescription>
477
478 try
479 % <SyntaxCode>
480 u1 = unit('V m^-1');
481 pl = plist('yunits', u1);
482 out = at1.setYunits(pl);
483 mout = rebuild(out);
484 % </SyntaxCode>
485 stest = true;
486 catch err
487 disp(err.message)
488 stest = false;
489 end
490
491 % <AlgoDescription>
492 %
493 % 1) Check that 'ain' has the correct yunits field
494 % 2) Check that the re-built object is the same object as 'out'.
495 %
496 % </AlgoDescription>
497
498 atest = true;
499 if stest
500 % <AlgoCode>
501 % Check the field 'yunits'
502 if ~eq(out.data.yunits, u1), atest = false; end
503 % Check the re-built object
504 if ~eq(mout, out, ple2), atest = false; end
505 % </AlgoCode>
506 else
507 atest = false;
508 end
509
510 % Return a result structure
511 result = utp_prepare_result(atest, stest, dbstack, mfilename);
512 end % END UTP_08
513
514 %% UTP_09
515
516 % <TestDescription>
517 %
518 % Check that the setYunits method pass back the output objects to a list of
519 % output variables or to a single variable.
520 %
521 % </TestDescription>
522 function result = utp_09
523
524 % <SyntaxDescription>
525 %
526 % Call the method with a list of output variables and with a single output
527 % variable. Additionaly check that the rebuild method works on the output.
528 %
529 % </SyntaxDescription>
530
531 try
532 % <SyntaxCode>
533 [o1, o2] = setYunits(at5, at6, unit('Hz'));
534 o3 = setYunits(at5, at6, unit('Hz'));
535 mout1 = rebuild(o1);
536 mout2 = rebuild(o2);
537 mout3 = rebuild(o3);
538 % </SyntaxCode>
539 stest = true;
540 catch err
541 disp(err.message)
542 stest = false;
543 end
544
545 % <AlgoDescription>
546 %
547 % 1) Check that the output contains the right number of objects
548 % 2) Check that the 'rebuild' method produces the same object as 'out'.
549 %
550 % </AlgoDescription>
551
552 atest = true;
553 if stest
554 % <AlgoCode>
555 % Check the number of outputs
556 if numel(o1) ~=1, atest = false; end
557 if numel(o2) ~=1, atest = false; end
558 if numel(o3) ~=2, atest = false; end
559 % Check the rebuilding of the object
560 if ~eq(o1, mout1, ple2), atest = false; end
561 if ~eq(o2, mout2, ple2), atest = false; end
562 if ~eq(o3, mout3, ple2), atest = false; end
563 % </AlgoCode>
564 else
565 atest = false;
566 end
567
568 % Return a result structure
569 result = utp_prepare_result(atest, stest, dbstack, mfilename);
570 end % END UTP_09
571
572 end