comparison testing/utp_1.1/utps/ao/utp_ao_ne.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_NE a set of UTPs for the ao/ne method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_ne.m,v 1.6 2011/04/19 18:14:00 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The ne() method of the ao class ao1 ~= ao2 compares each element of an
11 % analysis object with the corresponding element of an second analysis object
12 % and returns a logical 1 (true) where ao1 and ao2 are not equal,
13 % or logical 0 (false) where they are equal.
14 %
15 % </MethodDescription>
16
17 function results = utp_ao_ne(varargin)
18
19 % Check the inputs
20 if nargin == 0
21
22 % Some keywords
23 class = 'ao';
24 mthd = 'ne';
25
26 results = [];
27 disp('******************************************************');
28 disp(['**** Running UTPs for ' class '/' mthd]);
29 disp('******************************************************');
30
31 % Test AOs
32 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]);
33
34 % Exception list for the UTPs:
35 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
36
37 % Run the tests
38 results = [results utp_01]; % getInfo call
39 results = [results utp_02]; % Vector input
40 results = [results utp_03]; % Matrix input
41 results = [results utp_04]; % List input
42 results = [results utp_05]; % Test with mixed input
43 results = [results utp_06]; % Test history is working
44 results = [results utp_07]; % Test with the exception list 'name'
45 results = [results utp_08]; % Test exception list in a plist
46
47 disp('Done.');
48 disp('******************************************************');
49
50 elseif nargin == 1 % Check for UTP functions
51 if strcmp(varargin{1}, 'isutp')
52 results = 1;
53 else
54 results = 0;
55 end
56 else
57 error('### Incorrect inputs')
58 end
59
60 %% UTP_01
61
62 % <TestDescription>
63 %
64 % Tests that the getInfo call works for this method.
65 %
66 % </TestDescription>
67 function result = utp_01
68
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 try
78 % <SyntaxCode>
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 % </SyntaxCode>
88 stest = true;
89 catch err
90 disp(err.message)
91 stest = false;
92 end
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 atest = true;
102 if stest
103 % <AlgoCode>
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 ~= 0, atest = false; end
114 % Check key
115 % Check default value
116 % Check options
117 end
118 % </AlgoCode>
119 else
120 atest = false;
121 end
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 ne 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 ne method works for a vector of AOs as input. Test the
139 % positive and the negative case.
140 %
141 % </SyntaxDescription>
142
143 try
144 % <SyntaxCode>
145 aa = at1.setName('my name');
146 avec1 = [at4, at3, at2, at1];
147 avec2 = [at4, at3, at2, aa];
148 out1 = ne(avec1, avec1);
149 out2 = ne(avec1, avec2);
150 % </SyntaxCode>
151 stest = true;
152 catch err
153 disp(err.message)
154 stest = false;
155 end
156
157 % <AlgoDescription>
158 %
159 % 1) Check the output of the ne function.
160 %
161 % </AlgoDescription>
162
163 atest = true;
164 if stest
165 % <AlgoCode>
166 if out1 ~= 0, atest = false; end
167 if out2 ~= 1, atest = false; end
168 % </AlgoCode>
169 else
170 atest = false;
171 end
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 ne 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 ne method works for a matrix of AOs as input. Test the
189 % positive and the negative case.
190 %
191 % </SyntaxDescription>
192
193 try
194 % <SyntaxCode>
195 aa = at1.setName('my name');
196 amat1 = [at4, at3, at1, at1, at2, at4];
197 amat2 = [at4, at3, aa; at1, at2, at4];
198 out1 = ne(amat1, amat1);
199 out2 = ne(amat1, amat2);
200 % </SyntaxCode>
201 stest = true;
202 catch err
203 disp(err.message)
204 stest = false;
205 end
206
207 % <AlgoDescription>
208 %
209 % 1) Check the output of the ne function.
210 %
211 % </AlgoDescription>
212
213 atest = true;
214 if stest
215 % <AlgoCode>
216 if out1 ~= 0, atest = false; end
217 if out2 ~= 1, atest = false; end
218 % </AlgoCode>
219 else
220 atest = false;
221 end
222
223 % Return a result structure
224 result = utp_prepare_result(atest, stest, dbstack, mfilename);
225 end % END UTP_03
226
227 %% UTP_04
228
229 % <TestDescription>
230 %
231 % Tests that the ne method works with a list of AOs as input.
232 %
233 % </TestDescription>
234 function result = utp_04
235
236 % <SyntaxDescription>
237 %
238 % The ne method doesn't works for a list of AOs as input. Nothing to do.
239 %
240 % </SyntaxDescription>
241
242 try
243 % <SyntaxCode>
244 % </SyntaxCode>
245 stest = true;
246 catch err
247 disp(err.message)
248 stest = false;
249 end
250
251 % <AlgoDescription>
252 %
253 % </AlgoDescription>
254
255 atest = true;
256 if stest
257 % <AlgoCode>
258 % </AlgoCode>
259 else
260 atest = false;
261 end
262
263 % Return a result structure
264 result = utp_prepare_result(atest, stest, dbstack, mfilename);
265 end % END UTP_04
266
267 %% UTP_05
268
269 % <TestDescription>
270 %
271 % Tests that the ne method works with a mix of different shaped AOs as
272 % input.
273 %
274 % </TestDescription>
275 function result = utp_05
276
277 % <SyntaxDescription>
278 %
279 % The ne method doesn't works for a list of AOs as input. Nothing to do.
280 %
281 % </SyntaxDescription>
282
283 try
284 % <SyntaxCode>
285 % </SyntaxCode>
286 stest = true;
287 catch err
288 disp(err.message)
289 stest = false;
290 end
291
292 % <AlgoDescription>
293 %
294 % </AlgoDescription>
295
296 atest = true;
297 if stest
298 % <AlgoCode>
299 % </AlgoCode>
300 else
301 atest = false;
302 end
303
304 % Return a result structure
305 result = utp_prepare_result(atest, stest, dbstack, mfilename);
306 end % END UTP_05
307
308 %% UTP_06
309
310 % <TestDescription>
311 %
312 % Tests that the ne method properly applies history.
313 %
314 % </TestDescription>
315 function result = utp_06
316
317 % <SyntaxDescription>
318 %
319 % The ne method doesn't change the AO, thus will no history added.
320 % Nothing to do
321 %
322 % </SyntaxDescription>
323
324 try
325 % <SyntaxCode>
326 % </SyntaxCode>
327 stest = true;
328 catch err
329 disp(err.message)
330 stest = false;
331 end
332
333 % <AlgoDescription>
334 %
335 % </AlgoDescription>
336
337 atest = true;
338 if stest
339 % <AlgoCode>
340 % </AlgoCode>
341 else
342 atest = false;
343 end
344
345 % Return a result structure
346 result = utp_prepare_result(atest, stest, dbstack, mfilename);
347 end % END UTP_06
348
349 %% UTP_07
350
351 % <TestDescription>
352 %
353 % Test the ne method with an exception list.
354 % The function ao/ne use the function ao/eq so it is not necessary to check
355 % all possibilities of the exception list.
356 %
357 % </TestDescription>
358 function result = utp_07
359
360 % <SyntaxDescription>
361 %
362 % Test the ne method with the exception 'name'. Use the option 'internal' to
363 % suppress the history. It is necessary to add 'created' to the exception
364 % list because aa is created at an other time.
365 %
366 % </SyntaxDescription>
367
368 try
369 % <SyntaxCode>
370 aa = testCallerIsMethod(@setName, at1, 'my name');
371 out1 = ne(aa, at1);
372 out2 = ne(aa, at1, 'name', 'created', 'UUID');
373 out3 = ne(aa, at1, 'ao/name', 'created', 'UUID');
374 % </SyntaxCode>
375 stest = true;
376 catch err
377 disp(err.message)
378 stest = false;
379 end
380
381 % <AlgoDescription>
382 %
383 % 1) Check the output.
384 %
385 % </AlgoDescription>
386
387 atest = true;
388 if stest
389 % <AlgoCode>
390 if out1 ~= 1, atest = false; end
391 if out2 ~= 0, atest = false; end
392 if out3 ~= 0, atest = false; end
393 % </AlgoCode>
394 else
395 atest = false;
396 end
397
398 % Return a result structure
399 result = utp_prepare_result(atest, stest, dbstack, mfilename);
400 end % END UTP_07
401
402 %% UTP_08
403
404 % <TestDescription>
405 %
406 % Test the ne method with an exception list which is in a plist.
407 %
408 % </TestDescription>
409 function result = utp_08
410
411 % <SyntaxDescription>
412 %
413 % Test that the ne method uses the exception list in a plist.
414 %
415 % </SyntaxDescription>
416
417 try
418 % <SyntaxCode>
419 aa = testCallerIsMethod(@setName, at1, 'my name');
420 pl = plist('Exceptions', {'name', 'created', 'UUID'});
421 out1 = ne(aa, at1);
422 out2 = ne(aa, at1, pl);
423 out3 = ne(aa, at1, pl);
424 % </SyntaxCode>
425 stest = true;
426 catch err
427 disp(err.message)
428 stest = false;
429 end
430
431 % <AlgoDescription>
432 %
433 % 1) Check the output.
434 %
435 % </AlgoDescription>
436
437 atest = true;
438 if stest
439 % <AlgoCode>
440 % Check the shape of the output data
441 if out1 ~= 1, atest = false; end
442 if out2 ~= 0, atest = false; end
443 if out3 ~= 0, atest = false; end
444 % </AlgoCode>
445 else
446 atest = false;
447 end
448
449 % Return a result structure
450 result = utp_prepare_result(atest, stest, dbstack, mfilename);
451 end % END UTP_08
452
453 end