Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/mfir/utp_mfir_char.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_CHAR a set of UTPs for the mfir/char method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_mfir_char.m,v 1.2 2009/07/23 12:33:00 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The char method of the mfir class converts the objects into one character string | |
11 % which contains information of the object. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_mfir_char(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'mfir'; | |
22 mthd = 'char'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test MFIR objects | |
30 [firhp,firlp,firbp,firbr,firpzm,firao,firv,firm] = get_test_objects_mfir; | |
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 | |
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 char method works with a vector of MFIR objects as input. | |
128 % | |
129 % </TestDescription> | |
130 function result = utp_02 | |
131 | |
132 % <SyntaxDescription> | |
133 % | |
134 % Test that the char method works for a vector of MFIR objects as input. | |
135 % | |
136 % </SyntaxDescription> | |
137 | |
138 try | |
139 % <SyntaxCode> | |
140 out = char(firv); | |
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 output contain at least each object name | |
151 % | |
152 % </AlgoDescription> | |
153 | |
154 atest = true; | |
155 if stest | |
156 % <AlgoCode> | |
157 % Check the output | |
158 if ~ischar(out), atest = false; end; | |
159 for kk = 1:numel(firv) | |
160 if isempty(strfind(out, firv(kk).name)), atest = false; end | |
161 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 char method works with a matrix of MFIR objects as input. | |
176 % | |
177 % </TestDescription> | |
178 function result = utp_03 | |
179 | |
180 % <SyntaxDescription> | |
181 % | |
182 % Test that the char method works for a matrix of MFIR objects as input. | |
183 % | |
184 % </SyntaxDescription> | |
185 | |
186 try | |
187 % <SyntaxCode> | |
188 out = char(firm); | |
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 output contain at least each object name | |
199 % | |
200 % </AlgoDescription> | |
201 | |
202 atest = true; | |
203 if stest | |
204 % <AlgoCode> | |
205 if ~ischar(out), atest = false; end; | |
206 for kk = 1:numel(firm) | |
207 if isempty(strfind(out, firm(kk).name)), atest = false; end | |
208 end | |
209 % </AlgoCode> | |
210 else | |
211 atest = false; | |
212 end | |
213 | |
214 % Return a result structure | |
215 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
216 end % END UTP_03 | |
217 | |
218 %% UTP_04 | |
219 | |
220 % <TestDescription> | |
221 % | |
222 % Tests that the char method works with a list of MFIR objects as input. | |
223 % | |
224 % </TestDescription> | |
225 function result = utp_04 | |
226 | |
227 % <SyntaxDescription> | |
228 % | |
229 % Test that the char method works for a list of MFIR objects as input. | |
230 % | |
231 % </SyntaxDescription> | |
232 | |
233 try | |
234 % <SyntaxCode> | |
235 out = char(firbp,firhp,firpzm); | |
236 % </SyntaxCode> | |
237 stest = true; | |
238 catch err | |
239 disp(err.message) | |
240 stest = false; | |
241 end | |
242 | |
243 % <AlgoDescription> | |
244 % | |
245 % 1) Check that the output contain at least each object name | |
246 % | |
247 % </AlgoDescription> | |
248 | |
249 atest = true; | |
250 firin = [firbp,firhp,firpzm]; | |
251 if stest | |
252 % <AlgoCode> | |
253 if ~ischar(out), atest = false; end; | |
254 for kk = 1:numel(firin) | |
255 if isempty(strfind(out, firin(kk).name)), atest = false; end | |
256 end | |
257 % </AlgoCode> | |
258 else | |
259 atest = false; | |
260 end | |
261 | |
262 % Return a result structure | |
263 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
264 end % END UTP_04 | |
265 | |
266 %% UTP_05 | |
267 | |
268 % <TestDescription> | |
269 % | |
270 % Tests that the char method works with a mix of different shaped MFIR objects | |
271 % as input. | |
272 % | |
273 % </TestDescription> | |
274 function result = utp_05 | |
275 | |
276 % <SyntaxDescription> | |
277 % | |
278 % Test that the char method works with an input of matrices and vectors | |
279 % and single MFIR objects. | |
280 % | |
281 % </SyntaxDescription> | |
282 | |
283 try | |
284 % <SyntaxCode> | |
285 out = char(firhp,firv,firao,firm,firlp); | |
286 % </SyntaxCode> | |
287 stest = true; | |
288 catch err | |
289 disp(err.message) | |
290 stest = false; | |
291 end | |
292 | |
293 % <AlgoDescription> | |
294 % | |
295 % 1) Check that the output contain at least each object name | |
296 % | |
297 % </AlgoDescription> | |
298 | |
299 atest = true; | |
300 firin = [firhp,reshape(firv,1,[]),firao,reshape(firm,1,[]),firlp]; | |
301 if stest | |
302 % <AlgoCode> | |
303 if ~ischar(out), atest = false; end; | |
304 for kk = 1:numel(firin) | |
305 if isempty(strfind(out, firin(kk).name)), atest = false; end | |
306 end | |
307 % </AlgoCode> | |
308 else | |
309 atest = false; | |
310 end | |
311 | |
312 % Return a result structure | |
313 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
314 end % END UTP_05 | |
315 | |
316 %% UTP_06 | |
317 | |
318 % <TestDescription> | |
319 % | |
320 % Tests that the char method properly applies history. | |
321 % | |
322 % </TestDescription> | |
323 function result = utp_06 | |
324 | |
325 % <SyntaxDescription> | |
326 % | |
327 % The method char doesn't change the data, thus it is not possible to check | |
328 % the history. Nothing to do. | |
329 % | |
330 % </SyntaxDescription> | |
331 | |
332 try | |
333 % <SyntaxCode> | |
334 % </SyntaxCode> | |
335 stest = true; | |
336 catch err | |
337 disp(err.message) | |
338 stest = false; | |
339 end | |
340 | |
341 % <AlgoDescription> | |
342 % | |
343 % </AlgoDescription> | |
344 | |
345 atest = true; | |
346 if stest | |
347 % <AlgoCode> | |
348 % </AlgoCode> | |
349 else | |
350 atest = false; | |
351 end | |
352 | |
353 % Return a result structure | |
354 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
355 end % END UTP_06 | |
356 | |
357 end |