comparison testing/utp_1.1/utps/ao/utp_ao_dropduplicates.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_DROPDUPLICATES a set of UTPs for the ao/dropduplicates method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_dropduplicates.m,v 1.10 2009/08/07 10:05:39 hewitson Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The dropduplicates method of the ao class drops duplicate samples from AOs.
11 %
12 % </MethodDescription>
13
14 function results = utp_ao_dropduplicates(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'ao';
21 mthd = 'dropduplicates';
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 the modify call works
42 results = [results utp_08]; % Test the data shape
43 results = [results utp_09]; % Test output of the data
44 results = [results utp_10]; % Test with different tolerances.
45 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear
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 ~= 1, atest = false; end
114 % Check key
115 if ~io(3).plists.isparam('tol'), atest = false; end
116 % Check default value
117 if ~isequal(io(3).plists.find('tol'), .005), atest = false; end
118 % Check options
119 if ~isequal(io(3).plists.getOptionsForParam('tol'), {.005}), atest = false; end
120 end
121 % </AlgoCode>
122 else
123 atest = false;
124 end
125
126 % Return a result structure
127 result = utp_prepare_result(atest, stest, dbstack, mfilename);
128 end % END UTP_01
129
130 %% UTP_02
131
132 % <TestDescription>
133 %
134 % Tests that the dropduplicates method works with a vector of AOs as input.
135 %
136 % </TestDescription>
137 function result = utp_02
138
139 % <SyntaxDescription>
140 %
141 % Test that the dropduplicates method works for a vector of AOs as input.
142 %
143 % </SyntaxDescription>
144
145 try
146 % <SyntaxCode>
147 x = 1:100;
148 x = sort([x x+1e-4]);
149 y = randn(length(x),1);
150 at1 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
151 avec = [at1 at5 at6];
152 out = dropduplicates(avec);
153 % </SyntaxCode>
154 stest = true;
155 catch err
156 disp(err.message)
157 stest = false;
158 end
159
160 % <AlgoDescription>
161 %
162 % 1) Check that the number of elements in 'out' is the square of the
163 % number in the input.
164 % 2) Check that each output AO contains the correct data.
165 %
166 % </AlgoDescription>
167
168 atest = true;
169 if stest
170 % <AlgoCode>
171 % Check we have the correct number of outputs
172 if numel(out) ~= numel(avec), atest = false; end
173 % Check the output data
174 for kk = 1:numel(avec)
175 x = avec(kk).x;
176 y = avec(kk).y;
177 d = abs(diff(x));
178 idx = find(d<5e-3);
179 x(idx) = [];
180 y(idx) = [];
181 if ~isequal(out(kk).x, x), atest = false; end
182 if ~isequal(out(kk).y, y), atest = false; end
183 end
184 % </AlgoCode>
185 else
186 atest = false;
187 end
188
189 % Return a result structure
190 result = utp_prepare_result(atest, stest, dbstack, mfilename);
191 end % END UTP_02
192
193 %% UTP_03
194
195 % <TestDescription>
196 %
197 % Tests that the dropduplicates method works with a matrix of AOs as input.
198 %
199 % </TestDescription>
200 function result = utp_03
201
202 % <SyntaxDescription>
203 %
204 % Test that the dropduplicates method works for a matrix of AOs as input.
205 %
206 % </SyntaxDescription>
207
208 try
209 % <SyntaxCode>
210 x = 1:100;
211 x = sort([x x+1e-4]);
212 y = randn(length(x),1);
213 at1 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
214 amat = [at1 at5 at6; at5 at6 at1];
215 out = dropduplicates(amat);
216 % </SyntaxCode>
217 stest = true;
218 catch err
219 disp(err.message)
220 stest = false;
221 end
222
223 % <AlgoDescription>
224 %
225 % 1) Check that the number of elements in 'out' is the square of the
226 % number in the input.
227 % 2) Check that each output AO contains the correct data.
228 %
229 % </AlgoDescription>
230
231 atest = true;
232 if stest
233 % <AlgoCode>
234 % Check we have the correct number of outputs
235 if numel(out) ~= numel(amat), atest = false; end
236 % Check the output data
237 for kk = 1:numel(amat)
238 x = amat(kk).x;
239 y = amat(kk).y;
240 d = abs(diff(x));
241 idx = find(d<5e-3);
242 x(idx) = [];
243 y(idx) = [];
244 if ~isequal(out(kk).x, x), atest = false; end
245 if ~isequal(out(kk).y, y), atest = false; end
246 end
247 % </AlgoCode>
248 else
249 atest = false;
250 end
251
252 % Return a result structure
253 result = utp_prepare_result(atest, stest, dbstack, mfilename);
254 end % END UTP_03
255
256 %% UTP_04
257
258 % <TestDescription>
259 %
260 % Tests that the dropduplicates method works with a list of AOs as input.
261 %
262 % </TestDescription>
263 function result = utp_04
264
265 % <SyntaxDescription>
266 %
267 % Test that the dropduplicates method works for a list of AOs as input.
268 %
269 % </SyntaxDescription>
270
271 try
272 % <SyntaxCode>
273 x = 1:100;
274 x = sort([x x+1e-4]);
275 y = randn(length(x),1);
276 at1 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
277 out = dropduplicates(at1,at5,at6);
278 % </SyntaxCode>
279 stest = true;
280 catch err
281 disp(err.message)
282 stest = false;
283 end
284
285 % <AlgoDescription>
286 %
287 % 1) Check that the number of elements in 'out' is the square of the
288 % number in the input.
289 % 2) Check that each output AO contains the correct data.
290 %
291 % </AlgoDescription>
292
293 atest = true;
294 aoin = [at1, at5, at6];
295 if stest
296 % <AlgoCode>
297 % Check we have the correct number of outputs
298 if numel(out) ~= 3, atest = false; end
299 % Check the output data
300 for kk = 1:numel(aoin)
301 x = aoin(kk).x;
302 y = aoin(kk).y;
303 d = abs(diff(x));
304 idx = find(d<5e-3);
305 x(idx) = [];
306 y(idx) = [];
307 if ~isequal(out(kk).x, x), atest = false; end
308 if ~isequal(out(kk).y, y), atest = false; end
309 end
310 % </AlgoCode>
311 else
312 atest = false;
313 end
314
315 % Return a result structure
316 result = utp_prepare_result(atest, stest, dbstack, mfilename);
317 end % END UTP_04
318
319 %% UTP_05
320
321 % <TestDescription>
322 %
323 % Tests that the dropduplicates method works with a mix of different shaped AOs as
324 % input.
325 %
326 % </TestDescription>
327 function result = utp_05
328
329 % <SyntaxDescription>
330 %
331 % Test that the dropduplicates method works with an input of matrices and vectors
332 % and single AOs.
333 %
334 % </SyntaxDescription>
335
336 try
337 % <SyntaxCode>
338 x = 1:100;
339 x = sort([x x+1e-4]);
340 y = randn(length(x),1);
341 at1 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
342 out = dropduplicates(at1,[at5 at6],at5,[at5 at1; at6 at1],at6);
343 % </SyntaxCode>
344 stest = true;
345 catch err
346 disp(err.message)
347 stest = false;
348 end
349
350 % <AlgoDescription>
351 %
352 % 1) Check that the number of elements in 'out' is the same as in
353 % input.
354 % 2) Check that each output AO contains the correct data.
355 %
356 % </AlgoDescription>
357
358 atest = true;
359 aoin = [at1, reshape([at5 at6], 1, []), at5, reshape([at5 at1; at6 at1], 1, []), at6];
360 if stest
361 % <AlgoCode>
362 % Check we have the correct number of outputs
363 if numel(out) ~= 9, atest = false; end
364 % Check the output data
365 for kk = 1:numel(aoin)
366 x = aoin(kk).x;
367 y = aoin(kk).y;
368 d = abs(diff(x));
369 idx = find(d<5e-3);
370 x(idx) = [];
371 y(idx) = [];
372 if ~isequal(out(kk).x, x), atest = false; end
373 if ~isequal(out(kk).y, y), atest = false; end
374 end
375 % </AlgoCode>
376 else
377 atest = false;
378 end
379
380 % Return a result structure
381 result = utp_prepare_result(atest, stest, dbstack, mfilename);
382 end % END UTP_05
383
384 %% UTP_06
385
386 % <TestDescription>
387 %
388 % Tests that the dropduplicates method properly applies history.
389 %
390 % </TestDescription>
391 function result = utp_06
392
393 % <SyntaxDescription>
394 %
395 % Test that the result of applying the dropduplicates method can be processed back
396 % to an m-file.
397 %
398 % </SyntaxDescription>
399
400 try
401 % <SyntaxCode>
402 out = dropduplicates(at5);
403 mout = rebuild(out);
404 % </SyntaxCode>
405 stest = true;
406 catch err
407 disp(err.message)
408 stest = false;
409 end
410
411 % <AlgoDescription>
412 %
413 % 1) Check that the last entry in the history of 'out' corresponds to
414 % 'dropduplicates'.
415 % 2) Check that the re-built object is the same object as 'out'.
416 %
417 % </AlgoDescription>
418
419 atest = true;
420 if stest
421 % <AlgoCode>
422 % Check the last step in the history of 'out'
423 if ~strcmp(out.hist.methodInfo.mname, 'dropduplicates'), atest = false; end
424 % Check the re-built object
425 if ~eq(mout, out, ple2), atest = false; end
426 % </AlgoCode>
427 else
428 atest = false;
429 end
430
431 % Return a result structure
432 result = utp_prepare_result(atest, stest, dbstack, mfilename);
433 end % END UTP_06
434
435 %% UTP_07
436
437 % <TestDescription>
438 %
439 % Tests that the dropduplicates method can modify the input AO.
440 %
441 % </TestDescription>
442 function result = utp_07
443
444 % <SyntaxDescription>
445 %
446 % Test that the dropduplicates method can modify the input AO by calling
447 % with no output.
448 %
449 % </SyntaxDescription>
450
451 try
452 % <SyntaxCode>
453 % copy at1 to work with
454 x = 1:100;
455 x = sort([x x+1e-4]);
456 y = randn(length(x),1);
457 at1 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
458 ain = ao(at1);
459 % modify ain
460 aout = ain.dropduplicates();
461 ain.dropduplicates();
462 % </SyntaxCode>
463 stest = true;
464 catch err
465 disp(err.message)
466 stest = false;
467 end
468
469 % <AlgoDescription>
470 %
471 % 1) Check that 'at1' and 'ain' are now different.
472 % 2) Check that 'ain' is dropduplicates(at1).
473 %
474 % </AlgoDescription>
475
476 atest = true;
477 if stest
478 % <AlgoCode>
479 % Check that dropduplicates modified the input by comparing to the copy
480 if eq(ao(at1), ain, ple1), atest = false; end
481 % Check that dropduplicates doesn't modified the input for the function notation
482 if ~eq(aout, ain, ple1), atest = false; end
483 % Check that the modified input is the dropduplicates of the copy
484 x = at1.x;
485 y = at1.y;
486 d = abs(diff(x));
487 idx = find(d<5e-3);
488 x(idx) = [];
489 y(idx) = [];
490 if ~isequal(ain.x, x), atest = false; end
491 if ~isequal(ain.y, y), atest = false; end
492 % </AlgoCode>
493 else
494 atest = false;
495 end
496
497 % Return a result structure
498 result = utp_prepare_result(atest, stest, dbstack, mfilename);
499 end % END UTP_07
500
501 %% UTP_08
502
503 % <TestDescription>
504 %
505 % Tests that the dropduplicates method keeps the data shape of the input object.
506 %
507 % </TestDescription>
508 function result = utp_08
509
510 % <SyntaxDescription>
511 %
512 % Test that the dropduplicates method keeps the data shape of the input object. The
513 % input AO must be an AO with row data and an AO with column data.
514 %
515 % </SyntaxDescription>
516
517 try
518 % <SyntaxCode>
519 x = 1:100;
520 x = sort([x x+1e-4]);
521 y = randn(length(x),1);
522 at5 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
523 at6 = at5.';
524 out1 = dropduplicates(at5);
525 out2 = dropduplicates(at6);
526 % </SyntaxCode>
527 stest = true;
528 catch err
529 disp(err.message)
530 stest = false;
531 end
532
533 % <AlgoDescription>
534 %
535 % 1) Check that the shpe of the data doesn't change.
536 %
537 % </AlgoDescription>
538
539 atest = true;
540 if stest
541 % <AlgoCode>
542 % Check the shape of the output data
543 if size(out1.data.x, 2) ~= 1, atest = false; end
544 if size(out1.data.y, 2) ~= 1, atest = false; end
545 if size(out2.data.x, 1) ~= 1, atest = false; end
546 if size(out2.data.y, 1) ~= 1, atest = false; end
547 % </AlgoCode>
548 else
549 atest = false;
550 end
551
552 % Return a result structure
553 result = utp_prepare_result(atest, stest, dbstack, mfilename);
554 end % END UTP_08
555
556 %% UTP_09
557
558 % <TestDescription>
559 %
560 % Check that the dropduplicates method pass back the output objects to a list of
561 % output variables or to a single variable.
562 %
563 % </TestDescription>
564 function result = utp_09
565
566 % <SyntaxDescription>
567 %
568 % Call the method with a list of output variables and with a single output
569 % variable. Additionaly check that the rebuild method works on the output.
570 %
571 % </SyntaxDescription>
572
573 try
574 % <SyntaxCode>
575 x = 1:100;
576 x = sort([x x+1e-4]);
577 y = randn(length(x),1);
578 at5 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
579 at6 = at5.';
580 [o1, o2] = dropduplicates(at5, at6);
581 o3 = dropduplicates(at5, at6);
582 mout1 = rebuild(o1);
583 mout2 = rebuild(o2);
584 mout3 = rebuild(o3);
585 % </SyntaxCode>
586 stest = true;
587 catch err
588 disp(err.message)
589 stest = false;
590 end
591
592 % <AlgoDescription>
593 %
594 % 1) Check that the output contains the right number of objects
595 % 2) Check that the 'rebuild' method produces the same object as 'out'.
596 %
597 % </AlgoDescription>
598
599 atest = true;
600 if stest
601 % <AlgoCode>
602 % Check the number of outputs
603 if numel(o1) ~=1, atest = false; end
604 if numel(o2) ~=1, atest = false; end
605 if numel(o3) ~=2, atest = false; end
606 % Check the rebuilding of the object
607 if ~eq(o1, mout1, ple2), atest = false; end
608 if ~eq(o2, mout2, ple2), atest = false; end
609 if ~eq(o3, mout3, ple2), atest = false; end
610 % </AlgoCode>
611 else
612 atest = false;
613 end
614
615 % Return a result structure
616 result = utp_prepare_result(atest, stest, dbstack, mfilename);
617 end % END UTP_09
618
619 %% UTP_10
620
621 % <TestDescription>
622 %
623 % Control the method with a plist.
624 %
625 % </TestDescription>
626 function result = utp_10
627
628 % <SyntaxDescription>
629 %
630 % Test the dropduplicates method with different tolerances.
631 %
632 % </SyntaxDescription>
633
634 try
635 % <SyntaxCode>
636 x = 1:100;
637 x = sort([x x+.01]);
638 y = randn(length(x),1);
639 at1 = ao(plist('xvals', x, 'yvals', y, 'type', 'tsdata'));
640 tol1 = 0.1;
641 tol2 = 0.001;
642 pl1 = plist('tol', tol1);
643 pl2 = plist('tol', tol2);
644 out1 = dropduplicates(at1, pl1);
645 out2 = dropduplicates(at1, pl2);
646 mout1 = rebuild(out1);
647 mout2 = rebuild(out2);
648 % </SyntaxCode>
649 stest = true;
650 catch err
651 disp(err.message)
652 stest = false;
653 end
654
655 % <AlgoDescription>
656 %
657 % 1) Check that the different tolerances
658 % 2) Check that the re-built object is the same object as 'out'.
659 %
660 % </AlgoDescription>
661
662 atest = true;
663 if stest
664 % <AlgoCode>
665 % The sensitivity of 'tol' is high enough to remove data points
666 if eq(at1, out1, ple3), atest = false; end
667 % The sensitivity of 'tol' is NOT high enough to remove data points
668 % This means that input and output objectsare the same except the history
669 if ~eq(at1, out2, ple3), atest = false; end
670 % Check the re-built object
671 if ~eq(mout1, out1, ple2), atest = false; end
672 if ~eq(mout2, out2, ple2), atest = false; end
673 % </AlgoCode>
674 else
675 atest = false;
676 end
677
678 % Return a result structure
679 result = utp_prepare_result(atest, stest, dbstack, mfilename);
680 end % END UTP_10
681
682 end