comparison testing/utp_1.1/generic_utps/utp_02.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 % <TestDescription>
2 %
3 % Tests that the <METHOD> method works with a vector of objects as input.
4 %
5 % </TestDescription>
6 %
7 % $Id: utp_02.m,v 1.3 2010/07/27 07:13:59 hewitson Exp $
8 %
9
10 function result = utp_02(method, vec, algo, pli, ple3)
11
12 % <SyntaxDescription>
13 %
14 % Test that the <METHOD> method works for a vector of objects as input.
15 %
16 % </SyntaxDescription>
17
18 try
19 % <SyntaxCode>
20 if isempty(pli)
21 out = feval(method, vec);
22 else
23 out = feval(method, vec, pli);
24 end
25 % </SyntaxCode>
26 stest = true;
27 catch err
28 disp(err.message)
29 stest = false;
30 end
31
32 % <AlgoDescription>
33 %
34 % 1) Check that the number of elements in 'out' is the same as in 'vec'
35 % 2) Check that each output object contains the correct data.
36 %
37 % </AlgoDescription>
38
39 atest = true;
40 if stest
41 % <AlgoCode>
42 % Check we have the correct number of outputs
43 if ~isequal(size(out), size(vec)), atest = false; end
44 % Check each output against the correct value
45 for kk=1:numel(out)
46
47 % extra tests for constructors
48 if utils.helper.ismember(method, utils.helper.ltpda_userclasses)
49
50 % Check that the output is the same except the history
51 if ~eq(vec(kk), out(kk), ple3), atest = false; end
52 % Check the history
53 if ~eq(vec(kk).hist, out(kk).hist.inhists), atest = false; end
54 % Change the output to make sure that it is a 'real' copy
55 out(kk).setDescription('my desc');
56 if eq(vec(kk), out(kk), ple3), atest = false; end
57
58 else
59 atest = algo(vec(kk), out(kk), pli);
60 if ~atest
61 break;
62 end
63
64 end
65 end
66
67 % </AlgoCode>
68 else
69 atest = false;
70 end
71
72 % Return a result structure
73 dd = dbstack;
74 mfilename = dd(2).file(1:end-2);
75 result = utp_prepare_result(atest, stest, dbstack, mfilename);
76 end % END UTP_02