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