comparison testing/utp_1.1/utps/matrix/utp_matrix_ctranspose.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_MATRIX_CTRANSPOSE a set of UTPs for the matrix/ctranspose method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_matrix_ctranspose.m,v 1.4 2010/12/22 16:05:18 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The ctranspose method of the matrix transpose the inner objects.
11 %
12 % </MethodDescription>
13
14 function results = utp_matrix_ctranspose(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'matrix';
21 mthd = 'ctranspose';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test MATRIX objects
29 [ma1,ma2,ma3,ma4,mav,mam] = get_test_objects_matrix;
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]; % Test that the method accepts plists
43 results = [results utp_11(mthd, ma1, ple1, plist('NAME', 'foo'))]; % 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 if io(3).plists.nparams ~= 0, atest = false; end
112 % Check key
113 % Check default value
114 % Check options
115 end
116 % </AlgoCode>
117 else
118 atest = false;
119 end
120
121 % Return a result structure
122 result = utp_prepare_result(atest, stest, dbstack, mfilename);
123 end % END UTP_01
124
125 %% UTP_02
126
127 % <TestDescription>
128 %
129 % Tests that the ctranspose method works with a vector of MATRICES as input.
130 %
131 % </TestDescription>
132 function result = utp_02
133
134 % <SyntaxDescription>
135 %
136 % Test that the ctranspose method works for a vector of MATRICES as input.
137 %
138 % </SyntaxDescription>
139
140 try
141 % <SyntaxCode>
142 out = ctranspose(mav);
143 % </SyntaxCode>
144 stest = true;
145 catch err
146 disp(err.message)
147 stest = false;
148 end
149
150 % <AlgoDescription>
151 %
152 % 1) Check that the number of elements in 'out' is the same as in 'mav'
153 % 2) Check that each output 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 ~isequal(size(out), size(mav)), atest = false; end
162 % Check 'objs' field of each output
163 for oo = 1:numel(out)
164 s = size(out(oo));
165 for ll = 1:numel(s(1))
166 for rr = 1:numel(s(2))
167 if ~eq(out(oo).objs(ll,rr), mav(oo).objs(rr,ll), 'UUID'), atest = false; break; end
168 end
169 end
170 end
171 % </AlgoCode>
172 else
173 atest = false;
174 end
175
176 % Return a result structure
177 result = utp_prepare_result(atest, stest, dbstack, mfilename);
178 end % END UTP_02
179
180 %% UTP_03
181
182 % <TestDescription>
183 %
184 % Tests that the ctranspose method works with a matrix of MATRICES as input.
185 %
186 % </TestDescription>
187 function result = utp_03
188
189 % <SyntaxDescription>
190 %
191 % Test that the ctranspose method works for a matrix of MATRICES as input.
192 %
193 % </SyntaxDescription>
194
195 try
196 % <SyntaxCode>
197 out = ctranspose(mam);
198 % </SyntaxCode>
199 stest = true;
200 catch err
201 disp(err.message)
202 stest = false;
203 end
204
205 % <AlgoDescription>
206 %
207 % 1) Check that the number of elements in 'out' is the same as in 'mam'
208 % 2) Check that each output contains the correct data.
209 %
210 % </AlgoDescription>
211
212 atest = true;
213 if stest
214 % <AlgoCode>
215 % Check we have the correct number of outputs
216 if ~isequal(size(out), size(mam)), atest = false; end
217 % Check 'objs' field of each output
218 for oo = 1:numel(out)
219 s = size(out(oo));
220 for ll = 1:numel(s(1))
221 for rr = 1:numel(s(2))
222 if ~eq(out(oo).objs(ll,rr), mam(oo).objs(rr,ll), 'UUID'), atest = false; break; end
223 end
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 ctranspose method works with a list of MATRICES as input.
240 %
241 % </TestDescription>
242 function result = utp_04
243
244 % <SyntaxDescription>
245 %
246 % Test that the ctranspose method works for a list of MATRICES as input.
247 %
248 % </SyntaxDescription>
249
250 try
251 % <SyntaxCode>
252 out = ctranspose(ma1,ma2,ma3);
253 % </SyntaxCode>
254 stest = true;
255 catch err
256 disp(err.message)
257 stest = false;
258 end
259
260 % <AlgoDescription>
261 %
262 % 1) Check that the number of elements in 'out' is the same as in
263 % input.
264 % 2) Check that each output contains the correct data.
265 %
266 % </AlgoDescription>
267
268 atest = true;
269 main = [ma1, ma2, ma3];
270 if stest
271 % <AlgoCode>
272 % Check we have the correct number of outputs
273 if ~isequal(size(out), size(main)), atest = false; end
274 % Check 'objs' field of each output
275 for oo = 1:numel(out)
276 s = size(out(oo));
277 for ll = 1:numel(s(1))
278 for rr = 1:numel(s(2))
279 if ~eq(out(oo).objs(ll,rr), main(oo).objs(rr,ll), 'UUID'), atest = false; break; end
280 end
281 end
282 end
283 % </AlgoCode>
284 else
285 atest = false;
286 end
287
288 % Return a result structure
289 result = utp_prepare_result(atest, stest, dbstack, mfilename);
290 end % END UTP_04
291
292 %% UTP_05
293
294 % <TestDescription>
295 %
296 % Tests that the ctranspose method works with a mix of different shaped
297 % MATRICES as input.
298 %
299 % </TestDescription>
300 function result = utp_05
301
302 % <SyntaxDescription>
303 %
304 % Test that the ctranspose method works with an input of matrices and
305 % vectors and single MATRICES.
306 %
307 % </SyntaxDescription>
308
309 try
310 % <SyntaxCode>
311 out = ctranspose(ma1,mav,ma2,mam);
312 % </SyntaxCode>
313 stest = true;
314 catch err
315 disp(err.message)
316 stest = false;
317 end
318
319 % <AlgoDescription>
320 %
321 % 1) Check that the number of elements in 'out' is the same as in
322 % input.
323 % 2) Check that each output contains the correct data.
324 %
325 % </AlgoDescription>
326
327 atest = true;
328 main = [ma1, reshape(mav, 1, []), ma2, reshape(mam, 1, [])];
329 if stest
330 % <AlgoCode>
331 % Check we have the correct number of outputs
332 if ~isequal(size(out), size(main)), atest = false; end
333 % Check 'objs' field of each output
334 for oo = 1:numel(out)
335 s = size(out(oo));
336 for ll = 1:numel(s(1))
337 for rr = 1:numel(s(2))
338 if ~eq(out(oo).objs(ll,rr), main(oo).objs(rr,ll), 'UUID'), atest = false; break; end
339 end
340 end
341 end
342 % </AlgoCode>
343 else
344 atest = false;
345 end
346
347 % Return a result structure
348 result = utp_prepare_result(atest, stest, dbstack, mfilename);
349 end % END UTP_05
350
351 %% UTP_06
352
353 % <TestDescription>
354 %
355 % Tests that the ctranspose method properly applies history.
356 %
357 % </TestDescription>
358 function result = utp_06
359
360 % <SyntaxDescription>
361 %
362 % Test that the result of applying the ctranspose method can be
363 % processed back.
364 %
365 % </SyntaxDescription>
366
367 try
368 % <SyntaxCode>
369 out = ctranspose(ma1);
370 mout = rebuild(out);
371 % </SyntaxCode>
372 stest = true;
373 catch err
374 disp(err.message)
375 stest = false;
376 end
377
378 % <AlgoDescription>
379 %
380 % 1) Check that the last entry in the history of 'out' corresponds to
381 % 'ctranspose'.
382 % 2) Check that the re-built object is the same object as 'out'.
383 %
384 % </AlgoDescription>
385
386 atest = true;
387 if stest
388 % <AlgoCode>
389 % Check the last step in the history of 'out1'
390 if ~strcmp(out.hist.methodInfo.mname, 'transpose'),atest = false; end
391 % Check the re-built object
392 if ~eq(mout, out, ple2), atest = false; end
393 % </AlgoCode>
394 else
395 atest = false;
396 end
397
398 % Return a result structure
399 result = utp_prepare_result(atest, stest, dbstack, mfilename);
400 end % END UTP_06
401
402 %% UTP_07
403
404 % <TestDescription>
405 %
406 % Tests that the ctranspose method can modify the input MATRIX.
407 %
408 % </TestDescription>
409 function result = utp_07
410
411 % <SyntaxDescription>
412 %
413 % Test that the ctranspose method can modify the input MATRIX by calling
414 % with no output.
415 %
416 % </SyntaxDescription>
417
418 try
419 % <SyntaxCode>
420 obj_modi = copy(ma1,1);
421 obj_eq = copy(ma1,1);
422
423 out = obj_eq.ctranspose();
424 obj_modi.ctranspose();
425 % </SyntaxCode>
426 stest = true;
427 catch err
428 disp(err.message)
429 stest = false;
430 end
431
432 % <AlgoDescription>
433 %
434 % 1) Check that 'out' and 'obj_eq' are now different.
435 % 2) Check that 'obj_eq' is not changed
436 % 3) Check that the modified input is the ctranspose value of the copy
437 % 4) Check that out and amodi are the same
438 %
439 % </AlgoDescription>
440
441 atest = true;
442 if stest
443 % <AlgoCode>
444 % Check that 'out' and 'obj_eq' are now different.
445 if eq(out, obj_eq, ple2), atest = false; end
446 % Check that 'obj_eq' is not changed
447 if ~eq(obj_eq, ma1, ple1), atest = false; end
448 % Check 'objs' field of each output
449 for oo = 1:numel(out)
450 s = size(out(oo));
451 for ll = 1:numel(s(1))
452 for rr = 1:numel(s(2))
453 if ~eq(out(oo).objs(ll,rr), ma1(oo).objs(rr,ll), 'UUID'), atest = false; break; end
454 end
455 end
456 end
457 % Check that out and obj_modi are the same
458 if ~eq(out, obj_modi, ple1), atest = false; end
459 % </AlgoCode>
460 else
461 atest = false;
462 end
463
464 % Return a result structure
465 result = utp_prepare_result(atest, stest, dbstack, mfilename);
466 end % END UTP_07
467
468 %% UTP_08
469
470 % <TestDescription>
471 %
472 % Tests that the ctranspose method accepts plist as an input.
473 %
474 % </TestDescription>
475 function result = utp_08
476
477 % <SyntaxDescription>
478 %
479 % Tests that the ctranspose method accepts plist as an input.
480 %
481 % </SyntaxDescription>
482
483 try
484 % <SyntaxCode>
485 out = ma1.ctranspose(plist());
486 mout = rebuild(out);
487 % </SyntaxCode>
488 stest = true;
489 catch err
490 disp(err.message)
491 stest = false;
492 end
493
494 % <AlgoDescription>
495 %
496 % 1) Check that the correct data
497 % 2) Check that the re-built object is the same object as 'out'.
498 %
499 % </AlgoDescription>
500
501 atest = true;
502 if stest
503 % <AlgoCode>
504 % Check 'objs' field of each output
505 for oo = 1:numel(out)
506 s = size(out(oo));
507 for ll = 1:numel(s(1))
508 for rr = 1:numel(s(2))
509 if ~eq(out(oo).objs(ll,rr), ma1(oo).objs(rr,ll), 'UUID'), atest = false; break; end
510 end
511 end
512 end
513 % Check the re-built object
514 if ~eq(mout, out, ple2), atest = false; end
515 % </AlgoCode>
516 else
517 atest = false;
518 end
519
520 % Return a result structure
521 result = utp_prepare_result(atest, stest, dbstack, mfilename);
522 end % END UTP_08
523
524 end