comparison testing/utp_1.1/utps/ao/utp_ao_linSubtract.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_LINSUBTRACT a set of UTPs for the ao/linSubtract method
2 %
3 % M Nofrarias 05-07-09
4 %
5 % $Id: utp_ao_linSubtract.m,v 1.3 2009/08/07 10:47:05 hewitson Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % LINSUBTRACT subtracts a linear contribution from an input ao
11 %
12 % </MethodDescription>
13
14 function results = utp_ao_linSubtract(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'ao';
21 mthd = 'linSubtract';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test AOs
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
30
31 % Exception list for the UTPs:
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
33
34 % Run the tests
35 results = [results utp_01]; % getInfo call
36 results = [results utp_02]; % Vector input
37 results = [results utp_03]; % Matrix input
38 results = [results utp_04]; % List input
39 results = [results utp_05]; % Test with mixed input
40 results = [results utp_06]; % Test history is working
41 results = [results utp_07]; % Test output of the data
42
43 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
44 amat = [at1 at5 at6; at5 at6 at1];
45 results = [results utp_11(mthd, amat, ple1, pl)]; % Test plotinfo doesn't disappear
46
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 % <SyntaxDescription>
71 %
72 % Test that the getInfo call works for no sets, all sets, and each set
73 % individually.
74 %
75 % </SyntaxDescription>
76
77 % <SyntaxCode>
78 try
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 stest = true;
88 catch err
89 disp(err.message)
90 stest = false;
91 end
92 % </SyntaxCode>
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 % <AlgoCode>
102 atest = true;
103 if stest
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 ~= 5, atest = false; end
114 % Check key
115 % Check default value
116 % Check options
117 end
118 else
119 atest = false;
120 end
121 % </AlgoCode>
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 linSubtract method works with a vector of AOs as input.
132 %
133 % </TestDescription>
134 function result = utp_02
135
136 % <SyntaxDescription>
137 %
138 % Test that the linSubtract method works for a vector of AOs as input.
139 %
140 % </SyntaxDescription>
141
142 % <SyntaxCode>
143 try
144 avec = [at1 at5 at6];
145 fs = at1.fs;
146 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
147 out = linSubtract(avec,pl);
148 stest = true;
149 catch err
150 disp(err.message)
151 stest = false;
152 end
153 % </SyntaxCode>
154
155 % <AlgoDescription>
156 %
157 % 1) Check that the number of elements in 'out' is the square of the
158 % number in the input.
159 % 2) Check that each output AO contains the correct data.
160 %
161 % </AlgoDescription>
162
163 % <AlgoCode>
164 atest = true;
165 if stest
166 % Check we have the correct number of outputs
167 if numel(out) ~= 1, atest = false; end
168 else
169 atest = false;
170 end
171 % </AlgoCode>
172
173 % Return a result structure
174 result = utp_prepare_result(atest, stest, dbstack, mfilename);
175 end % END UTP_02
176
177 %% UTP_03
178
179 % <TestDescription>
180 %
181 % Tests that the linSubtract method works with a matrix of AOs as input.
182 %
183 % </TestDescription>
184 function result = utp_03
185
186 % <SyntaxDescription>
187 %
188 % Test that the linSubtract method works for a matrix of AOs as input.
189 %
190 % </SyntaxDescription>
191
192 % <SyntaxCode>
193 try
194 amat = [at1 at5 at6; at5 at6 at1];
195 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
196 out = linSubtract(amat,pl);
197 stest = true;
198 catch err
199 disp(err.message)
200 stest = false;
201 end
202 % </SyntaxCode>
203
204 % <AlgoDescription>
205 %
206 % 1) Check that the number of elements in 'out' is the square of the
207 % number in the input.
208 % 2) Check that each output AO contains the correct data.
209 %
210 % </AlgoDescription>
211
212 % <AlgoCode>
213 atest = true;
214 if stest
215 % Check we have the correct number of outputs
216 if numel(out) ~= 1, atest = false; end
217 else
218 atest = false;
219 end
220 % </AlgoCode>
221
222 % Return a result structure
223 result = utp_prepare_result(atest, stest, dbstack, mfilename);
224 end % END UTP_03
225
226 %% UTP_04
227
228 % <TestDescription>
229 %
230 % Tests that the linSubtract method works with a list of AOs as input.
231 %
232 % </TestDescription>
233 function result = utp_04
234
235 % <SyntaxDescription>
236 %
237 % Test that the linSubtract method works for a list of AOs as input.
238 %
239 % </SyntaxDescription>
240
241 % <SyntaxCode>
242 try
243 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
244 out = linSubtract(at1,at5,at6,pl);
245 stest = true;
246 catch err
247 disp(err.message)
248 stest = false;
249 end
250 % </SyntaxCode>
251
252 % <AlgoDescription>
253 %
254 % 1) Check that the number of elements in 'out' is the square of the
255 % number in the input.
256 % 2) Check that each output AO contains the correct data.
257 %
258 % </AlgoDescription>
259
260 % <AlgoCode>
261 atest = true;
262 if stest
263 % Check we have the correct number of outputs
264 if numel(out) ~= 1, atest = false; end
265 else
266 atest = false;
267 end
268 % </AlgoCode>
269
270 % Return a result structure
271 result = utp_prepare_result(atest, stest, dbstack, mfilename);
272 end % END UTP_04
273
274 %% UTP_05
275
276 % <TestDescription>
277 %
278 % Tests that the linSubtract method works with a mix of different shaped AOs as
279 % input.
280 %
281 % </TestDescription>
282 function result = utp_05
283
284 % <SyntaxDescription>
285 %
286 % Test that the linSubtract method works with an input of matrices and vectors
287 % and single AOs.
288 %
289 % </SyntaxDescription>
290
291 % <SyntaxCode>
292 try
293 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
294 out = linSubtract(at1,[at5 at6],at5,[at5 at1; at6 at1],at6,pl);
295 stest = true;
296 catch err
297 disp(err.message)
298 stest = false;
299 end
300 % </SyntaxCode>
301
302 % <AlgoDescription>
303 %
304 % 1) Check that the number of elements in 'out' is the same as in
305 % input.
306 % 2) Check that each output AO contains the correct data.
307 %
308 % </AlgoDescription>
309
310 % <AlgoCode>
311 atest = true;
312 if stest
313 % Check we have the correct number of outputs
314 if numel(out) ~= 1, atest = false; end
315 else
316 atest = false;
317 end
318 % </AlgoCode>
319
320 % Return a result structure
321 result = utp_prepare_result(atest, stest, dbstack, mfilename);
322 end % END UTP_05
323
324 %% UTP_06
325 % <TestDescription>
326 %
327 % Tests that the linSubtract method properly applies history.
328 %
329 % </TestDescription>
330 function result = utp_06
331
332 % <SyntaxDescription>
333 %
334 % Test that the result of applying the linSubtract method can be processed back
335 % to an m-file.
336 %
337 % </SyntaxDescription>
338
339 % <SyntaxCode>
340 try
341 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
342 out = linSubtract(at1,at5,at6,pl);
343 mout = rebuild(out);
344 stest = true;
345 catch err
346 disp(err.message)
347 stest = false;
348 end
349 % </SyntaxCode>
350
351 % <AlgoDescription>
352 %
353 % 1) Check that the last entry in the history of 'out' corresponds to
354 % 'linSubtract'.
355 % 2) Check that the re-built object is the same object as 'out'.
356 %
357 % </AlgoDescription>
358
359 % <AlgoCode>
360 atest = true;
361 if stest
362 % Check the last step in the history of 'out'
363 if ~strcmp(out.hist.methodInfo.mname, 'linSubtract'), atest = false; end
364 % Check the re-built object
365 if ~eq(mout, out, ple2), atest = false; end
366 else
367 atest = false;
368 end
369 % </AlgoCode>
370
371 % Return a result structure
372 result = utp_prepare_result(atest, stest, dbstack, mfilename);
373 end % END UTP_06
374
375 %% UTP_07
376
377 % <TestDescription>
378 %
379 % Tests that the linSubtract method can not modify the input AO.
380 %
381 % </TestDescription>
382 function result = utp_07
383
384 % <SyntaxDescription>
385 %
386 % Test that the tfe method can not modify the input AO.
387 % The method must throw an error for the modifier call.
388 %
389 % </SyntaxDescription>
390
391 try
392 % <SyntaxCode>
393 % copy at1 to work with
394 ain = ao(at1);
395 % modify ains[s[s[s[[[[[[s[
396 pl = plist('coupling',{{'n(1)'},{'n(2)'}},'fc',[0.1 0.4]);
397 ain.linSubtract(at1,at5,at6,pl);
398 % </SyntaxCode>
399 stest = false;
400 catch err
401 stest = true;
402 end
403
404 % <AlgoDescription>
405 %
406 % 1) Nothing to check.
407 %
408 % </AlgoDescription>
409
410 atest = true;
411 if stest
412 % <AlgoCode>
413 % </AlgoCode>
414 else
415 atest = false;
416 end
417
418 % Return a result structure
419 result = utp_prepare_result(atest, stest, dbstack, mfilename);
420 end % END UTP_07
421
422
423
424 end
425