Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/mfir/utp_mfir_setHistout.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_MFIR_SETHISTOUT a set of UTPs for the mfir/setHistout method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_mfir_setHistout.m,v 1.7 2011/04/19 18:14:01 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The setHistout method of the mfir class sets the histout property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_mfir_setHistout(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'mfir'; | |
21 mthd = 'setHistout'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test MFIR objects | |
29 [firhp,firlp,firbp,firbr,firpzm,firao,firv,firm] = get_test_objects_mfir; | |
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]; % Set the property with a plist | |
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 ~= 1, atest = false; end | |
111 % Check key | |
112 if ~io(3).plists.isparam('histout'), atest = false; end | |
113 % Check default value | |
114 if ~isEmptyDouble(io(3).plists.find('histout')), atest = false; end | |
115 % Check options | |
116 if ~isequal(io(3).plists.getOptionsForParam('histout'), {[]}), atest = false; end | |
117 end | |
118 % </AlgoCode> | |
119 else | |
120 atest = false; | |
121 end | |
122 | |
123 % Return a result structure | |
124 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
125 end % END UTP_01 | |
126 | |
127 %% UTP_02 | |
128 | |
129 % <TestDescription> | |
130 % | |
131 % Tests that the setHistout method works with a vector of MFIR objects as input. | |
132 % | |
133 % </TestDescription> | |
134 function result = utp_02 | |
135 | |
136 % <SyntaxDescription> | |
137 % | |
138 % The setHistout should set the output history (histout) of each input. | |
139 % | |
140 % </SyntaxDescription> | |
141 | |
142 try | |
143 % <SyntaxCode> | |
144 vals = [1 2 3]; | |
145 out = setHistout(firv, vals); | |
146 % </SyntaxCode> | |
147 stest = true; | |
148 catch err | |
149 stest = false; | |
150 end | |
151 | |
152 % <AlgoDescription> | |
153 % | |
154 % 1) Check the histout has the correct values | |
155 % | |
156 % </AlgoDescription> | |
157 | |
158 atest = true; | |
159 if stest | |
160 % <AlgoCode> | |
161 if ~isequal(out.histout, vals), 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 setHistout method works with a matrix of MFIR objects as input. | |
176 % | |
177 % </TestDescription> | |
178 function result = utp_03 | |
179 | |
180 % <SyntaxDescription> | |
181 % | |
182 % The setHistout should set the output history (histout) of each input. | |
183 % | |
184 % </SyntaxDescription> | |
185 | |
186 try | |
187 % <SyntaxCode> | |
188 vals = [1 2 3]; | |
189 out = setHistout(firm, vals); | |
190 % </SyntaxCode> | |
191 stest = true; | |
192 catch err | |
193 stest = false; | |
194 end | |
195 | |
196 % <AlgoDescription> | |
197 % | |
198 % 1) Check the histout has the correct values | |
199 % | |
200 % </AlgoDescription> | |
201 | |
202 atest = true; | |
203 if stest | |
204 % <AlgoCode> | |
205 if ~isequal(out.histout, vals), atest = false; end | |
206 % </AlgoCode> | |
207 else | |
208 atest = false; | |
209 end | |
210 | |
211 % Return a result structure | |
212 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
213 end % END UTP_03 | |
214 | |
215 %% UTP_04 | |
216 | |
217 % <TestDescription> | |
218 % | |
219 % Tests that the setHistout method works with a list of MFIR objects as input. | |
220 % | |
221 % </TestDescription> | |
222 function result = utp_04 | |
223 | |
224 % <SyntaxDescription> | |
225 % | |
226 % The setHistout should set the output history (histout) of each input. | |
227 % | |
228 % </SyntaxDescription> | |
229 | |
230 try | |
231 % <SyntaxCode> | |
232 vals = [1 2 3]; | |
233 out = setHistout(firhp,firpzm,firbp, vals); | |
234 % </SyntaxCode> | |
235 stest = true; | |
236 catch err | |
237 stest = false; | |
238 end | |
239 | |
240 % <AlgoDescription> | |
241 % | |
242 % 1) Check the histout has the correct values | |
243 % | |
244 % </AlgoDescription> | |
245 | |
246 atest = true; | |
247 if stest | |
248 % <AlgoCode> | |
249 if ~isequal(out.histout, vals), atest = false; end | |
250 % </AlgoCode> | |
251 else | |
252 atest = false; | |
253 end | |
254 | |
255 % Return a result structure | |
256 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
257 end % END UTP_04 | |
258 | |
259 %% UTP_05 | |
260 | |
261 % <TestDescription> | |
262 % | |
263 % Tests that the setHistout method works with a mix of different shaped MFIR | |
264 % objects as input. | |
265 % | |
266 % </TestDescription> | |
267 function result = utp_05 | |
268 | |
269 % <SyntaxDescription> | |
270 % | |
271 % The setHistout method is not designed for this call, for that reason must | |
272 % this call fail. | |
273 % | |
274 % </SyntaxDescription> | |
275 | |
276 try | |
277 % <SyntaxCode> | |
278 vals = [1 2 3]; | |
279 out = setHistout(firhp,firv,firpzm,firm,firbp, vals); | |
280 % </SyntaxCode> | |
281 stest = true; | |
282 catch err | |
283 stest = fail; | |
284 end | |
285 | |
286 % <AlgoDescription> | |
287 % | |
288 % 1) Check the histout has the correct values | |
289 % | |
290 % </AlgoDescription> | |
291 | |
292 atest = true; | |
293 if stest | |
294 % <AlgoCode> | |
295 if ~isequal(out.histout, vals), atest = false; end | |
296 % </AlgoCode> | |
297 else | |
298 atest = false; | |
299 end | |
300 | |
301 % Return a result structure | |
302 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
303 end % END UTP_05 | |
304 | |
305 %% UTP_06 | |
306 | |
307 % <TestDescription> | |
308 % | |
309 % Tests that the setHistout method properly applies history and that the | |
310 % option 'internal' suppresses the history. | |
311 % | |
312 % </TestDescription> | |
313 function result = utp_06 | |
314 | |
315 % <SyntaxDescription> | |
316 % | |
317 % Test that the result of applying the setHistout method can be processed back | |
318 % to an m-file. | |
319 % | |
320 % </SyntaxDescription> | |
321 | |
322 try | |
323 % <SyntaxCode> | |
324 out1 = setHistout(firhp, [1 2 3]); | |
325 out2 = testCallerIsMethod(@setHistout, firhp, [1 2 3]); | |
326 mout1 = rebuild(out1); | |
327 mout2 = rebuild(out2); | |
328 % </SyntaxCode> | |
329 stest = true; | |
330 catch err | |
331 disp(err.message) | |
332 stest = false; | |
333 end | |
334 | |
335 % <AlgoDescription> | |
336 % | |
337 % 1) Check that the last entry in the history of 'out1' corresponds to | |
338 % 'setHistout'. | |
339 % 2) Check that the last entry in the history of 'out2' NOT corresponds to | |
340 % 'setHistout'. | |
341 % 3) Check that the 'rebuild' method produces the same object as 'out'. | |
342 % | |
343 % </AlgoDescription> | |
344 | |
345 atest = true; | |
346 if stest | |
347 % <AlgoCode> | |
348 % Check the last step in the history of 'out1' | |
349 if ~(strcmp(out1.hist.methodInfo.mname, 'setHistout') && ... | |
350 eq(out1.hist.plistUsed, plist('histout', [1 2 3]), ple1)) | |
351 atest = false; | |
352 end | |
353 % Check the last step in the history of 'out2' | |
354 if eq(out2.hist.plistUsed, plist('histout', [1 2 3]), ple1) | |
355 atest = false; | |
356 end | |
357 % Check the rebuilt object | |
358 if ~eq(mout1, out1, ple2), atest = false; end | |
359 e = ple2.find('EXCEPTIONS'); | |
360 ple = plist('EXCEPTIONS', [e {'histout'}]); | |
361 if ~eq(mout2, out2, ple), atest = false; end | |
362 % </AlgoCode> | |
363 else | |
364 atest = false; | |
365 end | |
366 | |
367 % Return a result structure | |
368 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
369 end % END UTP_06 | |
370 | |
371 %% UTP_07 | |
372 | |
373 % <TestDescription> | |
374 % | |
375 % Tests that the setHistout method can modify the input MFIR object. | |
376 % | |
377 % </TestDescription> | |
378 function result = utp_07 | |
379 | |
380 % <SyntaxDescription> | |
381 % | |
382 % Test that the setHistout method can modify the input MFIR object | |
383 % by calling with no output. | |
384 % | |
385 % </SyntaxDescription> | |
386 | |
387 try | |
388 % <SyntaxCode> | |
389 % copy firhp to work with | |
390 ain = mfir(firhp); | |
391 % modify ain | |
392 aout = ain.setHistout([1 2 3]); | |
393 ain.setHistout([1 2 3]); | |
394 % </SyntaxCode> | |
395 stest = true; | |
396 catch err | |
397 disp(err.message) | |
398 stest = false; | |
399 end | |
400 | |
401 % <AlgoDescription> | |
402 % | |
403 % 1) Check that 'firhp' and 'ain' are now different. | |
404 % 2) Check that 'ain' has the correct histout field | |
405 % | |
406 % </AlgoDescription> | |
407 | |
408 atest = true; | |
409 if stest | |
410 % <AlgoCode> | |
411 % Check that setHistout modified the input by comparing to the copy | |
412 if eq(mfir(firhp), ain, ple1), atest = false; end | |
413 % Check that setHistout doesn't modified the input for the function notation | |
414 if ~eq(aout, ain, ple1), atest = false; end | |
415 % Check that the modified object contains the changed value | |
416 if ~eq(ain.histout, [1 2 3]), atest = false; end | |
417 % </AlgoCode> | |
418 else | |
419 atest = false; | |
420 end | |
421 | |
422 % Return a result structure | |
423 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
424 end % END UTP_07 | |
425 | |
426 %% UTP_08 | |
427 | |
428 % <TestDescription> | |
429 % | |
430 % Tests that the setHistout method can set the property with a plist. | |
431 % | |
432 % </TestDescription> | |
433 function result = utp_08 | |
434 | |
435 % <SyntaxDescription> | |
436 % | |
437 % Test that the setHistout method can modify the property 'histout' | |
438 % with a value in a plist. | |
439 % | |
440 % </SyntaxDescription> | |
441 | |
442 try | |
443 % <SyntaxCode> | |
444 pl = plist('histout', [1 2 3]); | |
445 out = firhp.setHistout(pl); | |
446 mout = rebuild(out); | |
447 % </SyntaxCode> | |
448 stest = true; | |
449 catch err | |
450 disp(err.message) | |
451 stest = false; | |
452 end | |
453 | |
454 % <AlgoDescription> | |
455 % | |
456 % 1) Check that 'ain' has the correct histout field | |
457 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
458 % | |
459 % </AlgoDescription> | |
460 | |
461 atest = true; | |
462 if stest | |
463 % <AlgoCode> | |
464 % Check the field 'histout' | |
465 if ~eq(out.histout, [1 2 3]), atest = false; end | |
466 % Check the rebuilt object | |
467 if ~eq(mout, out, ple2), atest = false; end | |
468 % </AlgoCode> | |
469 else | |
470 atest = false; | |
471 end | |
472 | |
473 % Return a result structure | |
474 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
475 end % END UTP_08 | |
476 | |
477 end |