comparison testing/utp_1.1/utps/parfrac/utp_parfrac_rebuild.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_PARFRAC_REBUILD a set of UTPs for the parfrac/rebuild method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_parfrac_rebuild.m,v 1.2 2009/07/23 16:45:23 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The rebuild method of the parfrac class rebuilds the input objects using the
11 % history. This method is also intensively tested in the most other UTPs.
12 %
13 % </MethodDescription>
14
15 function results = utp_parfrac_rebuild(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'parfrac';
22 mthd = 'rebuild';
23
24 results = [];
25 disp('******************************************************');
26 disp(['**** Running UTPs for ' class '/' mthd]);
27 disp('******************************************************');
28
29 % Test PARFRAC objects
30 [pf1,pf2,pf3,pfv,pfm] = get_test_objects_parfrac;
31
32 % Exception list for the UTPs:
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
34
35 % Run the tests
36 results = [results utp_01]; % getInfo call
37 results = [results utp_02]; % Vector input
38 results = [results utp_03]; % Matrix input
39 results = [results utp_04]; % List input
40 results = [results utp_05]; % Test with mixed input
41 results = [results utp_06]; % Test history is working
42 results = [results utp_07]; % Test the output
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 ~= 0, atest = false; end
111 % Check key
112 % Check default value
113 % Check options
114 end
115 % </AlgoCode>
116 else
117 atest = false;
118 end
119
120 % Return a result structure
121 result = utp_prepare_result(atest, stest, dbstack, mfilename);
122 end % END UTP_01
123
124 %% UTP_02
125
126 % <TestDescription>
127 %
128 % Tests that the rebuild method works with a vector of PARFRAC objects as
129 % input.
130 %
131 % </TestDescription>
132 function result = utp_02
133
134 % <SyntaxDescription>
135 %
136 % Test that the rebuild method works for a vector of PARFRAC objects as
137 % input.
138 %
139 % </SyntaxDescription>
140
141 try
142 % <SyntaxCode>
143 out = rebuild(pfv);
144 % </SyntaxCode>
145 stest = true;
146 catch err
147 disp(err.message)
148 stest = false;
149 end
150
151 % <AlgoDescription>
152 %
153 % 1) Check the rebuilt output.
154 %
155 % </AlgoDescription>
156
157 atest = true;
158 if stest
159 % <AlgoCode>
160 % Check the output
161 if ~isa(out, 'parfrac'), atest = false; end;
162 for kk = 1:numel(pfv)
163 if eq(out(kk), pfv(kk)), atest = false; end
164 end
165 % </AlgoCode>
166 else
167 atest = false;
168 end
169
170 % Return a result structure
171 result = utp_prepare_result(atest, stest, dbstack, mfilename);
172 end % END UTP_02
173
174 %% UTP_03
175
176 % <TestDescription>
177 %
178 % Tests that the rebuild method works with a matrix of PARFRAC objects as
179 % input.
180 %
181 % </TestDescription>
182 function result = utp_03
183
184 % <SyntaxDescription>
185 %
186 % Test that the rebuild method works for a matrix of PARFRAC objects as
187 % input.
188 %
189 % </SyntaxDescription>
190
191 try
192 % <SyntaxCode>
193 out = rebuild(pfm);
194 % </SyntaxCode>
195 stest = true;
196 catch err
197 disp(err.message)
198 stest = false;
199 end
200
201 % <AlgoDescription>
202 %
203 % 1) Check the rebuilt output.
204 %
205 % </AlgoDescription>
206
207 atest = true;
208 if stest
209 % <AlgoCode>
210 if ~isa(out, 'parfrac'), atest = false; end;
211 for kk = 1:numel(pfm)
212 if eq(out(kk), pfm(kk)), atest = false; end
213 end
214 % </AlgoCode>
215 else
216 atest = false;
217 end
218
219 % Return a result structure
220 result = utp_prepare_result(atest, stest, dbstack, mfilename);
221 end % END UTP_03
222
223 %% UTP_04
224
225 % <TestDescription>
226 %
227 % Tests that the rebuild method works with a list of PARFRAC objects as
228 % input.
229 %
230 % </TestDescription>
231 function result = utp_04
232
233 % <SyntaxDescription>
234 %
235 % Test that the rebuild method works for a list of PARFRAC objects as
236 % input.
237 %
238 % </SyntaxDescription>
239
240 try
241 % <SyntaxCode>
242 out = rebuild(pf1,pf2,pf3);
243 % </SyntaxCode>
244 stest = true;
245 catch err
246 disp(err.message)
247 stest = false;
248 end
249
250 % <AlgoDescription>
251 %
252 % 1) Check the rebuilt output.
253 %
254 % </AlgoDescription>
255
256 atest = true;
257 pfin = [pf1,pf2,pf3];
258 if stest
259 % <AlgoCode>
260 if ~isa(out, 'parfrac'), atest = false; end;
261 for kk = 1:numel(pfin)
262 if eq(out(kk), pfin(kk)), atest = false; end
263 end
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 rebuild method works with a mix of different shaped
278 % PARFRAC objects as input.
279 %
280 % </TestDescription>
281 function result = utp_05
282
283 % <SyntaxDescription>
284 %
285 % Test that the rebuild method works with an input of matrices and
286 % vectors and single PARFRAC objects.
287 %
288 % </SyntaxDescription>
289
290 try
291 % <SyntaxCode>
292 out = rebuild(pf2,pfv,pf1,pfm,pf3);
293 % </SyntaxCode>
294 stest = true;
295 catch err
296 disp(err.message)
297 stest = false;
298 end
299
300 % <AlgoDescription>
301 %
302 % 1) Check the rebuilt output.
303 %
304 % </AlgoDescription>
305
306 atest = true;
307 pfin = [pf2,reshape(pfv,1,[]),pf1,reshape(pfm,1,[]),pf3];
308 if stest
309 % <AlgoCode>
310 if ~isa(out, 'parfrac'), atest = false; end;
311 for kk = 1:numel(pfin)
312 if eq(out(kk), pfin(kk)), atest = false; end
313 end
314 % </AlgoCode>
315 else
316 atest = false;
317 end
318
319 % Return a result structure
320 result = utp_prepare_result(atest, stest, dbstack, mfilename);
321 end % END UTP_05
322
323 %% UTP_06
324
325 % <TestDescription>
326 %
327 % Tests that the rebuild method properly applies history.
328 %
329 % </TestDescription>
330 function result = utp_06
331
332 % <SyntaxDescription>
333 %
334 % The method rebuild doesn't change the data, thus it is not possible
335 % to check the history. Nothing to do.
336 %
337 % </SyntaxDescription>
338
339 try
340 % <SyntaxCode>
341 % </SyntaxCode>
342 stest = true;
343 catch err
344 disp(err.message)
345 stest = false;
346 end
347
348 % <AlgoDescription>
349 %
350 % </AlgoDescription>
351
352 atest = true;
353 if stest
354 % <AlgoCode>
355 % </AlgoCode>
356 else
357 atest = false;
358 end
359
360 % Return a result structure
361 result = utp_prepare_result(atest, stest, dbstack, mfilename);
362 end % END UTP_06
363
364 %% UTP_07
365
366 % <TestDescription>
367 %
368 % Check that the rebuild method pass back the output objects to a list of
369 % output variables or to a single variable.
370 %
371 % </TestDescription>
372 function result = utp_07
373
374 % <SyntaxDescription>
375 %
376 % Call the method with a list of output variables and with a single output
377 % variable. Additionaly check that the rebuild method works on the output.
378 %
379 % </SyntaxDescription>
380
381 try
382 % <SyntaxCode>
383 [o1, o2] = rebuild(pf3, pf1);
384 o3 = rebuild(pf3, pf1);
385 % </SyntaxCode>
386 stest = true;
387 catch err
388 disp(err.message)
389 stest = false;
390 end
391
392 % <AlgoDescription>
393 %
394 % 1) Check that the output contains the right number of objects
395 % 2) Check that the 'rebuild' method produces the same object as 'out'.
396 %
397 % </AlgoDescription>
398
399 atest = true;
400 if stest
401 % <AlgoCode>
402 % Check the number of outputs
403 if numel(o1) ~=1, atest = false; end
404 if numel(o2) ~=1, atest = false; end
405 if numel(o3) ~=2, atest = false; end
406 % Check the rebuilding of the object
407 if ~eq(o1, pf3, ple2), atest = false; end
408 if ~eq(o2, pf1, ple2), atest = false; end
409 if ~eq(o3, [pf3 pf1], ple2), atest = false; end
410 % </AlgoCode>
411 else
412 atest = false;
413 end
414
415 % Return a result structure
416 result = utp_prepare_result(atest, stest, dbstack, mfilename);
417 end % END UTP_07
418
419 end