Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/rational/utp_rational_string.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_RATIONAL_STRING a set of UTPs for the rational/string method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_rational_string.m,v 1.4 2011/09/29 13:49:04 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The string method of the rational class writes a command string that can | |
11 % be used to recreate the input object(s). But the object should not have | |
12 % more than one history step. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_rational_string(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'rational'; | |
23 mthd = 'string'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 ra1 = rational([1 2], [4, 6+2i], 'nice name'); | |
31 ra2 = rational(plist('num', [1 2], 'den', [3, 6, -7])); | |
32 rav = [ra1, ra2, ra1]; | |
33 ram = [ra1, ra2, ra1; ra1, ra2, ra1]; | |
34 | |
35 % Exception list for the UTPs: | |
36 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
37 | |
38 % Run the tests | |
39 results = [results utp_01]; % getInfo call | |
40 results = [results utp_02]; % Vector input | |
41 results = [results utp_03]; % Matrix input | |
42 results = [results utp_04]; % List input | |
43 results = [results utp_05]; % Test with mixed input | |
44 results = [results utp_06]; % Test history is working | |
45 results = [results utp_07]; % Negative test: The object have more than one history step. | |
46 | |
47 disp('Done.'); | |
48 disp('******************************************************'); | |
49 | |
50 elseif nargin == 1 % Check for UTP functions | |
51 if strcmp(varargin{1}, 'isutp') | |
52 results = 1; | |
53 else | |
54 results = 0; | |
55 end | |
56 else | |
57 error('### Incorrect inputs') | |
58 end | |
59 | |
60 %% UTP_01 | |
61 | |
62 % <TestDescription> | |
63 % | |
64 % Tests that the getInfo call works for this method. | |
65 % | |
66 % </TestDescription> | |
67 function result = utp_01 | |
68 | |
69 | |
70 % <SyntaxDescription> | |
71 % | |
72 % Test that the getInfo call works for no sets, all sets, and each set | |
73 % individually. | |
74 % | |
75 % </SyntaxDescription> | |
76 | |
77 try | |
78 % <SyntaxCode> | |
79 % Call for no sets | |
80 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
81 % Call for all sets | |
82 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
83 % Call for each set | |
84 for kk=1:numel(io(2).sets) | |
85 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
86 end | |
87 % </SyntaxCode> | |
88 stest = true; | |
89 catch err | |
90 disp(err.message) | |
91 stest = false; | |
92 end | |
93 | |
94 % <AlgoDescription> | |
95 % | |
96 % 1) Check that getInfo call returned an minfo object in all cases. | |
97 % 2) Check that all plists have the correct parameters. | |
98 % | |
99 % </AlgoDescription> | |
100 | |
101 atest = true; | |
102 if stest | |
103 % <AlgoCode> | |
104 % check we have minfo objects | |
105 if isa(io, 'minfo') | |
106 %%% SET 'None' | |
107 if ~isempty(io(1).sets), atest = false; end | |
108 if ~isempty(io(1).plists), atest = false; end | |
109 %%% Check all Sets | |
110 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
111 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
112 %%%%%%%%%% SET 'Default' | |
113 if io(3).plists.nparams ~= 0, atest = false; end | |
114 % Check key | |
115 % Check default value | |
116 % Check options | |
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 string method works with a vector of RATIONAL objects as | |
132 % input. | |
133 % | |
134 % </TestDescription> | |
135 function result = utp_02 | |
136 | |
137 % <SyntaxDescription> | |
138 % | |
139 % Test that the string method works for a vector of RATIONAL objects as | |
140 % input. | |
141 % | |
142 % </SyntaxDescription> | |
143 | |
144 try | |
145 % <SyntaxCode> | |
146 out = string(rav); | |
147 rout = eval(out); | |
148 % </SyntaxCode> | |
149 stest = true; | |
150 catch err | |
151 disp(err.message) | |
152 stest = false; | |
153 end | |
154 | |
155 % <AlgoDescription> | |
156 % | |
157 % 1) Check that the output is a executable string. | |
158 % 2) Check the correct number of rout | |
159 % 3) Check the rebuild objects. | |
160 % | |
161 % </AlgoDescription> | |
162 | |
163 atest = true; | |
164 if stest | |
165 % <AlgoCode> | |
166 % Check the output | |
167 if ~ischar(out), atest = false; end; | |
168 if ~isa(rout, 'rational'), atest = false; end | |
169 if numel(rout) ~= numel(rav), atest = false; end | |
170 for kk = 1:numel(rav) | |
171 if eq(rout(kk), rav(kk)), atest = false; end | |
172 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 string method works with a matrix of RATIONAL objects as | |
187 % input. | |
188 % | |
189 % </TestDescription> | |
190 function result = utp_03 | |
191 | |
192 % <SyntaxDescription> | |
193 % | |
194 % Test that the string method works for a matrix of RATIONAL objects as | |
195 % input. | |
196 % | |
197 % </SyntaxDescription> | |
198 | |
199 try | |
200 % <SyntaxCode> | |
201 out = string(ram); | |
202 rout = eval(out); | |
203 % </SyntaxCode> | |
204 stest = true; | |
205 catch err | |
206 disp(err.message) | |
207 stest = false; | |
208 end | |
209 | |
210 % <AlgoDescription> | |
211 % | |
212 % 1) Check that the output is a executable string. | |
213 % 2) Check the correct number of rout | |
214 % 3) Check the rebuild objects. | |
215 % | |
216 % </AlgoDescription> | |
217 | |
218 atest = true; | |
219 if stest | |
220 % <AlgoCode> | |
221 % Check the output | |
222 if ~ischar(out), atest = false; end | |
223 if ~isa(rout, 'rational'), atest = false; end | |
224 if numel(rout) ~= numel(ram), atest = false; end | |
225 for kk = 1:numel(ram) | |
226 if eq(rout(kk), ram(kk)), atest = false; end | |
227 end | |
228 % </AlgoCode> | |
229 else | |
230 atest = false; | |
231 end | |
232 | |
233 % Return a result structure | |
234 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
235 end % END UTP_03 | |
236 | |
237 %% UTP_04 | |
238 | |
239 % <TestDescription> | |
240 % | |
241 % Tests that the string method works with a list of RATIONAL objects as | |
242 % input. | |
243 % | |
244 % </TestDescription> | |
245 function result = utp_04 | |
246 | |
247 % <SyntaxDescription> | |
248 % | |
249 % Test that the string method works for a list of RATIONAL objects as | |
250 % input. | |
251 % | |
252 % </SyntaxDescription> | |
253 | |
254 try | |
255 % <SyntaxCode> | |
256 out = string(ra1,ra2); | |
257 rout = eval(out); | |
258 % </SyntaxCode> | |
259 stest = true; | |
260 catch err | |
261 disp(err.message) | |
262 stest = false; | |
263 end | |
264 | |
265 % <AlgoDescription> | |
266 % | |
267 % 1) Check that the output is a executable string. | |
268 % 2) Check the correct number of rout | |
269 % 3) Check the rebuild objects. | |
270 % | |
271 % </AlgoDescription> | |
272 | |
273 atest = true; | |
274 rain = [ra1, ra2]; | |
275 if stest | |
276 % <AlgoCode> | |
277 % Check the output | |
278 if ~ischar(out), atest = false; end | |
279 if ~isa(rout, 'rational'), atest = false; end | |
280 if numel(rout) ~= numel(rain), atest = false; end | |
281 for kk = 1:numel(rain) | |
282 if eq(rout(kk), rain(kk)), atest = false; end | |
283 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_04 | |
292 | |
293 %% UTP_05 | |
294 | |
295 % <TestDescription> | |
296 % | |
297 % Tests that the string method works with a mix of different shaped | |
298 % RATIONAL objects as input. | |
299 % | |
300 % </TestDescription> | |
301 function result = utp_05 | |
302 | |
303 % <SyntaxDescription> | |
304 % | |
305 % Test that the string method works with an input of matrices and | |
306 % vectors and single RATIONAL objects. | |
307 % | |
308 % </SyntaxDescription> | |
309 | |
310 try | |
311 % <SyntaxCode> | |
312 out = string(ra1,ram,ra2); | |
313 rout = eval(out); | |
314 % </SyntaxCode> | |
315 stest = true; | |
316 catch err | |
317 disp(err.message) | |
318 stest = false; | |
319 end | |
320 | |
321 % <AlgoDescription> | |
322 % | |
323 % 1) Check that the output is a executable string. | |
324 % 2) Check the correct number of rout | |
325 % 3) Check the rebuild objects. | |
326 % | |
327 % </AlgoDescription> | |
328 | |
329 atest = true; | |
330 rain = [ra1, reshape(ram, 1, []), ra2]; | |
331 if stest | |
332 % <AlgoCode> | |
333 % Check the output | |
334 if ~ischar(out), atest = false; end | |
335 if ~isa(rout, 'rational'), atest = false; end | |
336 if numel(rout) ~= numel(rain), atest = false; end | |
337 for kk = 1:numel(rain) | |
338 if eq(rout(kk), rain(kk)), atest = false; end | |
339 end | |
340 % </AlgoCode> | |
341 else | |
342 atest = false; | |
343 end | |
344 | |
345 % Return a result structure | |
346 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
347 end % END UTP_05 | |
348 | |
349 %% UTP_06 | |
350 | |
351 % <TestDescription> | |
352 % | |
353 % Tests that the string method properly applies history. | |
354 % | |
355 % </TestDescription> | |
356 function result = utp_06 | |
357 | |
358 % <SyntaxDescription> | |
359 % | |
360 % The method string doesn't change the data, thus it is not possible to | |
361 % check the history. Nothing to do. | |
362 % | |
363 % </SyntaxDescription> | |
364 | |
365 try | |
366 % <SyntaxCode> | |
367 % </SyntaxCode> | |
368 stest = true; | |
369 catch err | |
370 disp(err.message) | |
371 stest = false; | |
372 end | |
373 | |
374 % <AlgoDescription> | |
375 % | |
376 % </AlgoDescription> | |
377 | |
378 atest = true; | |
379 if stest | |
380 % <AlgoCode> | |
381 % </AlgoCode> | |
382 else | |
383 atest = false; | |
384 end | |
385 | |
386 % Return a result structure | |
387 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
388 end % END UTP_06 | |
389 | |
390 %% UTP_07 | |
391 | |
392 % <TestDescription> | |
393 % | |
394 % Tests that the string method doesn't work if the RATIONAL object have | |
395 % more than one history step. | |
396 % | |
397 % </TestDescription> | |
398 function result = utp_07 | |
399 | |
400 % <SyntaxDescription> | |
401 % | |
402 % The method string throws an error because the input object have more | |
403 % than one history step. | |
404 % | |
405 % </SyntaxDescription> | |
406 | |
407 try | |
408 % <SyntaxCode> | |
409 pzm = pzmodel(12, {2, [3 5], 7}, {1+2i 5}); | |
410 ra3 = parfrac(pzm); | |
411 ra3.setName('Second history step'); | |
412 out = ra3.string(); | |
413 % </SyntaxCode> | |
414 stest = false; | |
415 catch err | |
416 stest = true; | |
417 end | |
418 | |
419 % <AlgoDescription> | |
420 % | |
421 % </AlgoDescription> | |
422 | |
423 atest = true; | |
424 if stest | |
425 % <AlgoCode> | |
426 % </AlgoCode> | |
427 else | |
428 atest = false; | |
429 end | |
430 | |
431 % Return a result structure | |
432 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
433 end % END UTP_07 | |
434 | |
435 end |