comparison testing/utp_1.1/utps/matrix/utp_matrix_ncols.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_NCOLS a set of UTPs for the matrix/ncols method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_matrix_ncols.m,v 1.1 2009/08/28 13:20:19 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The ncols method of the matrix class is a get-function for the number of
11 % columns of the inner objects
12 %
13 % </MethodDescription>
14
15 function results = utp_matrix_ncols(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'matrix';
22 mthd = 'ncols';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test MATRIX objects
30 [ma1,ma2,ma3,ma4,mav,mam] = get_test_objects_matrix;
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 method
43
44 disp('Done.');
45 disp('******************************************************');
46
47 elseif nargin == 1 % Check for UTP functions
48 if strcmp(varargin{1}, 'isutp')
49 results = 1;
50 else
51 results = 0;
52 end
53 else
54 error('### Incorrect inputs')
55 end
56
57 %% UTP_01
58
59 % <TestDescription>
60 %
61 % Tests that the getInfo call works for this method.
62 %
63 % </TestDescription>
64 function result = utp_01
65
66
67 % <SyntaxDescription>
68 %
69 % Test that the getInfo call works for no sets, all sets, and each set
70 % individually.
71 %
72 % </SyntaxDescription>
73
74 try
75 % <SyntaxCode>
76 % Call for no sets
77 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
78 % Call for all sets
79 io(2) = eval([class '.getInfo(''' mthd ''')']);
80 % Call for each set
81 for kk=1:numel(io(2).sets)
82 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
83 end
84 % </SyntaxCode>
85 stest = true;
86 catch err
87 disp(err.message)
88 stest = false;
89 end
90
91 % <AlgoDescription>
92 %
93 % 1) Check that getInfo call returned an minfo object in all cases.
94 % 2) Check that all plists have the correct parameters.
95 %
96 % </AlgoDescription>
97
98 atest = true;
99 if stest
100 % <AlgoCode>
101 % check we have minfo objects
102 if isa(io, 'minfo')
103 % SET 'None'
104 if ~isempty(io(1).sets), atest = false; end
105 if ~isempty(io(1).plists), atest = false; end
106 % Check all Sets
107 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
108 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
109 % SET 'Default'
110 if io(3).plists.nparams ~= 0, atest = false; end
111 % Check key
112 % Check default value
113 % Check options
114 end
115 % </AlgoCode>
116 else
117 atest = false;
118 end
119
120 % Return a result structure
121 result = utp_prepare_result(atest, stest, dbstack, mfilename);
122 end % END UTP_01
123
124 %% UTP_02
125
126 % <TestDescription>
127 %
128 % Tests that the ncols method works with a vector of MATRICES as input.
129 %
130 % </TestDescription>
131 function result = utp_02
132
133 % <SyntaxDescription>
134 %
135 % The ncols method doesn't work with a vector of MATRICES.
136 % Nothing to do
137 %
138 % </SyntaxDescription>
139
140 try
141 % <SyntaxCode>
142 % </SyntaxCode>
143 stest = true;
144 catch err
145 disp(err.message)
146 stest = false;
147 end
148
149 % <AlgoDescription>
150 %
151 % </AlgoDescription>
152
153 atest = true;
154 if stest
155 % <AlgoCode>
156 % </AlgoCode>
157 else
158 atest = false;
159 end
160
161 % Return a result structure
162 result = utp_prepare_result(atest, stest, dbstack, mfilename);
163 end % END UTP_02
164
165 %% UTP_03
166
167 % <TestDescription>
168 %
169 % Tests that the ncols method works with a matrix of MATRICES as input.
170 %
171 % </TestDescription>
172 function result = utp_03
173
174 % <SyntaxDescription>
175 %
176 % The ncols method doesn't work with a matrix of MATRICES.
177 % Nothing to do.
178 %
179 % </SyntaxDescription>
180
181 try
182 % <SyntaxCode>
183 % </SyntaxCode>
184 stest = true;
185 catch err
186 disp(err.message)
187 stest = false;
188 end
189
190 % <AlgoDescription>
191 %
192 % </AlgoDescription>
193
194 atest = true;
195 if stest
196 % <AlgoCode>
197 % </AlgoCode>
198 else
199 atest = false;
200 end
201
202 % Return a result structure
203 result = utp_prepare_result(atest, stest, dbstack, mfilename);
204 end % END UTP_03
205
206 %% UTP_04
207
208 % <TestDescription>
209 %
210 % Tests that the ncols method works with a list of MATRICES as input.
211 %
212 % </TestDescription>
213 function result = utp_04
214
215 % <SyntaxDescription>
216 %
217 % The ncols method doesn't work with a list of MATRICES.
218 % Nothing to do.
219 %
220 % </SyntaxDescription>
221
222 try
223 % <SyntaxCode>
224 % </SyntaxCode>
225 stest = true;
226 catch err
227 disp(err.message)
228 stest = false;
229 end
230
231 % <AlgoDescription>
232 %
233 % </AlgoDescription>
234
235 atest = true;
236 if stest
237 % <AlgoCode>
238 % </AlgoCode>
239 else
240 atest = false;
241 end
242
243 % Return a result structure
244 result = utp_prepare_result(atest, stest, dbstack, mfilename);
245 end % END UTP_04
246
247 %% UTP_05
248
249 % <TestDescription>
250 %
251 % Tests that the ncols method works with a mix of different shaped
252 % MATRICES as input.
253 %
254 % </TestDescription>
255 function result = utp_05
256
257 % <SyntaxDescription>
258 %
259 % The ncols method can only return the ncols values of one MATRIX.
260 % Nothing to do
261 %
262 % </SyntaxDescription>
263
264 try
265 % <SyntaxCode>
266 % </SyntaxCode>
267 stest = true;
268 catch err
269 disp(err.message)
270 stest = false;
271 end
272
273 % <AlgoDescription>
274 %
275 % </AlgoDescription>
276
277 atest = true;
278 if stest
279 % <AlgoCode>
280 % </AlgoCode>
281 else
282 atest = false;
283 end
284
285 % Return a result structure
286 result = utp_prepare_result(atest, stest, dbstack, mfilename);
287 end % END UTP_05
288
289 %% UTP_06
290
291 % <TestDescription>
292 %
293 % Tests that the ncols method properly applies history.
294 %
295 % </TestDescription>
296 function result = utp_06
297
298 % <SyntaxDescription>
299 %
300 % The ncols method doesn't change the MATRIX, thus will no history added.
301 % Nothing to do
302 %
303 % </SyntaxDescription>
304
305 try
306 % <SyntaxCode>
307 % </SyntaxCode>
308 stest = true;
309 catch err
310 disp(err.message)
311 stest = false;
312 end
313
314 % <AlgoDescription>
315 %
316 % </AlgoDescription>
317
318 atest = true;
319 if stest
320 % <AlgoCode>
321 % </AlgoCode>
322 else
323 atest = false;
324 end
325
326 % Return a result structure
327 result = utp_prepare_result(atest, stest, dbstack, mfilename);
328 end % END UTP_06
329
330 %% UTP_07
331
332 % <TestDescription>
333 %
334 % Tests that the ncols method returns the number of columns of the inner
335 % objects.
336 %
337 % </TestDescription>
338 function result = utp_07
339
340 % <SyntaxDescription>
341 %
342 % Tests that the ncols method returns the number of columns of the inner
343 % objects.
344 %
345 % </SyntaxDescription>
346
347 try
348 % <SyntaxCode>
349 objs1 = [ao(1), ao(2), ao(3); ao(4), ao(5), ao(6)];
350 objs2 = [miir, miir; miir miir; miir miir];
351 m1 = matrix(objs1);
352 m2 = matrix(objs2);
353 n1 = m1.ncols;
354 n2 = m2.ncols;
355 % </SyntaxCode>
356 stest = true;
357 catch err
358 disp(err.message)
359 stest = false;
360 end
361
362 % <AlgoDescription>
363 %
364 % 1) Check that n1 and n2 are correct.
365 %
366 % </AlgoDescription>
367
368 atest = true;
369 if stest
370 % <AlgoCode>
371 if ~isequal(n1, size(m1.objs, 2)), atest = false; end;
372 if ~isequal(n2, size(m2.objs, 2)), atest = false; end;
373 % </AlgoCode>
374 else
375 atest = false;
376 end
377
378 % Return a result structure
379 result = utp_prepare_result(atest, stest, dbstack, mfilename);
380 end % END UTP_07
381
382 end