Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_atan2.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_ATAN2 a set of UTPs for the ao/atan2 method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_atan2.m,v 1.3 2009/07/20 15:14:11 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The atan2 method of the ao class computes the the four quadrant | |
11 % arctangent of the real parts of the elements of X and Y. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_atan2(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'atan2'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test AOs | |
30 at1 = ao(1:30, randn(30,1), 1); | |
31 at2 = ao(1:30, randn(30,1), 1); | |
32 | |
33 % Exception list for the UTPs: | |
34 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
35 | |
36 % Run the tests | |
37 results = [results utp_01]; % getInfo call | |
38 results = [results utp_02]; % Vector input | |
39 results = [results utp_03]; % Test history is working | |
40 results = [results utp_04]; % Test the modify call works | |
41 | |
42 disp('Done.'); | |
43 disp('******************************************************'); | |
44 | |
45 elseif nargin == 1 % Check for UTP functions | |
46 if strcmp(varargin{1}, 'isutp') | |
47 results = 1; | |
48 else | |
49 results = 0; | |
50 end | |
51 else | |
52 error('### Incorrect inputs') | |
53 end | |
54 | |
55 %% UTP_01 | |
56 | |
57 % <TestDescription> | |
58 % | |
59 % Tests that the getInfo call works for this method. | |
60 % | |
61 % </TestDescription> | |
62 function result = utp_01 | |
63 | |
64 | |
65 % <SyntaxDescription> | |
66 % | |
67 % Test that the getInfo call works for no sets, all sets, and each set | |
68 % individually. | |
69 % | |
70 % </SyntaxDescription> | |
71 | |
72 try | |
73 % <SyntaxCode> | |
74 % Call for no sets | |
75 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
76 % Call for all sets | |
77 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
78 % Call for each set | |
79 for kk=1:numel(io(2).sets) | |
80 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
81 end | |
82 % </SyntaxCode> | |
83 stest = true; | |
84 catch err | |
85 disp(err.message) | |
86 stest = false; | |
87 end | |
88 | |
89 % <AlgoDescription> | |
90 % | |
91 % 1) Check that getInfo call returned an minfo object in all cases. | |
92 % 2) Check that all plists have the correct parameters. | |
93 % | |
94 % </AlgoDescription> | |
95 | |
96 atest = true; | |
97 if stest | |
98 % <AlgoCode> | |
99 % check we have minfo objects | |
100 if isa(io, 'minfo') | |
101 % SET 'None' | |
102 if ~isempty(io(1).sets), atest = false; end | |
103 if ~isempty(io(1).plists), atest = false; end | |
104 % Check all Sets | |
105 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
106 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
107 % SET 'Default' | |
108 if io(3).plists.nparams ~= 0, atest = false; end | |
109 % Check key | |
110 % Check default value | |
111 % Check options | |
112 end | |
113 % </AlgoCode> | |
114 else | |
115 atest = false; | |
116 end | |
117 | |
118 % Return a result structure | |
119 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
120 end % END UTP_01 | |
121 | |
122 %% UTP_02 | |
123 | |
124 % <TestDescription> | |
125 % | |
126 % Tests that the atan2 method works only with two AOs as input.. | |
127 % | |
128 % </TestDescription> | |
129 function result = utp_02 | |
130 | |
131 % <SyntaxDescription> | |
132 % | |
133 % Tests that the atan2 method works only with two AOs as input.. | |
134 % | |
135 % </SyntaxDescription> | |
136 | |
137 try | |
138 % <SyntaxCode> | |
139 out = atan2(at1, at2); | |
140 % </SyntaxCode> | |
141 stest = true; | |
142 catch err | |
143 disp(err.message) | |
144 stest = false; | |
145 end | |
146 | |
147 % <AlgoDescription> | |
148 % | |
149 % 1) Check that the number of elements in 'out' is the same as in 'atvec' | |
150 % 2) Check that each output AO contains the correct data. | |
151 % | |
152 % </AlgoDescription> | |
153 | |
154 atest = true; | |
155 if stest | |
156 % <AlgoCode> | |
157 % Check we have the correct number of outputs | |
158 if numel(out) ~= 1, atest = false; end | |
159 % Check the output data | |
160 if ~isequal(out.y, atan2(at1.y, at2.y)), atest = false; end | |
161 % </AlgoCode> | |
162 else | |
163 atest = false; | |
164 end | |
165 | |
166 % Return a result structure | |
167 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
168 end % END UTP_02 | |
169 | |
170 %% UTP_03 | |
171 | |
172 % <TestDescription> | |
173 % | |
174 % Tests that the atan2 method properly applies history. | |
175 % | |
176 % </TestDescription> | |
177 function result = utp_03 | |
178 | |
179 % <SyntaxDescription> | |
180 % | |
181 % Test that the result of applying the atan2 method can be processed | |
182 % back. | |
183 % | |
184 % </SyntaxDescription> | |
185 | |
186 try | |
187 % <SyntaxCode> | |
188 out = atan2(at1,at2); | |
189 mout = rebuild(out); | |
190 % </SyntaxCode> | |
191 stest = true; | |
192 catch err | |
193 disp(err.message) | |
194 stest = false; | |
195 end | |
196 | |
197 % <AlgoDescription> | |
198 % | |
199 % 1) Check that the last entry in the history of 'out' corresponds to | |
200 % 'atan2'. | |
201 % 2) Check that the re-built object is the same object as the input. | |
202 % | |
203 % </AlgoDescription> | |
204 | |
205 atest = true; | |
206 if stest | |
207 % <AlgoCode> | |
208 % Check the last step in the history of 'out' | |
209 if ~strcmp(out.hist.methodInfo.mname, 'atan2'), atest = false; end | |
210 % Check the re-built object | |
211 if ~eq(mout, out, ple2), atest = false; end | |
212 % </AlgoCode> | |
213 else | |
214 atest = false; | |
215 end | |
216 | |
217 % Return a result structure | |
218 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
219 end % END UTP_03 | |
220 | |
221 %% UTP_04 | |
222 | |
223 % <TestDescription> | |
224 % | |
225 % Tests that the atan2 method can not be used as a modifier method. | |
226 % | |
227 % </TestDescription> | |
228 function result = utp_04 | |
229 | |
230 % <SyntaxDescription> | |
231 % | |
232 % Tests that the atan2 method can not be used as a modifier method. The | |
233 % command should fail. | |
234 % | |
235 % </SyntaxDescription> | |
236 | |
237 try | |
238 % <SyntaxCode> | |
239 % copy at1 to work with | |
240 amodi = ao(at1); | |
241 aeq = ao(at1); | |
242 out = aeq.atan2(at2); | |
243 amodi.atan2(at2); | |
244 stest = false; | |
245 % </SyntaxCode> | |
246 catch | |
247 stest = true; | |
248 end | |
249 | |
250 % <AlgoDescription> | |
251 % | |
252 % 1) Nothing to test. | |
253 % | |
254 % </AlgoDescription> | |
255 | |
256 atest = true; | |
257 if stest | |
258 % <AlgoCode> | |
259 % </AlgoCode> | |
260 else | |
261 atest = false; | |
262 end | |
263 | |
264 % Return a result structure | |
265 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
266 end % END UTP_04 | |
267 | |
268 end |