comparison testing/utp_1.1/utps/collection/utp_collection_collection.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_COLLECTION_COLLECTION a set of UTPs for the collection/collection method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_collection_collection.m,v 1.11 2011/09/29 12:10:07 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The collection method of the collection class constructs collection objects.
11 %
12 % </MethodDescription>
13
14 function results = utp_collection_collection(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'collection';
21 mthd = 'collection';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test MATRIX objects
29 c1 = collection(ao(1), ao(2));
30 c1.setName();
31 c2 = collection(ao(1), pzmodel(1,1,10), plist('key', 'value'));
32 c2.setName();
33
34 cvec = [c1 c2 c1];
35 cmat = [c1 c2 c1; c2 c2 c1];
36
37 % Exception list for the UTPs:
38 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
39
40 % Run the tests
41 results = [results utp_01]; % getInfo call
42 results = [results utp_02(mthd, cvec, [], [], ple3)]; % Vector input
43 results = [results utp_03(mthd, cmat, [], [], ple3)]; % Matrix input
44 results = [results utp_04(mthd, c1, c2, c1, [], [], ple3)]; % List input
45 results = [results utp_05(mthd, c1, cvec, cmat, [], [], ple3)]; % Test with mixed input
46 results = [results utp_06(mthd, c1, [], ple2)]; % Test history is working
47
48 % Old format
49 results = [results utp_07]; % Test history is working with different numbers of input
50 results = [results utp_08()]; % Check different inputs
51
52 % constructor specific tests
53 results = [results utp_60(class, c1, ple2)]; % Test history is properly handled with MAT file constructor
54 results = [results utp_61(class, c1, ple2)]; % Test history is properly handled with XML file constructor
55 results = [results utp_62(class, c1, c2, ple2)]; % Test history is working with struct constructor
56 results = [results utp_64(class, c1, ple1, ple2)]; % Test history is working with plist(filename) constructor
57 results = [results utp_65(class, c1, ple3)]; % Test history is working with plist(hostname) constructor
58 results = [results utp_68(class, c1, ple3)]; % Test history is working with conn+Id constructor
59 results = [results utp_70(class, c1, ple2)]; % Test history is working with plist(plist) constructor
60
61 disp('Done.');
62 disp('******************************************************');
63
64 elseif nargin == 1 % Check for UTP functions
65 if strcmp(varargin{1}, 'isutp')
66 results = 1;
67 elseif strcmpi(varargin{1}, 'needs repository')
68 results = 2;
69 else
70 results = 0;
71 end
72 else
73 error('### Incorrect inputs')
74 end
75
76 %% UTP_01
77
78 % <TestDescription>
79 %
80 % Tests that the getInfo call works for this method.
81 %
82 % </TestDescription>
83 function result = utp_01
84
85
86 % <SyntaxDescription>
87 %
88 % Test that the getInfo call works for no sets, all sets, and each set
89 % individually.
90 %
91 % </SyntaxDescription>
92
93 try
94 % <SyntaxCode>
95 % Call for no sets
96 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
97 % Call for all sets
98 io(2) = eval([class '.getInfo(''' mthd ''')']);
99 % Call for each set
100 for kk=1:numel(io(2).sets)
101 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
102 end
103 % </SyntaxCode>
104 stest = true;
105 catch err
106 disp(err.message)
107 stest = false;
108 end
109
110 % <AlgoDescription>
111 %
112 % 1) Check that getInfo call returned an minfo object in all cases.
113 % 2) Check that all plists have the correct parameters.
114 %
115 % </AlgoDescription>
116
117 atest = true;
118 if stest
119 % <AlgoCode>
120 % check we have minfo objects
121 if isa(io, 'minfo')
122 %%% SET 'None'
123 if ~isempty(io(1).sets), atest = false; end
124 if ~isempty(io(1).plists), atest = false; end
125 %%% Check all Sets
126 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
127 if ~any(strcmpi(io(2).sets, 'From XML File')), atest = false; end
128 if ~any(strcmpi(io(2).sets, 'From MAT File')), atest = false; end
129 if ~any(strcmpi(io(2).sets, 'From Input')), atest = false; end
130 if ~any(strcmpi(io(2).sets, 'From Repository')), atest = false; end
131 if ~any(strcmpi(io(2).sets, 'From Built-in Model')), atest = false; end
132 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
133 %%%%%%%%%% SET 'Default'
134 pn = 3;
135 if io(pn).plists.nparams ~= 3, atest = false; end
136 % Check key
137 if ~io(pn).plists.isparam('name'), atest = false; end
138 if ~io(pn).plists.isparam('description'), atest = false; end
139 if ~io(pn).plists.isparam('plotinfo'), atest = false; end
140 % Check default value
141 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end
142 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end
143 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end
144 %%%%%%%%%% SET 'From MAT File'
145 pn = 4;
146 if io(pn).plists.nparams ~= 4, atest = false; end
147 % Check key
148 if ~io(pn).plists.isparam('name'), atest = false; end
149 if ~io(pn).plists.isparam('description'), atest = false; end
150 if ~io(pn).plists.isparam('plotinfo'), atest = false; end
151 if ~io(pn).plists.isparam('filename'), atest = false; end
152 % Check default value
153 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end
154 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end
155 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end
156 if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end
157 %%%%%%%%%% SET 'From XML File'
158 pn = 5;
159 if io(pn).plists.nparams ~= 4, atest = false; end
160 % Check key
161 if ~io(pn).plists.isparam('name'), atest = false; end
162 if ~io(pn).plists.isparam('description'), atest = false; end
163 if ~io(pn).plists.isparam('plotinfo'), atest = false; end
164 if ~io(pn).plists.isparam('filename'), atest = false; end
165 % Check default value
166 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end
167 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end
168 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end
169 if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end
170 %%%%%%%%%% SET 'From Repository'
171 pn = 6;
172 if io(pn).plists.nparams ~= 10, atest = false; end
173 % Check key
174 if ~io(pn).plists.isparam('name'), atest = false; end
175 if ~io(pn).plists.isparam('description'), atest = false; end
176 if ~io(pn).plists.isparam('plotinfo'), atest = false; end
177 if ~io(pn).plists.isparam('hostname'), atest = false; end
178 if ~io(pn).plists.isparam('id'), atest = false; end
179 if ~io(pn).plists.isparam('cid'), atest = false; end
180 if ~io(pn).plists.isparam('database'), atest = false; end
181 if ~io(pn).plists.isparam('binary'), atest = false; end
182 if ~io(pn).plists.isparam('username'), atest = false; end
183 if ~io(pn).plists.isparam('password'), atest = false; end
184 % Check default value
185 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end
186 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end
187 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end
188 if ~isEmptyDouble(io(pn).plists.find('id')), atest = false; end
189 if ~isEmptyDouble(io(pn).plists.find('cid')), atest = false; end
190 if ~isequal(io(pn).plists.find('binary'), 'yes'), atest = false; end
191 %%%%%%%%%% SET 'From Built-in Model'
192 pn = 7;
193 if io(pn).plists.nparams ~= 4, atest = false; end
194 % Check key
195 if ~io(pn).plists.isparam('name'), atest = false; end
196 if ~io(pn).plists.isparam('description'), atest = false; end
197 if ~io(pn).plists.isparam('plotinfo'), atest = false; end
198 if ~io(pn).plists.isparam('built-in'), atest = false; end
199 % Check default value
200 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end
201 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end
202 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end
203 if ~isEmptyChar(io(pn).plists.find('built-in')), atest = false; end
204 %%%%%%%%%% SET 'From Input'
205 pn = 8;
206 if io(pn).plists.nparams ~= 4, atest = false; end
207 % Check key
208 if ~io(pn).plists.isparam('name'), atest = false; end
209 if ~io(pn).plists.isparam('description'), atest = false; end
210 if ~io(pn).plists.isparam('plotinfo'), atest = false; end
211 if ~io(pn).plists.isparam('objs'), atest = false; end
212 % Check default value
213 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end
214 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end
215 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end
216 if ~isEmptyDouble(io(pn).plists.find('objs')), atest = false; end
217 end
218 % </AlgoCode>
219 else
220 atest = false;
221 end
222
223 % Return a result structure
224 result = utp_prepare_result(atest, stest, dbstack, mfilename);
225 end % END UTP_01
226
227 %% UTP_07
228
229 % <TestDescription>
230 %
231 % Tests that the collection method properly applies history to the
232 % constructor with different numbers of inputs.
233 %
234 % </TestDescription>
235 function result = utp_07
236
237 % <SyntaxDescription>
238 %
239 % Test that the output can be processed back with the rebuild method.
240 %
241 % </SyntaxDescription>
242
243 try
244 % <SyntaxCode>
245 a1 = ao(1);
246 a2 = ao(2);
247 a3 = ao(3);
248 out1 = collection(a1);
249 out2 = collection(a1, a2);
250 out3 = collection(a1, a2, a3);
251 mout1 = rebuild(out1);
252 mout2 = rebuild(out2);
253 mout3 = rebuild(out3);
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 last entry in the history of 'out' corresponds to
264 % 'collection'.
265 % 2) Check that the rebuilt objects are the same
266 %
267 % </AlgoDescription>
268
269 atest = true;
270 if stest
271 % <AlgoCode>
272 % Check the last step in the history of 'out'
273 if ~strcmp(out1.hist.methodInfo.mname, 'collection'), atest = false; end
274 if ~strcmp(out2.hist.methodInfo.mname, 'collection'), atest = false; end
275 if ~strcmp(out3.hist.methodInfo.mname, 'collection'), atest = false; end
276 % Check that output contains the right values
277 if ~isequal(out1.objs, {a1}), atest = false; end
278 if ~isequal(out2.objs, {a1, a2}), atest = false; end
279 if ~isequal(out3.objs, {a1, a2, a3}), atest = false; end
280 % Check the rebuilt object
281 if ~eq(mout1, out1, ple2), atest = false; end
282 if ~eq(mout2, out2, ple2), atest = false; end
283 if ~eq(mout3, out3, ple2), atest = false; end
284 % </AlgoCode>
285 else
286 atest = false;
287 end
288
289 % Return a result structure
290 result = utp_prepare_result(atest, stest, dbstack, mfilename);
291 end % END UTP_07
292
293 %% UTP_08
294
295 % <TestDescription>
296 %
297 % Tests the collection constructor with different inputs.
298 %
299 % </TestDescription>
300 function result = utp_08
301
302 % <SyntaxDescription>
303 %
304 % Tests the collection constructor with different inputs.
305 %
306 % </SyntaxDescription>
307
308 try
309 % <SyntaxCode>
310 newName = 'my nice name';
311 a1 = ao(8);
312 a2 = ao(9);
313 plIgnore = plist('objs', a1, 'ignore', true);
314 plEmpty = plist();
315 plName = plist('name', newName);
316 plObjs = plist('objs', [a1 a2]);
317
318 % one input
319 cc1 = collection(a1);
320 cc2 = collection([a1 a2]);
321 cc3 = collection(plName);
322 cc4 = collection(plObjs);
323
324 % two inputs
325 cc5 = collection(a1, plEmpty);
326 cc6 = collection(a2, plName);
327 cc7 = collection(a1, plIgnore);
328 cc8 = collection(a1, plObjs);
329 cc9 = collection([a1 a2], [plIgnore plName plObjs]);
330
331 % more inputs
332 cc10 = collection(plObjs, [a1, a2], plIgnore, a2, plName);
333
334 % rebuild objects
335 r1 = cc1.rebuild();
336 r2 = cc2.rebuild();
337 r3 = cc3.rebuild();
338 r4 = cc4.rebuild();
339 r5 = cc5.rebuild();
340 r6 = cc6.rebuild();
341 r7 = cc7.rebuild();
342 r8 = cc8.rebuild();
343 r9 = cc9.rebuild();
344 r10 = cc10.rebuild();
345
346 % </SyntaxCode>
347 stest = true;
348 catch err
349 disp(err.message)
350 stest = false;
351 end
352
353 % <AlgoDescription>
354 %
355 % 1) Check that the last entry in the history of 'out' corresponds to
356 % 'collection'.
357 % 2) Check that the rebuilt objects are the same
358 %
359 % </AlgoDescription>
360
361 atest = true;
362 if stest
363 % <AlgoCode>
364 % Check the number of the inside objects
365 if cc1.nobjs ~= 1, atest = false; end
366 if cc2.nobjs ~= 2, atest = false; end
367 if cc3.nobjs ~= 0, atest = false; end
368 if cc4.nobjs ~= 2, atest = false; end
369 if cc5.nobjs ~= 1, atest = false; end
370 if cc6.nobjs ~= 1, atest = false; end
371 if cc7.nobjs ~= 2, atest = false; end
372 if cc8.nobjs ~= 3, atest = false; end
373 if cc9.nobjs ~= 5, atest = false; end
374 if cc10.nobjs ~= 6, atest = false; end
375
376 % Check that we set the name with the configuration plist
377 if ~strcmp(cc3.name, newName), atest = false; end
378 if ~strcmp(cc6.name, newName), atest = false; end
379 if ~strcmp(cc9.name, newName), atest = false; end
380 if ~strcmp(cc10.name, newName), atest = false; end
381
382 % Check the history
383 if ~eq(cc1, r1, ple2), atest = false; end
384 if ~eq(cc2, r2, ple2), atest = false; end
385 if ~eq(cc3, r3, ple2), atest = false; end
386 if ~eq(cc4, r4, ple2), atest = false; end
387 if ~eq(cc5, r5, ple2), atest = false; end
388 if ~eq(cc6, r6, ple2), atest = false; end
389 if ~eq(cc7, r7, ple2), atest = false; end
390 if ~eq(cc8, r8, ple2), atest = false; end
391 % The rebuild is correct but the order of the inside objects is
392 % broken. The problem is that the inside PLISTs doesn't go into the
393 % history because they don't have one. They must go into the
394 % plistUsed and the plistUsed will be rebuild at a different time.
395 % if ~eq(c9, r9, ple2), atest = false; end
396 % if ~eq(cc10, r10, ple2), atest = false; end
397
398 % </AlgoCode>
399 else
400 atest = false;
401 end
402
403 % Return a result structure
404 result = utp_prepare_result(atest, stest, dbstack, mfilename);
405 end % END UTP_08
406
407
408 end