Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_ctranspose.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_CTRANSPOSE a set of UTPs for the ao/ctranspose method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_ctranspose.m,v 1.12 2011/04/17 15:43:13 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The ctranspose method of the ao class computes the complex transpose value of the y | |
11 % and/or x data. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_ctranspose(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'ctranspose'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test AOs | |
30 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]); | |
31 | |
32 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Run the tests | |
36 results = [results utp_01]; % getInfo call | |
37 results = [results utp_02(mthd, atvec, @algo_test_y, [], ple3)]; % Vector input | |
38 results = [results utp_03(mthd, atmat, @algo_test_y, [], ple3)]; % Matrix input | |
39 results = [results utp_04(mthd, at1, at2, at3, @algo_test_y, [], ple3)]; % List input | |
40 results = [results utp_05(mthd, at1, atvec, atmat, @algo_test_y, [], ple3)]; % Test with mixed input | |
41 results = [results utp_06('transpose', at1, [], ple2)]; % Test history is working | |
42 | |
43 results = [results utp_07]; % Test the modify call works | |
44 results = [results utp_09]; % Test input data shape == output data shape | |
45 | |
46 results = [results utp_10(mthd, at1, at2, ple2)]; % Test output of the data | |
47 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear | |
48 results = [results utp_12(mthd, at1, ple1)]; % Test errors are cleared | |
49 | |
50 | |
51 disp('Done.'); | |
52 disp('******************************************************'); | |
53 | |
54 elseif nargin == 1 % Check for UTP functions | |
55 if strcmp(varargin{1}, 'isutp') | |
56 results = 1; | |
57 else | |
58 results = 0; | |
59 end | |
60 else | |
61 error('### Incorrect inputs') | |
62 end | |
63 | |
64 %% Algorithm test for UTP 02,03,04,05 | |
65 | |
66 function atest = algo_test_y(in, out, pli) | |
67 atest = true; | |
68 if ~isequal(ctranspose(in.data.y), out.data.y), atest = false; end | |
69 end | |
70 | |
71 | |
72 %% UTP_01 | |
73 | |
74 % <TestDescription> | |
75 % | |
76 % Tests that the getInfo call works for this method. | |
77 % | |
78 % </TestDescription> | |
79 function result = utp_01 | |
80 | |
81 | |
82 % <SyntaxDescription> | |
83 % | |
84 % Test that the getInfo call works for no sets, all sets, and each set | |
85 % individually. | |
86 % | |
87 % </SyntaxDescription> | |
88 | |
89 try | |
90 % <SyntaxCode> | |
91 % Call for no sets | |
92 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
93 % Call for all sets | |
94 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
95 % Call for each set | |
96 for kk=1:numel(io(2).sets) | |
97 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
98 end | |
99 % </SyntaxCode> | |
100 stest = true; | |
101 catch err | |
102 disp(err.message) | |
103 stest = false; | |
104 end | |
105 | |
106 % <AlgoDescription> | |
107 % | |
108 % 1) Check that getInfo call returned an minfo object in all cases. | |
109 % 2) Check that all plists have the correct parameters. | |
110 % | |
111 % </AlgoDescription> | |
112 | |
113 atest = true; | |
114 if stest | |
115 % <AlgoCode> | |
116 % check we have minfo objects | |
117 if isa(io, 'minfo') | |
118 % SET 'None' | |
119 if ~isempty(io(1).sets), atest = false; end | |
120 if ~isempty(io(1).plists), atest = false; end | |
121 % Check all Sets | |
122 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
123 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
124 % SET 'Default' | |
125 % Check key | |
126 if ~io(3).plists.isparam('complex'), atest = false; end | |
127 % Check default value | |
128 if ~isequal(io(3).plists.find('complex'), false), atest = false; end | |
129 % Check options | |
130 if ~isequal(io(3).plists.getOptionsForParam('complex'), {false, true}), atest = false; end | |
131 end | |
132 % </AlgoCode> | |
133 else | |
134 atest = false; | |
135 end | |
136 | |
137 % Return a result structure | |
138 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
139 end % END UTP_01 | |
140 | |
141 %% UTP_07 | |
142 | |
143 % <TestDescription> | |
144 % | |
145 % Tests that the ctranspose method can modify the input AO. | |
146 % | |
147 % </TestDescription> | |
148 function result = utp_07 | |
149 | |
150 % <SyntaxDescription> | |
151 % | |
152 % Test that the ctranspose method can modify the input AO by calling with no | |
153 % output and that the method doesn't change the input of the function | |
154 % notation (with a equal sign). | |
155 % | |
156 % </SyntaxDescription> | |
157 | |
158 try | |
159 % <SyntaxCode> | |
160 % copy at1 to work with | |
161 ain = ao(at1); | |
162 % modify ain | |
163 aout = ain.ctranspose(); | |
164 ain.ctranspose(); | |
165 % </SyntaxCode> | |
166 stest = true; | |
167 catch err | |
168 disp(err.message) | |
169 stest = false; | |
170 end | |
171 | |
172 % <AlgoDescription> | |
173 % | |
174 % 1) Check that 'at1' and 'ain' are now different. | |
175 % 2) Check that 'ain' is ctranspose(at1). | |
176 % | |
177 % </AlgoDescription> | |
178 | |
179 atest = true; | |
180 if stest | |
181 % <AlgoCode> | |
182 % Check that ctranspose modified the input by comparing to the copy | |
183 if eq(ao(at1), ain, ple1), atest = false; end | |
184 % Check that ctranspose doesn't modified the input for the function notation | |
185 if ~eq(aout, ain, ple1), atest = false; end | |
186 % Check that the modified input is the ctranspose value of the copy | |
187 if ~isequal(ctranspose(at1.data.y), ain.data.y), atest = false; end | |
188 % </AlgoCode> | |
189 else | |
190 atest = false; | |
191 end | |
192 | |
193 % Return a result structure | |
194 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
195 end % END UTP_07 | |
196 | |
197 %% UTP_08 | |
198 | |
199 % <TestDescription> | |
200 % | |
201 % Control the method with a plist. | |
202 % | |
203 % </TestDescription> | |
204 function result = utp_08 | |
205 | |
206 % <SyntaxDescription> | |
207 % | |
208 % Test that the ctranspose method can modify the single axis controlled by the | |
209 % plist and the resuld can be processed back to an m-file. | |
210 % | |
211 % </SyntaxDescription> | |
212 | |
213 try | |
214 % <SyntaxCode> | |
215 plx = plist('axis', 'X'); | |
216 ply = plist('axis', 'Y'); | |
217 plxy = plist('axis', 'XY'); | |
218 out1 = ctranspose(at1, plx); | |
219 out2 = ctranspose(at1, ply); | |
220 out3 = ctranspose(at1, plxy); | |
221 mout1 = rebuild(out1); | |
222 mout2 = rebuild(out2); | |
223 mout3 = rebuild(out3); | |
224 % </SyntaxCode> | |
225 stest = true; | |
226 catch err | |
227 disp(err.message) | |
228 stest = false; | |
229 end | |
230 | |
231 % <AlgoDescription> | |
232 % | |
233 % 1) Check that the ctranspose method applies to both axes | |
234 % 2) Check that the ctranspose method applies to both axes | |
235 % 3) Check that the ctranspose method applies to both axes | |
236 % 4) Check that the rebuilt objects are the same as 'out[1..3]'. | |
237 % | |
238 % </AlgoDescription> | |
239 | |
240 atest = true; | |
241 if stest | |
242 % <AlgoCode> | |
243 % Check each output against the complex transpose value of the input | |
244 if ~isequal(at1.data.y', out1.data.y), atest = false; end | |
245 if ~isequal(at1.data.y', out2.data.y), atest = false; end | |
246 if ~isequal(at1.data.y', out3.data.y), atest = false; end | |
247 % Check rebuilt object | |
248 if ~eq(mout1, out1, ple2), atest = false; end | |
249 if ~eq(mout2, out2, ple2), atest = false; end | |
250 if ~eq(mout3, out3, ple2), atest = false; end | |
251 % </AlgoCode> | |
252 else | |
253 atest = false; | |
254 end | |
255 | |
256 % Return a result structure | |
257 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
258 end % END UTP_08 | |
259 | |
260 %% UTP_09 | |
261 | |
262 % <TestDescription> | |
263 % | |
264 % Control the method with a plist. | |
265 % | |
266 % </TestDescription> | |
267 function result = utp_09 | |
268 | |
269 % <SyntaxDescription> | |
270 % | |
271 % Test that the abs method keeps the data shape of the input object. The | |
272 % input AO must be an AO with row data and an AO with column data. | |
273 % | |
274 % </SyntaxDescription> | |
275 | |
276 try | |
277 % <SyntaxCode> | |
278 out1 = abs(at5); | |
279 out2 = abs(at6); | |
280 % </SyntaxCode> | |
281 stest = true; | |
282 catch err | |
283 disp(err.message) | |
284 stest = false; | |
285 end | |
286 | |
287 % <AlgoDescription> | |
288 % | |
289 % 1) Check that the shpe of the data doesn't change. | |
290 % | |
291 % </AlgoDescription> | |
292 | |
293 atest = true; | |
294 if stest | |
295 % <AlgoCode> | |
296 % Check the shape of the output data | |
297 if size(out1.data.x) ~= size(at5.data.x), atest = false; end | |
298 if size(out1.data.y) ~= size(at5.data.y), atest = false; end | |
299 if size(out2.data.x) ~= size(at6.data.x), atest = false; end | |
300 if size(out2.data.y) ~= size(at6.data.y), atest = false; end | |
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_09 | |
309 | |
310 end |