comparison testing/utp_1.1/utps/timespan/utp_timespan_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_TIMESPAN_NE a set of UTPs for the timespan/ne method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_timespan_ne.m,v 1.6 2011/04/19 18:14:02 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The ne() method of the timespan class ts1 ~= ts2 compares each element of an
11 % timespan object with the corresponding element of an second ts object and returns
12 % a logical 1 (true) where ts1 and ts2 are not equal, or logical 0 (false)
13 % where they are equal.
14 %
15 % </MethodDescription>
16
17 function results = utp_timespan_ne(varargin)
18
19 % Check the inputs
20 if nargin == 0
21
22 % Some keywords
23 class = 'timespan';
24 mthd = 'ne';
25
26 results = [];
27 disp('******************************************************');
28 disp(['**** Running UTPs for ' class '/' mthd]);
29 disp('******************************************************');
30
31 % Test TIMESPAN objects
32 [ts1, ts2, ts3, ts4, ts5, ts6, tsv, tsm] = get_test_objects_timespan;
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 TIMESPAN objects 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 TIMESPAN objects as input.
139 % Test the positive and the negative case.
140 %
141 % </SyntaxDescription>
142
143 try
144 % <SyntaxCode>
145 ts = ts3.setName('my name');
146 tsv1 = [ts5, ts4, ts2, ts3];
147 tsv2 = [ts5, ts4, ts2, ts];
148 out1 = ne(tsv1, tsv1);
149 out2 = ne(tsv1, tsv2);
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 TIMESPAN objects 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 TIMESPAN objects as input.
189 % Test the positive and the negative case.
190 %
191 % </SyntaxDescription>
192
193 try
194 % <SyntaxCode>
195 ts = ts3.setName('my name');
196 tsm1 = [ts5, ts4, ts3, ts3, ts2, ts5];
197 tsm2 = [ts5, ts4, ts; ts3, ts2, ts5];
198 out1 = ne(tsm1, tsm1);
199 out2 = ne(tsm1, tsm2);
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 TIMESPAN objects 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 TIMESPAN objects as input.
239 % Nothing to do.
240 %
241 % </SyntaxDescription>
242
243 try
244 % <SyntaxCode>
245 % </SyntaxCode>
246 stest = true;
247 catch err
248 disp(err.message)
249 stest = false;
250 end
251
252 % <AlgoDescription>
253 %
254 % </AlgoDescription>
255
256 atest = true;
257 if stest
258 % <AlgoCode>
259 % </AlgoCode>
260 else
261 atest = false;
262 end
263
264 % Return a result structure
265 result = utp_prepare_result(atest, stest, dbstack, mfilename);
266 end % END UTP_04
267
268 %% UTP_05
269
270 % <TestDescription>
271 %
272 % Tests that the ne method works with a mix of different shaped TIMESPAN objects
273 % as input.
274 %
275 % </TestDescription>
276 function result = utp_05
277
278 % <SyntaxDescription>
279 %
280 % The ne method doesn't works for a list of TIMESPAN objects as input.
281 % Nothing to do.
282 %
283 % </SyntaxDescription>
284
285 try
286 % <SyntaxCode>
287 % </SyntaxCode>
288 stest = true;
289 catch err
290 disp(err.message)
291 stest = false;
292 end
293
294 % <AlgoDescription>
295 %
296 % </AlgoDescription>
297
298 atest = true;
299 if stest
300 % <AlgoCode>
301 % </AlgoCode>
302 else
303 atest = false;
304 end
305
306 % Return a result structure
307 result = utp_prepare_result(atest, stest, dbstack, mfilename);
308 end % END UTP_05
309
310 %% UTP_06
311
312 % <TestDescription>
313 %
314 % Tests that the ne method properly applies history.
315 %
316 % </TestDescription>
317 function result = utp_06
318
319 % <SyntaxDescription>
320 %
321 % The ne method doesn't change the TIMESPAN object, thus will no history added.
322 % Nothing to do
323 %
324 % </SyntaxDescription>
325
326 try
327 % <SyntaxCode>
328 % </SyntaxCode>
329 stest = true;
330 catch err
331 disp(err.message)
332 stest = false;
333 end
334
335 % <AlgoDescription>
336 %
337 % </AlgoDescription>
338
339 atest = true;
340 if stest
341 % <AlgoCode>
342 % </AlgoCode>
343 else
344 atest = false;
345 end
346
347 % Return a result structure
348 result = utp_prepare_result(atest, stest, dbstack, mfilename);
349 end % END UTP_06
350
351 %% UTP_07
352
353 % <TestDescription>
354 %
355 % Test the ne method with an exception list.
356 % The function timespan/ne use the function timespan/eq so it is not
357 % necessary to check all possibilities of the exception list.
358 %
359 % </TestDescription>
360 function result = utp_07
361
362 % <SyntaxDescription>
363 %
364 % Test the ne method with the exception 'name'. Use the option 'internal' to
365 % suppress the history. It is necessary to add 'created' to the exception
366 % list because ts is created at an other time.
367 %
368 % </SyntaxDescription>
369
370 try
371 % <SyntaxCode>
372 ts = testCallerIsMethod(@setName, ts3, 'my name');
373 out1 = ne(ts, ts3);
374 out2 = ne(ts, ts3, 'name', 'created', 'UUID');
375 out3 = ne(ts, ts3, 'timespan/name', 'created', 'UUID');
376 % </SyntaxCode>
377 stest = true;
378 catch err
379 disp(err.message)
380 stest = false;
381 end
382
383 % <AlgoDescription>
384 %
385 % 1) Check that each output contains the correct data.
386 %
387 % </AlgoDescription>
388
389 atest = true;
390 if stest
391 % <AlgoCode>
392 if out1 ~= 1, atest = false; end
393 if out2 ~= 0, atest = false; end
394 if out3 ~= 0, atest = false; end
395 % </AlgoCode>
396 else
397 atest = false;
398 end
399
400 % Return a result structure
401 result = utp_prepare_result(atest, stest, dbstack, mfilename);
402 end % END UTP_07
403
404 %% UTP_08
405
406 % <TestDescription>
407 %
408 % Test the ne method with an exception list which is in a plist.
409 %
410 % </TestDescription>
411 function result = utp_08
412
413 % <SyntaxDescription>
414 %
415 % Test that the ne method uses the exception list in a plist.
416 %
417 % </SyntaxDescription>
418
419 try
420 % <SyntaxCode>
421 ts = testCallerIsMethod(@setName, ts3, 'my name');
422 pl = plist('Exceptions', {'name', 'created', 'UUID'});
423 out1 = ne(ts, ts3);
424 out2 = ne(ts, ts3, pl);
425 out3 = ne(ts, ts3, pl);
426 % </SyntaxCode>
427 stest = true;
428 catch err
429 disp(err.message)
430 stest = false;
431 end
432
433 % <AlgoDescription>
434 %
435 % 1) Check that each output contains the correct data.
436 %
437 % </AlgoDescription>
438
439 atest = true;
440 if stest
441 % <AlgoCode>
442 % Check the shape of the output data
443 if out1 ~= 1, atest = false; end
444 if out2 ~= 0, atest = false; end
445 if out3 ~= 0, atest = false; end
446 % </AlgoCode>
447 else
448 atest = false;
449 end
450
451 % Return a result structure
452 result = utp_prepare_result(atest, stest, dbstack, mfilename);
453 end % END UTP_08
454
455 end