Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/plist/utp_plist_isprop.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_ISPROP a set of UTPs for the plist/isprop method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_plist_isprop.m,v 1.6 2011/03/29 13:13:33 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The isprop method of the plist class determine whether input is object property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_plist_isprop(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'plist'; | |
21 mthd = 'isprop'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test PLIST objects | |
29 [pl1, pl2, pl3, pl4, plv, plm] = get_test_objects_plist; | |
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 the modify call works | |
41 results = [results utp_07]; % Test negative case | |
42 | |
43 disp('Done.'); | |
44 disp('******************************************************'); | |
45 | |
46 elseif nargin == 1 % Check for UTP functions | |
47 if strcmp(varargin{1}, 'isutp') | |
48 results = 1; | |
49 else | |
50 results = 0; | |
51 end | |
52 else | |
53 error('### Incorrect inputs') | |
54 end | |
55 | |
56 %% UTP_01 | |
57 | |
58 % <TestDescription> | |
59 % | |
60 % Tests that the getInfo call works for this method. | |
61 % | |
62 % </TestDescription> | |
63 function result = utp_01 | |
64 | |
65 | |
66 % <SyntaxDescription> | |
67 % | |
68 % Test that the getInfo call works for no sets, all sets, and each set | |
69 % individually. | |
70 % | |
71 % </SyntaxDescription> | |
72 | |
73 try | |
74 % <SyntaxCode> | |
75 % Call for no sets | |
76 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
77 % Call for all sets | |
78 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
79 % Call for each set | |
80 for kk=1:numel(io(2).sets) | |
81 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
82 end | |
83 % </SyntaxCode> | |
84 stest = true; | |
85 catch err | |
86 disp(err.message) | |
87 stest = false; | |
88 end | |
89 | |
90 % <AlgoDescription> | |
91 % | |
92 % 1) Check that getInfo call returned an minfo object in all cases. | |
93 % 2) Check that all plists have the correct parameters. | |
94 % | |
95 % </AlgoDescription> | |
96 | |
97 atest = true; | |
98 if stest | |
99 % <AlgoCode> | |
100 % check we have minfo objects | |
101 if isa(io, 'minfo') | |
102 % SET 'None' | |
103 if ~isempty(io(1).sets), atest = false; end | |
104 if ~isempty(io(1).plists), atest = false; end | |
105 % Check all Sets | |
106 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
107 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
108 % SET 'Default' | |
109 if io(3).plists.nparams ~= 0, atest = false; end | |
110 % Check key | |
111 % Check default value | |
112 % Check options | |
113 end | |
114 % </AlgoCode> | |
115 else | |
116 atest = false; | |
117 end | |
118 | |
119 % Return a result structure | |
120 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
121 end % END UTP_01 | |
122 | |
123 %% UTP_02 | |
124 | |
125 % <TestDescription> | |
126 % | |
127 % Tests that the isprop method works with a vector of PLIST objects as input. | |
128 % | |
129 % </TestDescription> | |
130 function result = utp_02 | |
131 | |
132 % <SyntaxDescription> | |
133 % | |
134 % Test that the isprop method works for a vector of PLIST objects as input. | |
135 % | |
136 % </SyntaxDescription> | |
137 | |
138 try | |
139 % <SyntaxCode> | |
140 out = isprop(plv, 'name'); | |
141 % </SyntaxCode> | |
142 stest = true; | |
143 catch err | |
144 disp(err.message) | |
145 stest = false; | |
146 end | |
147 | |
148 % <AlgoDescription> | |
149 % | |
150 % 1) Check that the number of elements in 'out' is the same as in 'plv' | |
151 % 2) Check that each output contains the correct data. | |
152 % | |
153 % </AlgoDescription> | |
154 | |
155 atest = true; | |
156 if stest | |
157 % <AlgoCode> | |
158 % Check we have the correct number of outputs | |
159 if ~isequal(size(out), size(plv)), atest = false; end | |
160 % Check each output | |
161 if ~all(out), atest = false; end | |
162 % </AlgoCode> | |
163 else | |
164 atest = false; | |
165 end | |
166 | |
167 % Return a result structure | |
168 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
169 end % END UTP_02 | |
170 | |
171 %% UTP_03 | |
172 | |
173 % <TestDescription> | |
174 % | |
175 % Tests that the isprop method works with a matrix of PLIST objects as input. | |
176 % | |
177 % </TestDescription> | |
178 function result = utp_03 | |
179 | |
180 % <SyntaxDescription> | |
181 % | |
182 % Test that the isprop method works for a matrix of PLIST objects as input. | |
183 % | |
184 % </SyntaxDescription> | |
185 | |
186 try | |
187 % <SyntaxCode> | |
188 out = isprop(plm, 'name'); | |
189 % </SyntaxCode> | |
190 stest = true; | |
191 catch err | |
192 disp(err.message) | |
193 stest = false; | |
194 end | |
195 | |
196 % <AlgoDescription> | |
197 % | |
198 % 1) Check that the number of elements in 'out' is the same as in 'plm' | |
199 % 2) Check that each output contains the correct data. | |
200 % | |
201 % </AlgoDescription> | |
202 | |
203 atest = true; | |
204 if stest | |
205 % <AlgoCode> | |
206 % Check we have the correct number of outputs | |
207 if ~isequal(size(out), size(plm)), atest = false; end | |
208 % Check each output | |
209 if ~all(out), atest = false; end | |
210 % </AlgoCode> | |
211 else | |
212 atest = false; | |
213 end | |
214 | |
215 % Return a result structure | |
216 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
217 end % END UTP_03 | |
218 | |
219 %% UTP_04 | |
220 | |
221 % <TestDescription> | |
222 % | |
223 % Tests that the isprop method works with a list of PLIST objects as input. | |
224 % | |
225 % </TestDescription> | |
226 function result = utp_04 | |
227 | |
228 % <SyntaxDescription> | |
229 % | |
230 % Test that the isprop method works for a list of PLIST objects as input. | |
231 % | |
232 % </SyntaxDescription> | |
233 | |
234 try | |
235 % <SyntaxCode> | |
236 out = isprop(pl4,pl3,pl2, 'name'); | |
237 % </SyntaxCode> | |
238 stest = true; | |
239 catch err | |
240 disp(err.message) | |
241 stest = false; | |
242 end | |
243 | |
244 % <AlgoDescription> | |
245 % | |
246 % 1) Check that the number of elements in 'out' is the same as in | |
247 % input. | |
248 % 2) Check that each output contains the correct data. | |
249 % | |
250 % </AlgoDescription> | |
251 | |
252 atest = true; | |
253 if stest | |
254 % <AlgoCode> | |
255 % Check we have the correct number of outputs | |
256 if numel(out) ~= 3, atest = false; end | |
257 % Check each output | |
258 if ~all(out), atest = false; end | |
259 % </AlgoCode> | |
260 else | |
261 atest = false; | |
262 end | |
263 | |
264 % Return a result structure | |
265 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
266 end % END UTP_04 | |
267 | |
268 %% UTP_05 | |
269 | |
270 % <TestDescription> | |
271 % | |
272 % Tests that the isprop method works with a mix of different shaped | |
273 % PLIST objects as input. | |
274 % | |
275 % </TestDescription> | |
276 function result = utp_05 | |
277 | |
278 % <SyntaxDescription> | |
279 % | |
280 % Test that the isprop method works with an input of matrices and vectors | |
281 % and single PLIST objects. | |
282 % | |
283 % </SyntaxDescription> | |
284 | |
285 try | |
286 % <SyntaxCode> | |
287 out = isprop(pl4,plv,pl3,plm,pl2, 'name'); | |
288 % </SyntaxCode> | |
289 stest = true; | |
290 catch err | |
291 disp(err.message) | |
292 stest = false; | |
293 end | |
294 | |
295 % <AlgoDescription> | |
296 % | |
297 % 1) Check that the number of elements in 'out' is the same as in | |
298 % input. | |
299 % 2) Check that each output contains the correct data. | |
300 % | |
301 % </AlgoDescription> | |
302 | |
303 atest = true; | |
304 if stest | |
305 % <AlgoCode> | |
306 % Check we have the correct number of outputs | |
307 if numel(out) ~= (3+numel(plm)+numel(plv)), atest = false; end | |
308 % Check each output | |
309 if ~all(out), atest = false; end | |
310 % </AlgoCode> | |
311 else | |
312 atest = false; | |
313 end | |
314 | |
315 % Return a result structure | |
316 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
317 end % END UTP_05 | |
318 | |
319 %% UTP_06 | |
320 | |
321 % <TestDescription> | |
322 % | |
323 % Tests that the isprop method works for each property. | |
324 % | |
325 % </TestDescription> | |
326 function result = utp_06 | |
327 | |
328 % <SyntaxDescription> | |
329 % | |
330 % Test that the isprop method works for the properties: | |
331 % 'params', 'created', 'creator', 'name' | |
332 % | |
333 % </SyntaxDescription> | |
334 | |
335 try | |
336 % <SyntaxCode> | |
337 % copy pl4 to work with | |
338 out1 = isprop(pl4, 'params'); | |
339 out5 = isprop(pl4, 'name'); | |
340 % </SyntaxCode> | |
341 stest = true; | |
342 catch err | |
343 disp(err.message) | |
344 stest = false; | |
345 end | |
346 | |
347 % <AlgoDescription> | |
348 % | |
349 % 1) Check that each output contains the correct data. | |
350 % | |
351 % </AlgoDescription> | |
352 | |
353 atest = true; | |
354 if stest | |
355 % <AlgoCode> | |
356 if ~out1, atest = false; end; | |
357 if ~out5, 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 negative case and the not function command. | |
372 % | |
373 % </TestDescription> | |
374 function result = utp_07 | |
375 | |
376 % <SyntaxDescription> | |
377 % | |
378 % Test that the isprop method retrun false for a unknown property and for | |
379 % methods of the object. | |
380 % | |
381 % </SyntaxDescription> | |
382 | |
383 try | |
384 % <SyntaxCode> | |
385 out1 = isprop(pl2, 'foo'); | |
386 out2 = pl2.isprop('foo'); | |
387 out3 = pl2.isprop('name'); | |
388 out4 = pl2.isprop('type'); | |
389 out5 = pl2.isprop('char'); | |
390 % REMARK: In the ltpda_uoh class are the properties 'created' and | |
391 % 'creator' methods which gets the value from the history | |
392 % </SyntaxCode> | |
393 stest = true; | |
394 catch err | |
395 disp(err.message) | |
396 stest = false; | |
397 end | |
398 | |
399 % <AlgoDescription> | |
400 % | |
401 % 1) Check that each output contains the correct data. | |
402 % | |
403 % </AlgoDescription> | |
404 | |
405 atest = true; | |
406 if stest | |
407 % <AlgoCode> | |
408 if out1, atest = false; end; | |
409 if out2, atest = false; end; | |
410 if ~out3, atest = false; end; | |
411 if out4, atest = false; end; | |
412 if out5, atest = false; end; | |
413 % </AlgoCode> | |
414 else | |
415 atest = false; | |
416 end | |
417 | |
418 % Return a result structure | |
419 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
420 end % END UTP_07 | |
421 | |
422 end |