Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/plist/utp_plist_eq.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_PLIST_EQ a set of UTPs for the plist/eq method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_plist_eq.m,v 1.5 2010/11/19 12:33:33 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The eq() method of the plist class pl1 == pl2 compares each element of an | |
11 % plist object with the corresponding element of an second plist object and returns | |
12 % a logical 1 (true) where pl1 and pl2 are equal, or logical 0 (false) | |
13 % where they are not equal. | |
14 % | |
15 % </MethodDescription> | |
16 | |
17 function results = utp_plist_eq(varargin) | |
18 | |
19 % Check the inputs | |
20 if nargin == 0 | |
21 | |
22 % Some keywords | |
23 class = 'plist'; | |
24 mthd = 'eq'; | |
25 | |
26 results = []; | |
27 disp('******************************************************'); | |
28 disp(['**** Running UTPs for ' class '/' mthd]); | |
29 disp('******************************************************'); | |
30 | |
31 % Test PLIST objects | |
32 [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist; | |
33 | |
34 % Exception list for the UTPs: | |
35 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
36 | |
37 % Run the tests | |
38 results = [results utp_01]; % getInfo call | |
39 results = [results utp_02]; % Vector input | |
40 results = [results utp_03]; % Matrix input | |
41 results = [results utp_04]; % List input | |
42 results = [results utp_05]; % Test with mixed input | |
43 results = [results utp_06]; % Test with the exception list 'name' | |
44 results = [results utp_07]; % Test exception list in a plist | |
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 number of SETS | |
109 if numel(io(2).sets) ~= 1, atest = false; end | |
110 % Check all Sets | |
111 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
112 % SET 'Default' | |
113 % Check key | |
114 if ~io(3).plists.isparam('Exceptions'), atest = false; end | |
115 if ~io(3).plists.isparam('Tol'), atest = false; end | |
116 % Check default value | |
117 if ~isequal(io(3).plists.find('Exceptions'), {}), atest = false; end | |
118 if ~isequal(io(3).plists.find('Tol'), eps(1)), atest = false; end | |
119 % Check options | |
120 if ~isequal(io(3).plists.getOptionsForParam('Exceptions'), {{}}), atest = false; end | |
121 if ~isequal(io(3).plists.getOptionsForParam('Tol'), {eps(1)}), atest = false; end | |
122 end | |
123 % </AlgoCode> | |
124 else | |
125 atest = false; | |
126 end | |
127 | |
128 % Return a result structure | |
129 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
130 end % END UTP_01 | |
131 | |
132 %% UTP_02 | |
133 | |
134 % <TestDescription> | |
135 % | |
136 % Tests that the eq method works with a vector of PLIST objects as input. | |
137 % | |
138 % </TestDescription> | |
139 function result = utp_02 | |
140 | |
141 % <SyntaxDescription> | |
142 % | |
143 % Test that the eq method works for a vector of PLIST objects as input. | |
144 % Test the positive and the negative case. | |
145 % | |
146 % </SyntaxDescription> | |
147 | |
148 try | |
149 % <SyntaxCode> | |
150 pl = pl1.setName('my name'); | |
151 plv1 = [pl1, pl3, pl2, pl4]; | |
152 plv2 = [pl1, pl3, pl2, pl]; | |
153 out1 = eq(plv1, plv1); | |
154 out2 = eq(plv1, plv2); | |
155 % </SyntaxCode> | |
156 stest = true; | |
157 catch err | |
158 disp(err.message) | |
159 stest = false; | |
160 end | |
161 | |
162 % <AlgoDescription> | |
163 % | |
164 % 1) Check the output of the eq function. | |
165 % | |
166 % </AlgoDescription> | |
167 | |
168 atest = true; | |
169 if stest | |
170 % <AlgoCode> | |
171 if out1 ~= 1, atest = false; end | |
172 if out2 ~= 0, atest = false; 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 eq method works with a matrix of PLIST objects as input. | |
187 % | |
188 % </TestDescription> | |
189 function result = utp_03 | |
190 | |
191 % <SyntaxDescription> | |
192 % | |
193 % Test that the eq method works for a matrix of PLIST objects as input. | |
194 % Test the positive and the negative case. | |
195 % | |
196 % </SyntaxDescription> | |
197 | |
198 try | |
199 % <SyntaxCode> | |
200 pl = pl4.setName('my name'); | |
201 plm1 = [pl1, pl3, pl4, pl4, pl2, pl1]; | |
202 plm2 = [pl1, pl3, pl; pl4, pl2, pl1]; | |
203 out1 = eq(plm1, plm1); | |
204 out2 = eq(plm1, plm2); | |
205 % </SyntaxCode> | |
206 stest = true; | |
207 catch err | |
208 disp(err.message) | |
209 stest = false; | |
210 end | |
211 | |
212 % <AlgoDescription> | |
213 % | |
214 % 1) Check the output of the eq function. | |
215 % | |
216 % </AlgoDescription> | |
217 | |
218 atest = true; | |
219 if stest | |
220 % <AlgoCode> | |
221 if out1 ~= 1, atest = false; end | |
222 if out2 ~= 0, atest = false; end | |
223 % </AlgoCode> | |
224 else | |
225 atest = false; | |
226 end | |
227 | |
228 % Return a result structure | |
229 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
230 end % END UTP_03 | |
231 | |
232 %% UTP_04 | |
233 | |
234 % <TestDescription> | |
235 % | |
236 % Tests that the eq method works with a list of PLIST objects as input. | |
237 % | |
238 % </TestDescription> | |
239 function result = utp_04 | |
240 | |
241 % <SyntaxDescription> | |
242 % | |
243 % The eq method doesn't works for a list of PLIST objects as input. | |
244 % Nothing to do. | |
245 % | |
246 % </SyntaxDescription> | |
247 | |
248 try | |
249 % <SyntaxCode> | |
250 % </SyntaxCode> | |
251 stest = true; | |
252 catch err | |
253 disp(err.message) | |
254 stest = false; | |
255 end | |
256 | |
257 % <AlgoDescription> | |
258 % | |
259 % </AlgoDescription> | |
260 | |
261 atest = true; | |
262 if stest | |
263 % <AlgoCode> | |
264 % </AlgoCode> | |
265 else | |
266 atest = false; | |
267 end | |
268 | |
269 % Return a result structure | |
270 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
271 end % END UTP_04 | |
272 | |
273 %% UTP_05 | |
274 | |
275 % <TestDescription> | |
276 % | |
277 % Tests that the eq method works with a mix of different shaped PLIST objects | |
278 % as input. | |
279 % | |
280 % </TestDescription> | |
281 function result = utp_05 | |
282 | |
283 % <SyntaxDescription> | |
284 % | |
285 % The eq method doesn't works for a list of PLIST objects as input. | |
286 % Nothing to do. | |
287 % | |
288 % </SyntaxDescription> | |
289 | |
290 try | |
291 % <SyntaxCode> | |
292 % </SyntaxCode> | |
293 stest = true; | |
294 catch err | |
295 disp(err.message) | |
296 stest = false; | |
297 end | |
298 | |
299 % <AlgoDescription> | |
300 % | |
301 % </AlgoDescription> | |
302 | |
303 atest = true; | |
304 if stest | |
305 % <AlgoCode> | |
306 % </AlgoCode> | |
307 else | |
308 atest = false; | |
309 end | |
310 | |
311 % Return a result structure | |
312 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
313 end % END UTP_05 | |
314 | |
315 %% UTP_06 | |
316 | |
317 % <TestDescription> | |
318 % | |
319 % Test the eq method with an exception list. | |
320 % With the LTPDA toolbox 2.0 it is only possible to test the exception list | |
321 % with properties where a public set method exist. | |
322 % | |
323 % </TestDescription> | |
324 function result = utp_06 | |
325 | |
326 % <SyntaxDescription> | |
327 % | |
328 % Test the eq method with the exception 'name'. It is necessary to add | |
329 % 'created' to the exception list because pl is created at an other time. | |
330 % | |
331 % </SyntaxDescription> | |
332 | |
333 try | |
334 % <SyntaxCode> | |
335 pl = pl4.setName('my name'); | |
336 out1 = eq(pl, pl4); | |
337 out2 = eqLocal(pl, pl4, 'name'); | |
338 out3 = eqLocal(pl, pl4, 'plist/name'); | |
339 % </SyntaxCode> | |
340 stest = true; | |
341 catch err | |
342 disp(err.message) | |
343 stest = false; | |
344 end | |
345 | |
346 % <AlgoDescription> | |
347 % | |
348 % 1) Check the output. | |
349 % | |
350 % </AlgoDescription> | |
351 | |
352 atest = true; | |
353 if stest | |
354 % <AlgoCode> | |
355 if out1 ~= 0, atest = false; end | |
356 if out2 ~= 1, atest = false; end | |
357 if out3 ~= 1, atest = false; end | |
358 % </AlgoCode> | |
359 else | |
360 atest = false; | |
361 end | |
362 | |
363 % Return a result structure | |
364 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
365 end % END UTP_06 | |
366 | |
367 %% UTP_07 | |
368 | |
369 % <TestDescription> | |
370 % | |
371 % Test the eq method with an exception list which is in a plist. | |
372 % | |
373 % </TestDescription> | |
374 function result = utp_07 | |
375 | |
376 % <SyntaxDescription> | |
377 % | |
378 % Test that the eq method uses the exception list in a plist. | |
379 % | |
380 % </SyntaxDescription> | |
381 | |
382 try | |
383 % <SyntaxCode> | |
384 pl = pl4.setName('my name'); | |
385 out1 = eq(pl, pl4); | |
386 out2 = eq(pl, pl4, ple2); | |
387 out3 = eq(pl, pl4, ple2); | |
388 % </SyntaxCode> | |
389 stest = true; | |
390 catch err | |
391 disp(err.message) | |
392 stest = false; | |
393 end | |
394 | |
395 % <AlgoDescription> | |
396 % | |
397 % 1) Check the output. | |
398 % | |
399 % </AlgoDescription> | |
400 | |
401 atest = true; | |
402 if stest | |
403 % <AlgoCode> | |
404 % Check the shape of the output data | |
405 if out1 ~= 0, atest = false; end | |
406 if out2 ~= 1, atest = false; end | |
407 if out3 ~= 1, atest = false; end | |
408 % </AlgoCode> | |
409 else | |
410 atest = false; | |
411 end | |
412 | |
413 % Return a result structure | |
414 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
415 end % END UTP_07 | |
416 | |
417 function res = eqLocal(obj1, obj2, ex) | |
418 e = ple1.find('EXCEPTIONS'); | |
419 ple = plist('EXCEPTIONS', [e {ex}]); | |
420 | |
421 res = eq(obj1, obj2, ple); | |
422 end | |
423 end |