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