comparison testing/utp_1.1/utps/ao/utp_ao_setX.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_SETX a set of UTPs for the ao/setX method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_setX.m,v 1.16 2011/05/09 12:26:21 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The setX method of the ao class sets the 'x' property.
11 %
12 % </MethodDescription>
13
14 function results = utp_ao_setX(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'ao';
21 mthd = 'setX';
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 that the shape of the data doesn't change
44 results = [results utp_10]; % Test output of the data
45 results = [results utp_11(mthd, at1, ple1, plist('X', at1.y))]; % Test plotinfo doesn't disappear
46
47 disp('Done.');
48 disp('******************************************************');
49
50 elseif nargin == 1 % Check for UTP functions
51 if strcmp(varargin{1}, 'isutp')
52 results = 1;
53 else
54 results = 0;
55 end
56 else
57 error('### Incorrect inputs')
58 end
59
60 %% UTP_01
61
62 % <TestDescription>
63 %
64 % Tests that the getInfo call works for this method.
65 %
66 % </TestDescription>
67 function result = utp_01
68
69
70 % <SyntaxDescription>
71 %
72 % Test that the getInfo call works for no sets, all sets, and each set
73 % individually.
74 %
75 % </SyntaxDescription>
76
77 try
78 % <SyntaxCode>
79 % Call for no sets
80 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
81 % Call for all sets
82 io(2) = eval([class '.getInfo(''' mthd ''')']);
83 % Call for each set
84 for kk=1:numel(io(2).sets)
85 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
86 end
87 % </SyntaxCode>
88 stest = true;
89 catch err
90 disp(err.message)
91 stest = false;
92 end
93
94 % <AlgoDescription>
95 %
96 % 1) Check that getInfo call returned an minfo object in all cases.
97 % 2) Check that all plists have the correct parameters.
98 %
99 % </AlgoDescription>
100
101 atest = true;
102 if stest
103 % <AlgoCode>
104 % check we have minfo objects
105 if isa(io, 'minfo')
106 %%% SET 'None'
107 if ~isempty(io(1).sets), atest = false; end
108 if ~isempty(io(1).plists), atest = false; end
109 %%% Check all Sets
110 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
111 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
112 %%%%%%%%%% SET 'Default'
113 if io(3).plists.nparams ~= 1, atest = false; end
114 % Check key
115 if ~io(3).plists.isparam('x'), atest = false; end
116 % Check default value
117 if ~isEmptyDouble(io(3).plists.find('x')), atest = false; end
118 % Check options
119 if ~isequal(io(3).plists.getOptionsForParam('x'), {[]}), atest = false; end
120 end
121 % </AlgoCode>
122 else
123 atest = false;
124 end
125
126 % Return a result structure
127 result = utp_prepare_result(atest, stest, dbstack, mfilename);
128 end % END UTP_01
129
130 %% UTP_02
131
132 % <TestDescription>
133 %
134 % Tests that the setX method works with a vector of AOs as input.
135 %
136 % </TestDescription>
137 function result = utp_02
138
139 % <SyntaxDescription>
140 %
141 % Test that the setX method works for a vector of AOs as input.
142 %
143 % </SyntaxDescription>
144
145 try
146 % <SyntaxCode>
147 in = [1:at1.len]';
148 avec = [at1, at1, at1, at1];
149 out = setX(avec, in);
150 % </SyntaxCode>
151 stest = true;
152 catch err
153 disp(err.message)
154 stest = false;
155 end
156
157 % <AlgoDescription>
158 %
159 % 1) Check that the number of elements in 'out' is the same as in 'avec'
160 % 2) Check that each output AO contains the correct data.
161 %
162 % </AlgoDescription>
163
164 atest = true;
165 if stest
166 % <AlgoCode>
167 % Check we have the correct number of outputs
168 if ~isequal(size(out), size(avec)), atest = false; end
169 % Check 'x' field of each output
170 for kk=1:numel(out)
171 out_x = out(kk).data.x;
172 if size(out_x, 1) == 1
173 out_x = out_x.';
174 end
175 if ~isequal(out_x, in), atest = false; break; end
176 end
177 % </AlgoCode>
178 else
179 atest = false;
180 end
181
182 % Return a result structure
183 result = utp_prepare_result(atest, stest, dbstack, mfilename);
184 end % END UTP_02
185
186 %% UTP_03
187
188 % <TestDescription>
189 %
190 % Tests that the setX method works with a matrix of AOs as input.
191 %
192 % </TestDescription>
193 function result = utp_03
194
195 % <SyntaxDescription>
196 %
197 % Test that the setX method works for a matrix of AOs as input.
198 %
199 % </SyntaxDescription>
200
201 try
202 % <SyntaxCode>
203 in = [1:at2.len]';
204 amat = [at2, at2, at2; at2, at2, at2];
205 out = setX(amat, in);
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 'amat'
216 % 2) Check that each output AO contains the correct data.
217 %
218 % </AlgoDescription>
219
220 atest = true;
221 if stest
222 % <AlgoCode>
223 % Check we have the correct number of outputs
224 if ~isequal(size(out), size(amat)), atest = false; end
225 % Check 'x' field of each output
226 for kk=1:numel(out)
227 out_x = out(kk).data.x;
228 if size(out_x, 1) == 1
229 out_x = out_x.';
230 end
231 if ~isequal(out_x, in), atest = false; break; end
232 end
233 % </AlgoCode>
234 else
235 atest = false;
236 end
237
238 % Return a result structure
239 result = utp_prepare_result(atest, stest, dbstack, mfilename);
240 end % END UTP_03
241
242 %% UTP_04
243
244 % <TestDescription>
245 %
246 % Tests that the setX method works with a list of AOs as input.
247 %
248 % </TestDescription>
249 function result = utp_04
250
251 % <SyntaxDescription>
252 %
253 % Test that the setX method works for a list of AOs as input.
254 %
255 % </SyntaxDescription>
256
257 try
258 % <SyntaxCode>
259 in = [1:at3.len]';
260 out = setX(at3,at3,at3, in);
261 % </SyntaxCode>
262 stest = true;
263 catch err
264 disp(err.message)
265 stest = false;
266 end
267
268 % <AlgoDescription>
269 %
270 % 1) Check that the number of elements in 'out' is the same as in
271 % input.
272 % 2) Check that each output AO contains the correct data.
273 %
274 % </AlgoDescription>
275
276 atest = true;
277 if stest
278 % <AlgoCode>
279 % Check we have the correct number of outputs
280 if numel(out) ~= 3, atest = false; end
281 % Check each output against the input
282 if ~isequal(out(1).x, in), atest = false; end
283 if ~isequal(out(2).x, in), atest = false; end
284 if ~isequal(out(3).x, in), atest = false; end
285 % </AlgoCode>
286 else
287 atest = false;
288 end
289
290 % Return a result structure
291 result = utp_prepare_result(atest, stest, dbstack, mfilename);
292 end % END UTP_04
293
294 %% UTP_05
295
296 % <TestDescription>
297 %
298 % Tests that the setX method works with a mix of different shaped AOs as
299 % input.
300 %
301 % </TestDescription>
302 function result = utp_05
303
304 % <SyntaxDescription>
305 %
306 % Test that the setX method works with an input of matrices and vectors
307 % and single AOs.
308 %
309 % </SyntaxDescription>
310
311 try
312 % <SyntaxCode>
313 in = [1:at3.len]';
314 avec = [at3, at3, at3, at3];
315 amat = [at3, at3, at3; at3, at3, at3];
316 out = setX(at3,avec,at3,amat,at3, in);
317 % </SyntaxCode>
318 stest = true;
319 catch err
320 disp(err.message)
321 stest = false;
322 end
323
324 % <AlgoDescription>
325 %
326 % 1) Check that the number of elements in 'out' is the same as in
327 % input.
328 % 2) Check that each output AO contains the correct data.
329 %
330 % </AlgoDescription>
331
332 atest = true;
333 if stest
334 % <AlgoCode>
335 % Check we have the correct number of outputs
336 if numel(out) ~= (3+numel(amat)+numel(avec)), atest = false; end
337 for kk=1:numel(out)
338 out_x = out(kk).data.x;
339 if size(out_x, 1) == 1
340 out_x = out_x.';
341 end
342 if ~isequal(out_x, in), atest = false; break; end
343 end
344 % </AlgoCode>
345 else
346 atest = false;
347 end
348
349 % Return a result structure
350 result = utp_prepare_result(atest, stest, dbstack, mfilename);
351 end % END UTP_05
352
353 %% UTP_06
354
355 % <TestDescription>
356 %
357 % Tests that the setX method properly applies history and that the
358 % option 'internal' suppresses the history.
359 %
360 % </TestDescription>
361 function result = utp_06
362
363 % <SyntaxDescription>
364 %
365 % Test that the result of applying the setX method can be processed back
366 % to an m-file.
367 %
368 % </SyntaxDescription>
369
370 try
371 % <SyntaxCode>
372 in = [1:at1.len]';
373 out1 = setX(at1, in);
374 out2 = testCallerIsMethod(@setX, at1, in);
375 mout1 = rebuild(out1);
376 mout2 = rebuild(out2);
377 % </SyntaxCode>
378 stest = true;
379 catch err
380 disp(err.message)
381 stest = false;
382 end
383
384 % <AlgoDescription>
385 %
386 % 1) Check that the last entry in the history of 'out1' corresponds to
387 % 'setX'.
388 % 1) Check that the last entry in the history of 'out2' NOT corresponds to
389 % 'setX'.
390 % 2) Check that the re-built object is the same object as 'out'.
391 %
392 % </AlgoDescription>
393
394 atest = true;
395 if stest
396 % <AlgoCode>
397 % Check the last step in the history of 'out1'
398 if ~strcmp(out1.hist.methodInfo.mname, 'setX'), atest = false; end
399 % Check the last step in the history of 'out2'
400 if strcmp(out2.hist.methodInfo.mname, 'setX'), atest = false; end
401 % Check the re-built object
402 if ~eq(mout1, out1, ple2), atest = false; end
403 e = ple2.find('EXCEPTIONS');
404 ple = plist('EXCEPTIONS', [e {'x'}]);
405 if ~eq(mout2, out2, ple), atest = false; end
406 % </AlgoCode>
407 else
408 atest = false;
409 end
410
411 % Return a result structure
412 result = utp_prepare_result(atest, stest, dbstack, mfilename);
413 end % END UTP_06
414
415 %% UTP_07
416
417 % <TestDescription>
418 %
419 % Tests that the setX method can modify the input AO.
420 %
421 % </TestDescription>
422 function result = utp_07
423
424 % <SyntaxDescription>
425 %
426 % Test that the setX method can modify the input AO by calling with no
427 % output.
428 %
429 % </SyntaxDescription>
430
431 try
432 % <SyntaxCode>
433 % copy at1 to work with
434 in = [1:at1.len]';
435 ain = ao(at1);
436 % modify ain
437 aout = ain.setX(in);
438 ain.setX(in);
439 % </SyntaxCode>
440 stest = true;
441 catch err
442 disp(err.message)
443 stest = false;
444 end
445
446 % <AlgoDescription>
447 %
448 % 1) Check that 'at1' and 'ain' are now different.
449 % 2) Check that 'ain' has the correct 'x' field
450 %
451 % </AlgoDescription>
452
453 atest = true;
454 if stest
455 % <AlgoCode>
456 % Check that setX modified the input by comparing to the copy
457 if eq(ao(at1), ain, ple1), atest = false; end
458 % Check that setX doesn't modified the input for the function notation
459 if ~eq(aout, ain, ple1), atest = false; end
460 % Check that the modified object contains the changed value
461 if ~isequal(ain.data.x, in), atest = false; end
462 % </AlgoCode>
463 else
464 atest = false;
465 end
466
467 % Return a result structure
468 result = utp_prepare_result(atest, stest, dbstack, mfilename);
469 end % END UTP_07
470
471 %% UTP_08
472
473 % <TestDescription>
474 %
475 % Tests that the setX method can set the property with a plist.
476 %
477 % </TestDescription>
478 function result = utp_08
479
480 % <SyntaxDescription>
481 %
482 % Test that the setX method can modify the property 'x'
483 % with a value in a plist.
484 %
485 % </SyntaxDescription>
486
487 try
488 % <SyntaxCode>
489 in = [1:at1.len]';
490 pl = plist('x', in);
491 out = at1.setX(pl);
492 mout = rebuild(out);
493 % </SyntaxCode>
494 stest = true;
495 catch err
496 disp(err.message)
497 stest = false;
498 end
499
500 % <AlgoDescription>
501 %
502 % 1) Check that 'ain' has the correct x field
503 % 2) Check that the re-built object is the same object as 'out'.
504 %
505 % </AlgoDescription>
506
507 atest = true;
508 if stest
509 % <AlgoCode>
510 % Check the field 'x'
511 if ~isequal(out.data.x, in), atest = false; end
512 % Check the re-built object
513 if ~eq(mout, out, ple2), atest = false; end
514 % </AlgoCode>
515 else
516 atest = false;
517 end
518
519 % Return a result structure
520 result = utp_prepare_result(atest, stest, dbstack, mfilename);
521 end % END UTP_08
522
523 %% UTP_09
524
525 % <TestDescription>
526 %
527 % Tests that the setX method keeps the shape of the data.
528 %
529 % </TestDescription>
530 function result = utp_09
531
532 % <SyntaxDescription>
533 %
534 % Test that the setX method keeps the shape of the data. Independent of the
535 % input
536 %
537 % </SyntaxDescription>
538
539 try
540 % <SyntaxCode>
541 in_r = [1:at5.len];
542 in_c = [1:at5.len]';
543 out1 = at5.setX(in_r);
544 out2 = at5.setX(in_c);
545 out3 = at6.setX(in_r);
546 out4 = at6.setX(in_c);
547 % </SyntaxCode>
548 stest = true;
549 catch err
550 disp(err.message)
551 stest = false;
552 end
553
554 % <AlgoDescription>
555 %
556 % 1) Check that the shape of the data doesn't change.
557 %
558 % </AlgoDescription>
559
560 atest = true;
561 if stest
562 % <AlgoCode>
563 % The data of at5 is stored as a row vector
564 if size(out1.data.x, 2) ~= 1, atest = false; end
565 if size(out2.data.x, 2) ~= 1, atest = false; end
566 % The data of at6 is stored as a column vector
567 if size(out3.data.x, 1) ~= 1, atest = false; end
568 if size(out4.data.x, 1) ~= 1, atest = false; end
569 % </AlgoCode>
570 else
571 atest = false;
572 end
573
574 % Return a result structure
575 result = utp_prepare_result(atest, stest, dbstack, mfilename);
576 end % END UTP_09
577
578 %% UTP_10
579
580 % <TestDescription>
581 %
582 % Check that the setX method pass back the output objects to a list of
583 % output variables or to a single variable.
584 %
585 % </TestDescription>
586 function result = utp_10
587
588 % <SyntaxDescription>
589 %
590 % Call the method with a list of output variables and with a single output
591 % variable. Additionaly check that the rebuild method works on the output.
592 %
593 % </SyntaxDescription>
594
595 try
596 % <SyntaxCode>
597 [o1, o2] = setX(at5, at6, [1:at5.len]);
598 o3 = setX(at5, at6, [1:at5.len]);
599 mout1 = rebuild(o1);
600 mout2 = rebuild(o2);
601 mout3 = rebuild(o3);
602 % </SyntaxCode>
603 stest = true;
604 catch err
605 disp(err.message)
606 stest = false;
607 end
608
609 % <AlgoDescription>
610 %
611 % 1) Check that the output contains the right number of objects
612 % 2) Check that the 'rebuild' method produces the same object as 'out'.
613 %
614 % </AlgoDescription>
615
616 atest = true;
617 if stest
618 % <AlgoCode>
619 % Check the number of outputs
620 if numel(o1) ~=1, atest = false; end
621 if numel(o2) ~=1, atest = false; end
622 if numel(o3) ~=2, atest = false; end
623 % Check the rebuilding of the object
624 if ~eq(o1, mout1, ple2), atest = false; end
625 if ~eq(o2, mout2, ple2), atest = false; end
626 if ~eq(o3, mout3, ple2), atest = false; end
627 % </AlgoCode>
628 else
629 atest = false;
630 end
631
632 % Return a result structure
633 result = utp_prepare_result(atest, stest, dbstack, mfilename);
634 end % END UTP_10
635
636 end