comparison testing/utp_1.1/utps/ao/utp_ao_gt.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_GT a set of UTPs for the ao/gt method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_gt.m,v 1.2 2009/07/20 16:50:09 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The lt() function of the ao class ao1 > ao2 compares the y-axis values of
11 % ao1 with y-axis values of ao2 and returns an array with elements set to
12 % logical 1 (true) where the relation is true and elements set to logical 0
13 % where it is not.
14 %
15 % </MethodDescription>
16
17 function results = utp_ao_gt(varargin)
18
19 % Check the inputs
20 if nargin == 0
21
22 % Some keywords
23 class = 'ao';
24 mthd = 'gt';
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 % Run the tests
35 results = [results utp_01]; % getInfo call
36 results = [results utp_02]; % Compare against scalar
37 results = [results utp_03]; % Compare against AO
38
39 disp('Done.');
40 disp('******************************************************');
41
42 elseif nargin == 1 % Check for UTP functions
43 if strcmp(varargin{1}, 'isutp')
44 results = 1;
45 else
46 results = 0;
47 end
48 else
49 error('### Incorrect inputs')
50 end
51
52 %% UTP_01
53
54 % <TestDescription>
55 %
56 % Tests that the getInfo call works for this method.
57 %
58 % </TestDescription>
59 function result = utp_01
60
61
62 % <SyntaxDescription>
63 %
64 % Test that the getInfo call works for no sets, all sets, and each set
65 % individually.
66 %
67 % </SyntaxDescription>
68
69 try
70 % <SyntaxCode>
71 % Call for no sets
72 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
73 % Call for all sets
74 io(2) = eval([class '.getInfo(''' mthd ''')']);
75 % Call for each set
76 for kk=1:numel(io(2).sets)
77 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
78 end
79 % </SyntaxCode>
80 stest = true;
81 catch err
82 disp(err.message)
83 stest = false;
84 end
85
86 % <AlgoDescription>
87 %
88 % 1) Check that getInfo call returned an minfo object in all cases.
89 % 2) Check that all plists have the correct parameters.
90 %
91 % </AlgoDescription>
92
93 atest = true;
94 if stest
95 % <AlgoCode>
96 % check we have minfo objects
97 if isa(io, 'minfo')
98 % SET 'None'
99 if ~isempty(io(1).sets), atest = false; end
100 if ~isempty(io(1).plists), atest = false; end
101 % Check all Sets
102 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
103 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
104 % SET 'Default'
105 if io(3).plists.nparams ~= 0, atest = false; end
106 % Check key
107 % Check default value
108 % Check options
109 end
110 % </AlgoCode>
111 else
112 atest = false;
113 end
114
115 % Return a result structure
116 result = utp_prepare_result(atest, stest, dbstack, mfilename);
117 end % END UTP_01
118
119 %% UTP_02
120
121 % <TestDescription>
122 %
123 % Tests that the gt method compare an AO with scalar value
124 %
125 % </TestDescription>
126 function result = utp_02
127
128 % <SyntaxDescription>
129 %
130 % Test that the gt method works with relational operators and the function
131 % command. Use for this AOs with different data objects.
132 %
133 % </SyntaxDescription>
134
135 try
136 % <SyntaxCode>
137 scalar = 0.2;
138 out11 = at1 > scalar;
139 out12 = gt(at1,scalar);
140 out21 = at2 > scalar;
141 out22 = gt(at2,scalar);
142 out31 = at3 > scalar;
143 out32 = gt(at3,scalar);
144 out41 = at4 > scalar;
145 out42 = gt(at4,scalar);
146 % </SyntaxCode>
147 stest = true;
148 catch err
149 disp(err.message)
150 stest = false;
151 end
152
153 % <AlgoDescription>
154 %
155 % 1) Check that the result of the 'relational operator' and the 'function'
156 % command are the same.
157 % 2) Check that each output AO contains the correct data.
158 %
159 % </AlgoDescription>
160
161 atest = true;
162 if stest
163 % <AlgoCode>
164 % Check the different commands
165 if ~isequal(out11, out12), atest = false; end
166 if ~isequal(out21, out22), atest = false; end
167 if ~isequal(out31, out32), atest = false; end
168 if ~isequal(out41, out42), atest = false; end
169 % Check the output data
170 y1 = at1.y;
171 y2 = at2.y;
172 y3 = at3.y;
173 y4 = at4.y;
174 if ~isequal(out11, y1>scalar), atest = false; end
175 if ~isequal(out21, y2>scalar), atest = false; end
176 if ~isequal(out31, y3>scalar), atest = false; end
177 if ~isequal(out41, y4>scalar), atest = false; end
178 % </AlgoCode>
179 else
180 atest = false;
181 end
182
183 % Return a result structure
184 result = utp_prepare_result(atest, stest, dbstack, mfilename);
185 end % END UTP_02
186
187 %% UTP_03
188
189 % <TestDescription>
190 %
191 % Tests that the gt method compare an AO with one other AO
192 %
193 % </TestDescription>
194 function result = utp_03
195
196 % <SyntaxDescription>
197 %
198 % Test that the gt method works with relational operators and the function
199 % command. Use for this AOs with different data objects.
200 % Remark that both AOs must have the same size.
201 %
202 % </SyntaxDescription>
203
204 try
205 % <SyntaxCode>
206 out11 = at1 > ao(1:300, zeros(300,1));
207 out12 = gt(at1,ao(1:300, zeros(300,1)));
208 out21 = at2 > ao(1:151, zeros(151,1));
209 out22 = gt(at2,ao(1:151, zeros(151,1)));
210 out31 = at3 > ao(1:100, zeros(100,1));
211 out32 = gt(at3,ao(1:100, zeros(100,1)));
212 out41 = at4 > ao(zeros(3,3));
213 out42 = gt(at4,ao(zeros(3,3)));
214 % </SyntaxCode>
215 stest = true;
216 catch err
217 disp(err.message)
218 stest = false;
219 end
220
221 % <AlgoDescription>
222 %
223 % 1) Check that the result of the 'relational operator' and the 'function'
224 % command are the same.
225 % 2) Check that each output AO contains the correct data.
226 %
227 % </AlgoDescription>
228
229 atest = true;
230 if stest
231 % <AlgoCode>
232 % Check the different commands
233 if ~isequal(out11, out12), atest = false; end
234 if ~isequal(out21, out22), atest = false; end
235 if ~isequal(out31, out32), atest = false; end
236 if ~isequal(out41, out42), atest = false; end
237 % Check the output data
238 y1 = at1.y;
239 y2 = at2.y;
240 y3 = at3.y;
241 y4 = at4.y;
242 if ~isequal(out11, y1>0), atest = false; end
243 if ~isequal(out21, y2>0), atest = false; end
244 if ~isequal(out31, y3>0), atest = false; end
245 if ~isequal(out41, y4>0), atest = false; end
246 % </AlgoCode>
247 else
248 atest = false;
249 end
250
251 % Return a result structure
252 result = utp_prepare_result(atest, stest, dbstack, mfilename);
253 end % END UTP_03
254
255 end