Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/matrix/utp_matrix_setObjs.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_MATRIX_SETOBJS a set of UTPs for the matrix/setObjs method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_matrix_setObjs.m,v 1.2 2010/12/22 16:05:19 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The setObjs method of the matrix class sets the objs property. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_matrix_setObjs(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'matrix'; | |
21 mthd = 'setObjs'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test MATRIX objects | |
29 [ma1,ma2,ma3,ma4,mav,mam] = get_test_objects_matrix; | |
30 | |
31 % Exception list for the UTPs: | |
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
33 | |
34 pl_generic = plist('objs', [ao(1) ao(2)]); | |
35 | |
36 % Run the tests | |
37 results = [results utp_01]; % getInfo call | |
38 results = [results utp_02(mthd, mav, @algo_test_plist, pl_generic, ple2)]; % Vector input | |
39 results = [results utp_03(mthd, mam, @algo_test_plist, pl_generic, ple2)]; % Matrix input | |
40 results = [results utp_04(mthd, ma1, ma2, ma3, @algo_test_plist, pl_generic, ple2)]; % List input | |
41 results = [results utp_05(mthd, ma1, mam, mav, @algo_test_plist, pl_generic, ple2)]; % Mixed input | |
42 results = [results utp_06(mthd, ma1, pl_generic, ple2)]; % Test history is working | |
43 | |
44 % Old format | |
45 results = [results utp_07]; % Test the modify call works | |
46 results = [results utp_08]; % Set the property without a plist | |
47 results = [results utp_09]; % Test output of the data | |
48 results = [results utp_11(mthd, ma1, ple1, plist('OBJS', 'foo'))]; % Test plotinfo doesn't disappear | |
49 | |
50 disp('Done.'); | |
51 disp('******************************************************'); | |
52 | |
53 elseif nargin == 1 % Check for UTP functions | |
54 if strcmp(varargin{1}, 'isutp') | |
55 results = 1; | |
56 else | |
57 results = 0; | |
58 end | |
59 else | |
60 error('### Incorrect inputs') | |
61 end | |
62 | |
63 function atest = algo_test_plist(in, out, pli) | |
64 atest = true; | |
65 if ~eq(out.objs, pli.find('objs'), 'UUID'), atest = false; end | |
66 end | |
67 | |
68 %% UTP_01 | |
69 | |
70 % <TestDescription> | |
71 % | |
72 % Tests that the getInfo call works for this method. | |
73 % | |
74 % </TestDescription> | |
75 function result = utp_01 | |
76 | |
77 | |
78 % <SyntaxDescription> | |
79 % | |
80 % Test that the getInfo call works for no sets, all sets, and each set | |
81 % individually. | |
82 % | |
83 % </SyntaxDescription> | |
84 | |
85 try | |
86 % <SyntaxCode> | |
87 % Call for no sets | |
88 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
89 % Call for all sets | |
90 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
91 % Call for each set | |
92 for kk=1:numel(io(2).sets) | |
93 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
94 end | |
95 % </SyntaxCode> | |
96 stest = true; | |
97 catch err | |
98 disp(err.message) | |
99 stest = false; | |
100 end | |
101 | |
102 % <AlgoDescription> | |
103 % | |
104 % 1) Check that getInfo call returned an minfo object in all cases. | |
105 % 2) Check that all plists have the correct parameters. | |
106 % | |
107 % </AlgoDescription> | |
108 | |
109 atest = true; | |
110 if stest | |
111 % <AlgoCode> | |
112 % check we have minfo objects | |
113 if isa(io, 'minfo') | |
114 %%% SET 'None' | |
115 if ~isempty(io(1).sets), atest = false; end | |
116 if ~isempty(io(1).plists), atest = false; end | |
117 %%% Check all Sets | |
118 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
119 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
120 %%%%%%%%%% SET 'Default' | |
121 if io(3).plists.nparams ~= 1, atest = false; end | |
122 % Check key | |
123 if ~io(3).plists.isparam('objs'), atest = false; end | |
124 % Check default value | |
125 if ~isEmptyDouble(io(3).plists.find('objs')), atest = false; end | |
126 % Check options | |
127 if ~isequal(io(3).plists.getOptionsForParam('objs'), {[]}), atest = false; end | |
128 end | |
129 % </AlgoCode> | |
130 else | |
131 atest = false; | |
132 end | |
133 | |
134 % Return a result structure | |
135 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
136 end % END UTP_01 | |
137 | |
138 %% UTP_07 | |
139 | |
140 % <TestDescription> | |
141 % | |
142 % Tests that the setObjs method can modify the input MATRIX. | |
143 % | |
144 % </TestDescription> | |
145 function result = utp_07 | |
146 | |
147 % <SyntaxDescription> | |
148 % | |
149 % Test that the setObjs method can modify the input MATRIX by calling | |
150 % with no output. | |
151 % | |
152 % </SyntaxDescription> | |
153 | |
154 try | |
155 % <SyntaxCode> | |
156 pli = plist('objs', ao(1), ao(2)); | |
157 obj_modi = copy(ma1,1); | |
158 obj_eq = copy(ma1,1); | |
159 | |
160 out = obj_eq.setObjs(pli); | |
161 obj_modi.setObjs(pli); | |
162 % </SyntaxCode> | |
163 stest = true; | |
164 catch err | |
165 disp(err.message) | |
166 stest = false; | |
167 end | |
168 | |
169 % <AlgoDescription> | |
170 % | |
171 % 1) Check that 'out' and 'obj_eq' are now different. | |
172 % 2) Check that 'obj_eq' is not changed | |
173 % 3) Check that the modified input is the setObjs value of the copy | |
174 % 4) Check that out and amodi are the same | |
175 % | |
176 % </AlgoDescription> | |
177 | |
178 atest = true; | |
179 if stest | |
180 % <AlgoCode> | |
181 % Check that 'out' and 'obj_eq' are now different. | |
182 if eq(out, obj_eq, ple2), atest = false; end | |
183 % Check that 'obj_eq' is not changed | |
184 if ~eq(obj_eq, ma1, ple1), atest = false; end | |
185 % Check that the modified input is correct | |
186 if ~eq(obj_modi.objs, pli.find('objs'), 'UUID'), atest = false; end | |
187 % Check that out and obj_modi are the same | |
188 if ~eq(out, obj_modi, ple1), atest = false; end | |
189 % </AlgoCode> | |
190 else | |
191 atest = false; | |
192 end | |
193 | |
194 % Return a result structure | |
195 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
196 end % END UTP_07 | |
197 | |
198 %% UTP_08 | |
199 | |
200 % <TestDescription> | |
201 % | |
202 % Tests that the setObjs method can set the property without a plist. | |
203 % | |
204 % </TestDescription> | |
205 function result = utp_08 | |
206 | |
207 % <SyntaxDescription> | |
208 % | |
209 % Test that the setObjs method can modify the property 'objs' | |
210 % without a plist. | |
211 % | |
212 % </SyntaxDescription> | |
213 | |
214 try | |
215 % <SyntaxCode> | |
216 objs = [ao(1), ao(2)]; | |
217 out = ma1.setObjs(objs); | |
218 mout = rebuild(out); | |
219 % </SyntaxCode> | |
220 stest = true; | |
221 catch err | |
222 disp(err.message) | |
223 stest = false; | |
224 end | |
225 | |
226 % <AlgoDescription> | |
227 % | |
228 % 1) Check that 'out' has the correct objs field | |
229 % 2) Check that the re-built object is the same object as 'out'. | |
230 % | |
231 % </AlgoDescription> | |
232 | |
233 atest = true; | |
234 if stest | |
235 % <AlgoCode> | |
236 % Check the field 'objs' | |
237 if ~eq(out.objs, objs), atest = false; end | |
238 % Check the re-built object | |
239 if ~eq(mout, out, ple2), atest = false; end | |
240 % </AlgoCode> | |
241 else | |
242 atest = false; | |
243 end | |
244 | |
245 % Return a result structure | |
246 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
247 end % END UTP_08 | |
248 | |
249 %% UTP_09 | |
250 | |
251 % <TestDescription> | |
252 % | |
253 % Check that the setObjs method pass back the output objects to a list of | |
254 % output variables or to a single variable. | |
255 % | |
256 % </TestDescription> | |
257 function result = utp_09 | |
258 | |
259 % <SyntaxDescription> | |
260 % | |
261 % Call the method with a list of output variables and with a single output | |
262 % variable. Additionaly check that the rebuild method works on the output. | |
263 % | |
264 % </SyntaxDescription> | |
265 | |
266 try | |
267 % <SyntaxCode> | |
268 [o1, o2] = setObjs(ma1, ma2, [ao(1), ao(2)]); | |
269 o3 = setObjs(ma1, ma2, [ao(1), ao(2)]); | |
270 mout1 = rebuild(o1); | |
271 mout2 = rebuild(o2); | |
272 mout3 = rebuild(o3); | |
273 % </SyntaxCode> | |
274 stest = true; | |
275 catch err | |
276 disp(err.message) | |
277 stest = false; | |
278 end | |
279 | |
280 % <AlgoDescription> | |
281 % | |
282 % 1) Check that the output contains the right number of objects | |
283 % 2) Check that the 'rebuild' method produces the same object as 'out'. | |
284 % | |
285 % </AlgoDescription> | |
286 | |
287 atest = true; | |
288 if stest | |
289 % <AlgoCode> | |
290 % Check the number of outputs | |
291 if numel(o1) ~=1, atest = false; end | |
292 if numel(o2) ~=1, atest = false; end | |
293 if numel(o3) ~=2, atest = false; end | |
294 % Check that o1, o2 and o3 have the correct data | |
295 if ~eq(o1.objs, [ao(1) ao(2)], ple1), atest = false; end | |
296 if ~eq(o2.objs, [ao(1) ao(2)], ple1), atest = false; end | |
297 if ~eq(o3.objs, [ao(1) ao(2)], ple1), atest = false; end | |
298 % Check the rebuilding of the object | |
299 if ~eq(o1, mout1, ple2), atest = false; end | |
300 if ~eq(o2, mout2, ple2), atest = false; end | |
301 if ~eq(o3, mout3, ple2), atest = false; end | |
302 % </AlgoCode> | |
303 else | |
304 atest = false; | |
305 end | |
306 | |
307 % Return a result structure | |
308 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
309 end % END UTP_09 | |
310 | |
311 end |